The R Project SVN R

Rev

Rev 87904 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 87904 Rev 90234
Line 1... Line 1...
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C) 1997--2025  The R Core Team
3
 *  Copyright (C) 1997--2026  The R Core Team
4
 *  Copyright (C) 1995, 1996  Robert Gentleman and Ross Ihaka
4
 *  Copyright (C) 1995, 1996  Robert Gentleman and Ross Ihaka
5
 *
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  the Free Software Foundation; either version 2 of the License, or
Line 774... Line 774...
774
    REprintf(", return()ing %s\n", attrT2char(attr));
774
    REprintf(", return()ing %s\n", attrT2char(attr));
775
#endif
775
#endif
776
    return attr;
776
    return attr;
777
}
777
}
778
 
778
 
-
 
779
/* deparse a single attribute as `<name> = <value>`, shared by attr2() (the
-
 
780
   structure(..) form) and the OBJSXP / object(..) deparse below. */
-
 
781
static void attrEntry(SEXP a, LocalParseData *d)
-
 
782
{
-
 
783
    if(TAG(a) == R_DimSymbol) {
-
 
784
	print2buff("dim", d); // was .Dim
-
 
785
    }
-
 
786
    else if(TAG(a) == R_DimNamesSymbol) {
-
 
787
	print2buff("dimnames", d); // was .Dimnames
-
 
788
    }
-
 
789
    else if(TAG(a) == R_NamesSymbol) {
-
 
790
	print2buff("names", d); // was .Names
-
 
791
    }
-
 
792
    else if(TAG(a) == R_TspSymbol) {
-
 
793
	print2buff("tsp", d); // was .Tsp
-
 
794
    }
-
 
795
    else if(TAG(a) == R_LevelsSymbol) {
-
 
796
	print2buff("levels", d); // was .Label
-
 
797
    }
-
 
798
    else {
-
 
799
	/* TAG(a) might contain spaces etc */
-
 
800
	const char *tag = CHAR(PRINTNAME(TAG(a)));
-
 
801
	int d_opts_in = d->opts;
-
 
802
	d->opts = SIMPLEDEPARSE; /* turn off quote()ing */
-
 
803
	if(isValidName(tag))
-
 
804
	    deparse2buff(TAG(a), d);
-
 
805
	else {
-
 
806
	    print2buff("\"", d);
-
 
807
	    deparse2buff(TAG(a), d);
-
 
808
	    print2buff("\"", d);
-
 
809
	}
-
 
810
	d->opts = d_opts_in;
-
 
811
    }
-
 
812
    print2buff(" = ", d);
-
 
813
    bool fnarg = d->fnarg;
-
 
814
    d->fnarg = true;
-
 
815
    deparse2buff(CAR(a), d);
-
 
816
    d->fnarg = fnarg;
-
 
817
}
-
 
818
 
-
 
819
// function attr2()  writes full  attributes(s) to 'buff'
779
static void attr2(SEXP s, LocalParseData *d, bool not_names)
820
static void attr2(SEXP s, LocalParseData *d, bool not_names)
780
{
821
{
781
    SEXP a = ATTRIB(s);
822
    SEXP a = ATTRIB(s);
782
    while(!isNull(a)) {
823
    while(!isNull(a)) {
783
	if(TAG(a) != R_SrcrefSymbol &&
824
	if(TAG(a) != R_SrcrefSymbol &&
784
	   !(TAG(a) == R_NamesSymbol && not_names)) {
825
	   !(TAG(a) == R_NamesSymbol && not_names)) {
785
	    print2buff(", ", d);
826
	    print2buff(", ", d);
786
	    if(TAG(a) == R_DimSymbol) {
-
 
787
		print2buff("dim", d); // was .Dim
-
 
788
	    }
-
 
789
	    else if(TAG(a) == R_DimNamesSymbol) {
-
 
790
		print2buff("dimnames", d); // was .Dimnames
-
 
791
	    }
-
 
792
	    else if(TAG(a) == R_NamesSymbol) {
-
 
793
		print2buff("names", d); // was .Names
-
 
794
	    }
-
 
795
	    else if(TAG(a) == R_TspSymbol) {
-
 
796
		print2buff("tsp", d); // was .Tsp
-
 
797
	    }
-
 
798
	    else if(TAG(a) == R_LevelsSymbol) {
-
 
799
		print2buff("levels", d); // was .Label
-
 
800
	    }
-
 
801
	    else {
-
 
802
		/* TAG(a) might contain spaces etc */
-
 
803
		const char *tag = CHAR(PRINTNAME(TAG(a)));
-
 
804
		int d_opts_in = d->opts;
-
 
805
		d->opts = SIMPLEDEPARSE; /* turn off quote()ing */
-
 
806
		if(isValidName(tag))
-
 
807
		    deparse2buff(TAG(a), d);
-
 
808
		else {
-
 
809
		    print2buff("\"", d);
827
	    attrEntry(a, d);
810
		    deparse2buff(TAG(a), d);
-
 
811
		    print2buff("\"", d);
-
 
812
		}
-
 
813
		d->opts = d_opts_in;
-
 
814
	    }
-
 
815
	    print2buff(" = ", d);
-
 
816
	    bool fnarg = d->fnarg;
-
 
817
	    d->fnarg = true;
-
 
818
	    deparse2buff(CAR(a), d);
-
 
819
	    d->fnarg = fnarg;
-
 
820
	}
828
	}
821
	a = CDR(a);
829
	a = CDR(a);
822
    }
830
    }
823
    print2buff(")", d);
831
    print2buff(")", d);
824
}
832
}
Line 1508... Line 1516...
1508
	break;
1516
	break;
1509
    case WEAKREFSXP:
1517
    case WEAKREFSXP:
1510
	d->sourceable = false;
1518
	d->sourceable = false;
1511
	print2buff("<weak reference>", d);
1519
	print2buff("<weak reference>", d);
1512
	break;
1520
	break;
1513
    case OBJSXP: {
1521
    case OBJSXP:
-
 
1522
	/* a bare OBJSXP, e.g. from S7; objects with the S4 bit
-
 
1523
	   are dealt with above.  Deparse to  .OBJSXP() or  structure(.OBJSXP(), <attrs>)  */
-
 
1524
	if(d_opts_in & SHOW_ATTR_OR_NMS) {
1514
	/*
1525
	    SEXP a = ATTRIB(s);
1515
	print2buff("object(", d);
1526
	    print2buff("structure(.OBJSXP()", d);
1516
	if(attr >= STRUC_ATTR) attr2(s, d, (attr == STRUC_ATTR));
1527
	    for( ; !isNull(a); a = CDR(a)) {
-
 
1528
		if(TAG(a) != R_SrcrefSymbol) {
1517
	 print2buff(")", d);
1529
		    print2buff(", ", d);
-
 
1530
		    attrEntry(a, d);
1518
	*/
1531
		}
1519
	d->sourceable = false;
1532
	    }
-
 
1533
	}
1520
	print2buff("<object>", d);
1534
	print2buff(")", d);
1521
	break;
1535
	break;
1522
    }
-
 
1523
    default:
1536
    default:
1524
	d->sourceable = false;
1537
	d->sourceable = false;
1525
	UNIMPLEMENTED_TYPE("deparse2buff", s);
1538
	UNIMPLEMENTED_TYPE("deparse2buff", s);
1526
    }
1539
    }
1527
 
1540