c99tree nodes ============= statement --------- STATEMENT meaning: a statement argument: expr|if|switch|while|do|for|break|continue|goto|return children: depends on the argument - selection and iteration statements usually have CONDITION and a single STATEMENT or BLOCK children - jump and return statements have an expression child or none - expression statement has an expression child - empty statement (single ';') is not marked BLOCK meaning: a compound statement in {} argument: 'virtual' or none children: list of declaration and statement nodes for virtual block see LABEL can appear in expression context (gcc extension: i = '({ f(); g(); });') LABEL meaning: a jump or switch label argument: goto|case|default child: an expression, usually ID or ICONST notes: in c grammar the statement following a label is the child of the label and they together form a 'labelled statement'. in c99tree consecutive labels, statements and declarations are on the same level. in contexts where a single statement is needed, multiple labels can precede the single statement. in c99tree this is represented as a list of the labels and the statement. to avoid confusion a 'BLOCK virtual' node is inserted as a container for the list. virtual block example: 'if (cond) label1: label2: statement();' if there is no statement or block after a label then there must be an empty statement: single ';' CONDITION meaning: condition section of while, for, if,... statements arguments: none or init|condition|iter in case of for(;;) child: an expression (or declaration in case of init part of for(;;)) THEN meaning: then clause of an if statement child: single statement ELSE meaning: else clause of an if statement child: single statement ASM meaning: an asm statement or 'asm(...)' in general child: SCONST or SCONSTLIST - extended asm syntax of gcc is not represented properly declaration ----------- DECL meaning: declaration arguments: none children: a TYPE and one or more ID nodes example: 'extern long int n = 1, *p, a[3] = {2}, *(*f)(int, int);' notes: declaration consists of some type specifiers and a comma separated list of declarators which may contain additional type elements (eg pointer or array declarator), an identifier and initialization. TYPE holds the type specifiers applied to the entire list, then each ID node represents a declarator with type elements and initialization as its children. the ID node is a special case in c99tree. (its children do not follow a similar node hierarchy to expressions) the order of elements follows the backward thinking of c: one can read the type of an ID by saying "ID is a .." then reading the last element of the list. PTR is read as "pointer to ..", INDEX is read as "array of ..", ARGLIST is read as "function returning ..". example: TYPE TYPENAME int ID ARGLIST INDEX PTR is read as "ID is a pointer to array of functions returning int". (the children of TYPE should be treated as part of the list). (the list can contain type qualifiers and attributes as well). there is one more exception: if ID has an initializer then INIT is the last children of ID. the initializers are the children of INIT. TYPEDEF meaning: typedef declaration arguments: none children: identical to DECL FUNCDEF meaning: function definition arguments: name of the function (same as the child ID arg) child: TYPE, ID, BLOCK, (similar to DECL) the ID has an ARGLIST child or two in case of K&R style funcdef TYPE meaning: type container for qualifiers, specifier, typenames, attribs notes: there are two kind of type nodes: one which appears under DECL and similar nodes and has no PTR, INDEX, ARGLIST or ID children. the second one appears in 'OP cast binary' and 'OP sizeof binary'. in DECL the PTR, etc nodes are under a separate ID node, in cast and sizeof TYPE has an 'ID ' child as a container for those. CLASS meaning: storage class specifier argument: static|extern|auto|register|inline notes: in c inline is actually a specifier only avail for functions typedef is a storage class in c grammar, but behaves differently QUALIFIER meaning: type qualifier arguments: const|volatile|restrict TYPESPEC meaning: builtin type specifier arguments: long|short|signed|unsigned|_Complex|_Imaginary TYPENAME meaning: builtin type specifier arguments: int|float|void|... notes: the c standard does not distinguish typename and typespec, instead it lists the type specifiers which can appear together (eg 'unsigned long int' but not 'float int'). c99tree calls the "base types" as typename and additional type specifiers as typespec. TYPECUSTOM meaning: typedef'd type name argument: name of the custom type notes: has no children by default, but in verbose mode it has the same children as the original TYPEDEF had TYPEOF meaning: typeof(expr) (gcc extension) notes: typeof() can appear wherever TYPENAME can ARGLIST meaning: function arguments arguments: none|K&R/1|K&R/2 notes: appears under id in decl like nodes or in call in old k&r style function definitions there is two arglist: parameters without type information and a separate declaration list specifying the types. ARG meaning: a specific argument children: similar to DECL, but TYPE can be missing notes: appears in ARGLIST or ATTR. unnamed arguments are represented by 'ID '. multiple ID and initializer is only allowed in 'ARGLIST K&R/2' ELLIPSIS meaning: '...' in function argument notes: the gcc extensions 'case 3 ... 5' and '{[2]=4, [3 ... 5]=8}' use 'OP ... binary' PTR meaning: pointer type notes: can appear under type or id INDEX meaning: array type notes: can appear under type or id ENUM UNION STRUCT notes: struct fields are declarations BITS meaning: ':X' part of a bitfield INIT meaning: initializer in declarations child: an expression or INITLIST example: 'int i = 1;' notes: appears under ID in a declaration INITLIST meaning: initializer list example: 'int a[] = {1, 2};' notes: designators use expression nodes with anonymous IDs example: the INIT part of 'int a[] = {2, [3] = 4, 5}' turns into INIT INITLIST ICONST 2 OP = binary OP [] binary ID ICONST 3 ICONST 4 ICONST 5 expression ---------- CALL meaning: a function call expression OP meaning: operator expression argument1: pre++|post--|+|-|*|[]|.|->|cast|sizeof|&|=|>>=|... argument2: unary|binary|ternary notes: && unary is gcc extension EXPRLIST meaning: comma separated list of expressions example: 'return 1,2,3;' ID meaning: identifier ICONST meaning: integer constant FCONST meaning: floating point constant SCONST: meaning: string constant notes: '\' and '"' are backslash escaped example: "a\nb\"" turns into SCONST \"a\\n\\"\" SCONSTLIST meaning: container for a list of string constants children: list of SCONST example: 'puts("foo" "bar");' other ----- ATTRLIST meaning: list of attributes (gcc extension) ATTR meaning: attribute (gcc extension) example: '__attribute__((noreturn)) void f(void);' PREPROC meaning: preprocessor node children: pragma, define, include... notes: can appear anywhere in a merged tree COMMENT meaning: comment node argument: the comment itself DEBUG meaning: used for debugging should not appear in the output of c99tree releases INVALID meaning: internal node, must not appear in output