[51b7345] | 1 | #ifndef PARSENODE_H |
---|
| 2 | #define PARSENODE_H |
---|
| 3 | |
---|
| 4 | #include <string> |
---|
| 5 | #include <list> |
---|
| 6 | #include <iterator> |
---|
| 7 | |
---|
| 8 | #include "utility.h" |
---|
| 9 | #include "SynTree/Declaration.h" |
---|
| 10 | #include "UniqueName.h" |
---|
| 11 | |
---|
| 12 | class ExpressionNode; |
---|
| 13 | class CompositeExprNode; |
---|
| 14 | class CommaExprNode; |
---|
| 15 | class StatementNode; |
---|
| 16 | class CompoundStmtNode; |
---|
| 17 | class DeclarationNode; |
---|
| 18 | class InitializerNode; |
---|
| 19 | |
---|
| 20 | // Builder |
---|
| 21 | class ParseNode { |
---|
[bdd516a] | 22 | public: |
---|
| 23 | ParseNode( void ); |
---|
| 24 | ParseNode ( std::string ); |
---|
| 25 | virtual ~ParseNode( void ); |
---|
[51b7345] | 26 | |
---|
[bdd516a] | 27 | ParseNode *set_name ( std::string ) ; |
---|
| 28 | ParseNode *set_name ( std::string * ) ; |
---|
[51b7345] | 29 | |
---|
[bdd516a] | 30 | std::string get_name( void ); |
---|
[51b7345] | 31 | |
---|
[bdd516a] | 32 | ParseNode *get_link( void ) const; |
---|
| 33 | ParseNode *get_last( void ); |
---|
| 34 | ParseNode *set_link( ParseNode * ); |
---|
| 35 | void set_next( ParseNode *newlink ) { next = newlink; } |
---|
[51b7345] | 36 | |
---|
[bdd516a] | 37 | virtual ParseNode *clone() const { return 0; }; |
---|
[51b7345] | 38 | |
---|
[bdd516a] | 39 | const std::string get_name( void ) const; |
---|
| 40 | virtual void print( std::ostream &, int indent = 0 ) const; |
---|
| 41 | virtual void printList( std::ostream &, int indent = 0 ) const; |
---|
[51b7345] | 42 | |
---|
[bdd516a] | 43 | ParseNode &operator,( ParseNode &); |
---|
| 44 | protected: |
---|
| 45 | std::string name; |
---|
| 46 | ParseNode *next; |
---|
| 47 | static int indent_by; |
---|
[51b7345] | 48 | }; |
---|
| 49 | |
---|
[bdd516a] | 50 | ParseNode *mkList( ParseNode & ); |
---|
[51b7345] | 51 | |
---|
| 52 | class ExpressionNode : public ParseNode { |
---|
[bdd516a] | 53 | public: |
---|
| 54 | ExpressionNode(); |
---|
| 55 | ExpressionNode( std::string * ); |
---|
| 56 | ExpressionNode( const ExpressionNode &other ); |
---|
| 57 | virtual ~ExpressionNode() { /* can't delete asArgName because it might be referenced elsewhere */ }; |
---|
[51b7345] | 58 | |
---|
[bdd516a] | 59 | virtual ExpressionNode *clone() const = 0; |
---|
[51b7345] | 60 | |
---|
[bdd516a] | 61 | virtual CommaExprNode *add_to_list( ExpressionNode * ); |
---|
[51b7345] | 62 | |
---|
[bdd516a] | 63 | ExpressionNode *get_argName() const { return argName; } |
---|
| 64 | ExpressionNode *set_asArgName( std::string *aName ); |
---|
| 65 | ExpressionNode *set_asArgName( ExpressionNode *aDesignator ); |
---|
[51b7345] | 66 | |
---|
[bdd516a] | 67 | virtual void print( std::ostream &, int indent = 0) const = 0; |
---|
| 68 | virtual void printOneLine( std::ostream &, int indent = 0) const = 0; |
---|
[51b7345] | 69 | |
---|
[bdd516a] | 70 | virtual Expression *build() const = 0; |
---|
| 71 | protected: |
---|
| 72 | void printDesignation ( std::ostream &, int indent = 0) const; |
---|
| 73 | private: |
---|
| 74 | ExpressionNode *argName; |
---|
[51b7345] | 75 | }; |
---|
| 76 | |
---|
[bdd516a] | 77 | // NullExprNode is used in tuples as a place-holder where a tuple component is omitted e.g., [ 2, , 3 ] |
---|
| 78 | class NullExprNode : public ExpressionNode { |
---|
| 79 | public: |
---|
| 80 | NullExprNode(); |
---|
[51b7345] | 81 | |
---|
[bdd516a] | 82 | virtual NullExprNode *clone() const; |
---|
[51b7345] | 83 | |
---|
[bdd516a] | 84 | virtual void print( std::ostream &, int indent = 0) const; |
---|
| 85 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
[51b7345] | 86 | |
---|
[bdd516a] | 87 | virtual Expression *build() const; |
---|
[51b7345] | 88 | }; |
---|
| 89 | |
---|
| 90 | class ConstantNode : public ExpressionNode { |
---|
[bdd516a] | 91 | public: |
---|
| 92 | enum Type { |
---|
| 93 | Integer, Float, Character, String /* , Range, EnumConstant */ |
---|
| 94 | }; |
---|
| 95 | |
---|
| 96 | ConstantNode( void ); |
---|
| 97 | ConstantNode( std::string * ); |
---|
| 98 | ConstantNode( Type, std::string * ); |
---|
| 99 | ConstantNode( const ConstantNode &other ); |
---|
| 100 | |
---|
| 101 | virtual ConstantNode *clone() const { return new ConstantNode( *this ); } |
---|
| 102 | |
---|
| 103 | Type get_type( void ) const ; |
---|
| 104 | virtual void print( std::ostream &, int indent = 0) const; |
---|
| 105 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
| 106 | |
---|
| 107 | std::string get_value() const { return value; } |
---|
| 108 | ConstantNode *append( std::string *newValue ); |
---|
| 109 | |
---|
| 110 | Expression *build() const; |
---|
| 111 | private: |
---|
| 112 | void classify( std::string &); |
---|
| 113 | Type type; |
---|
| 114 | std::string value; |
---|
| 115 | bool sign; |
---|
| 116 | short base; |
---|
| 117 | int longs, size; |
---|
[51b7345] | 118 | }; |
---|
| 119 | |
---|
| 120 | class VarRefNode : public ExpressionNode { |
---|
[bdd516a] | 121 | public: |
---|
| 122 | VarRefNode(); |
---|
| 123 | VarRefNode( std::string *, bool isLabel = false ); |
---|
| 124 | VarRefNode( const VarRefNode &other ); |
---|
[51b7345] | 125 | |
---|
[bdd516a] | 126 | virtual Expression *build() const ; |
---|
[51b7345] | 127 | |
---|
[bdd516a] | 128 | virtual VarRefNode *clone() const { return new VarRefNode( *this ); } |
---|
[51b7345] | 129 | |
---|
[bdd516a] | 130 | virtual void print( std::ostream &, int indent = 0) const; |
---|
| 131 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
| 132 | private: |
---|
| 133 | bool isLabel; |
---|
[51b7345] | 134 | }; |
---|
| 135 | |
---|
[bdd516a] | 136 | class TypeValueNode : public ExpressionNode { |
---|
| 137 | public: |
---|
| 138 | TypeValueNode( DeclarationNode * ); |
---|
| 139 | TypeValueNode( const TypeValueNode &other ); |
---|
[51b7345] | 140 | |
---|
[bdd516a] | 141 | DeclarationNode *get_decl() const { return decl; } |
---|
[51b7345] | 142 | |
---|
[bdd516a] | 143 | virtual Expression *build() const ; |
---|
[51b7345] | 144 | |
---|
[bdd516a] | 145 | virtual TypeValueNode *clone() const { return new TypeValueNode( *this ); } |
---|
[51b7345] | 146 | |
---|
[bdd516a] | 147 | virtual void print( std::ostream &, int indent = 0) const; |
---|
| 148 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
| 149 | private: |
---|
| 150 | DeclarationNode *decl; |
---|
[51b7345] | 151 | }; |
---|
| 152 | |
---|
| 153 | class OperatorNode : public ExpressionNode { |
---|
[bdd516a] | 154 | public: |
---|
| 155 | enum Type { TupleC, Comma, TupleFieldSel, |
---|
| 156 | Cond, NCond, |
---|
| 157 | SizeOf, AlignOf, Attr, CompLit, Plus, Minus, Mul, Div, Mod, Or, And, |
---|
[51b7345] | 158 | BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq, |
---|
| 159 | Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, |
---|
| 160 | ERAssn, OrAssn, Index, FieldSel, PFieldSel, Range, |
---|
[bdd516a] | 161 | UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress |
---|
| 162 | }; |
---|
[51b7345] | 163 | |
---|
[bdd516a] | 164 | OperatorNode( Type t ); |
---|
| 165 | OperatorNode( const OperatorNode &other ); |
---|
| 166 | virtual ~OperatorNode(); |
---|
[51b7345] | 167 | |
---|
[bdd516a] | 168 | virtual OperatorNode *clone() const { return new OperatorNode( *this ); } |
---|
[51b7345] | 169 | |
---|
[bdd516a] | 170 | Type get_type( void ) const; |
---|
| 171 | std::string get_typename( void ) const; |
---|
[51b7345] | 172 | |
---|
[bdd516a] | 173 | virtual void print( std::ostream &, int indent = 0) const; |
---|
| 174 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
[51b7345] | 175 | |
---|
[bdd516a] | 176 | virtual Expression *build() const { return 0; } |
---|
| 177 | private: |
---|
| 178 | Type type; |
---|
| 179 | static const char *OpName[]; |
---|
[51b7345] | 180 | }; |
---|
| 181 | |
---|
| 182 | |
---|
| 183 | class CompositeExprNode : public ExpressionNode { |
---|
[bdd516a] | 184 | public: |
---|
| 185 | CompositeExprNode( void ); |
---|
| 186 | CompositeExprNode( std::string * ); |
---|
| 187 | CompositeExprNode( ExpressionNode *f, ExpressionNode *args = 0 ); |
---|
| 188 | CompositeExprNode( ExpressionNode *f, ExpressionNode *arg1, ExpressionNode *arg2 ); |
---|
| 189 | CompositeExprNode( const CompositeExprNode &other ); |
---|
| 190 | virtual ~CompositeExprNode(); |
---|
| 191 | |
---|
| 192 | virtual CompositeExprNode *clone() const { return new CompositeExprNode( *this ); } |
---|
| 193 | virtual Expression *build() const; |
---|
| 194 | |
---|
| 195 | virtual void print( std::ostream &, int indent = 0) const; |
---|
| 196 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
| 197 | |
---|
| 198 | void set_function( ExpressionNode * ); |
---|
| 199 | void set_args( ExpressionNode * ); |
---|
| 200 | |
---|
| 201 | void add_arg( ExpressionNode * ); |
---|
| 202 | |
---|
| 203 | ExpressionNode *get_function() const; |
---|
| 204 | ExpressionNode *get_args() const; |
---|
| 205 | private: |
---|
| 206 | ExpressionNode *function; |
---|
| 207 | ExpressionNode *arguments; |
---|
[51b7345] | 208 | }; |
---|
| 209 | |
---|
| 210 | class CommaExprNode : public CompositeExprNode { |
---|
[bdd516a] | 211 | public: |
---|
| 212 | CommaExprNode(); |
---|
| 213 | CommaExprNode( ExpressionNode * ); |
---|
| 214 | CommaExprNode( ExpressionNode *, ExpressionNode * ); |
---|
| 215 | CommaExprNode( const CommaExprNode &other ); |
---|
| 216 | |
---|
| 217 | virtual CommaExprNode *add_to_list( ExpressionNode * ); |
---|
| 218 | virtual CommaExprNode *clone() const { return new CommaExprNode( *this ); } |
---|
[51b7345] | 219 | }; |
---|
| 220 | |
---|
| 221 | class ForCtlExprNode : public ExpressionNode { |
---|
[bdd516a] | 222 | public: |
---|
| 223 | ForCtlExprNode( ParseNode *, ExpressionNode *, ExpressionNode * ) throw ( SemanticError ); |
---|
| 224 | ForCtlExprNode( const ForCtlExprNode &other ); |
---|
| 225 | ~ForCtlExprNode(); |
---|
| 226 | |
---|
| 227 | StatementNode *get_init() const { return init; } |
---|
| 228 | ExpressionNode *get_condition() const { return condition; } |
---|
| 229 | ExpressionNode *get_change() const { return change; } |
---|
| 230 | |
---|
| 231 | virtual ForCtlExprNode *clone() const { return new ForCtlExprNode( *this ); } |
---|
| 232 | virtual Expression *build() const; |
---|
| 233 | |
---|
| 234 | virtual void print( std::ostream &, int indent = 0 ) const; |
---|
| 235 | virtual void printOneLine( std::ostream &, int indent = 0 ) const; |
---|
| 236 | private: |
---|
| 237 | StatementNode *init; |
---|
| 238 | ExpressionNode *condition; |
---|
| 239 | ExpressionNode *change; |
---|
[51b7345] | 240 | }; |
---|
| 241 | |
---|
| 242 | class ValofExprNode : public ExpressionNode { |
---|
[bdd516a] | 243 | public: |
---|
| 244 | ValofExprNode(); |
---|
| 245 | ValofExprNode( StatementNode *s = 0 ); |
---|
| 246 | ValofExprNode( const ValofExprNode &other ); |
---|
| 247 | ~ValofExprNode(); |
---|
[51b7345] | 248 | |
---|
[bdd516a] | 249 | virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); } |
---|
[51b7345] | 250 | |
---|
[bdd516a] | 251 | StatementNode *get_body() const { return body; } |
---|
| 252 | void print( std::ostream &, int indent = 0 ) const; |
---|
| 253 | void printOneLine( std::ostream &, int indent = 0 ) const; |
---|
| 254 | Expression *build() const; |
---|
[51b7345] | 255 | |
---|
[bdd516a] | 256 | private: |
---|
| 257 | StatementNode *body; |
---|
[51b7345] | 258 | }; |
---|
| 259 | |
---|
| 260 | class TypeData; |
---|
| 261 | |
---|
[bdd516a] | 262 | class DeclarationNode : public ParseNode { |
---|
| 263 | public: |
---|
[c11e31c] | 264 | enum Qualifier { Const, Restrict, Volatile, Lvalue, Atomic, Attribute }; |
---|
| 265 | enum StorageClass { Extern, Static, Auto, Register, Inline, Fortran }; |
---|
[bdd516a] | 266 | enum BasicType { Char, Int, Float, Double, Void, Bool, Complex, Imaginary }; |
---|
| 267 | enum Modifier { Signed, Unsigned, Short, Long }; |
---|
| 268 | enum TyCon { Struct, Union, Context }; |
---|
| 269 | enum TypeClass { Type, Dtype, Ftype }; |
---|
| 270 | |
---|
| 271 | static const char *qualifierName[]; |
---|
| 272 | static const char *basicTypeName[]; |
---|
| 273 | static const char *modifierName[]; |
---|
| 274 | static const char *tyConName[]; |
---|
| 275 | static const char *typeClassName[]; |
---|
| 276 | |
---|
| 277 | static DeclarationNode *newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, |
---|
| 278 | StatementNode *body, bool newStyle = false ); |
---|
| 279 | static DeclarationNode *newQualifier( Qualifier ); |
---|
| 280 | static DeclarationNode *newStorageClass( StorageClass ); |
---|
| 281 | static DeclarationNode *newBasicType( BasicType ); |
---|
| 282 | static DeclarationNode *newModifier( Modifier ); |
---|
| 283 | static DeclarationNode *newForall( DeclarationNode *); |
---|
| 284 | static DeclarationNode *newFromTypedef( std::string *); |
---|
| 285 | static DeclarationNode *newAggregate( TyCon kind, std::string *name, DeclarationNode *formals, ExpressionNode *actuals, DeclarationNode *fields ); |
---|
| 286 | static DeclarationNode *newEnum( std::string *name, DeclarationNode *constants ); |
---|
| 287 | static DeclarationNode *newEnumConstant( std::string *name, ExpressionNode *constant ); |
---|
| 288 | static DeclarationNode *newName( std::string *); |
---|
| 289 | static DeclarationNode *newFromTypeGen( std::string*, ExpressionNode *params ); |
---|
| 290 | static DeclarationNode *newTypeParam( TypeClass, std::string *); |
---|
| 291 | static DeclarationNode *newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts ); |
---|
| 292 | static DeclarationNode *newContextUse( std::string *name, ExpressionNode *params ); |
---|
| 293 | static DeclarationNode *newTypeDecl( std::string *name, DeclarationNode *typeParams ); |
---|
| 294 | static DeclarationNode *newPointer( DeclarationNode *qualifiers ); |
---|
| 295 | static DeclarationNode *newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ); |
---|
| 296 | static DeclarationNode *newVarArray( DeclarationNode *qualifiers ); |
---|
| 297 | static DeclarationNode *newBitfield( ExpressionNode *size ); |
---|
| 298 | static DeclarationNode *newTuple( DeclarationNode *members ); |
---|
| 299 | static DeclarationNode *newTypeof( ExpressionNode *expr ); |
---|
| 300 | static DeclarationNode *newAttr( std::string*, ExpressionNode *expr ); |
---|
| 301 | static DeclarationNode *newAttr( std::string*, DeclarationNode *type ); |
---|
| 302 | |
---|
| 303 | DeclarationNode *addQualifiers( DeclarationNode *); |
---|
| 304 | DeclarationNode *copyStorageClasses( DeclarationNode *); |
---|
| 305 | DeclarationNode *addType( DeclarationNode *); |
---|
| 306 | DeclarationNode *addTypedef(); |
---|
| 307 | DeclarationNode *addAssertions( DeclarationNode *); |
---|
| 308 | DeclarationNode *addName( std::string *); |
---|
| 309 | DeclarationNode *addBitfield( ExpressionNode *size ); |
---|
| 310 | DeclarationNode *addVarArgs(); |
---|
| 311 | DeclarationNode *addFunctionBody( StatementNode *body ); |
---|
| 312 | DeclarationNode *addOldDeclList( DeclarationNode *list ); |
---|
| 313 | DeclarationNode *addPointer( DeclarationNode *qualifiers ); |
---|
| 314 | DeclarationNode *addArray( DeclarationNode *array ); |
---|
| 315 | DeclarationNode *addNewPointer( DeclarationNode *pointer ); |
---|
| 316 | DeclarationNode *addNewArray( DeclarationNode *array ); |
---|
| 317 | DeclarationNode *addParamList( DeclarationNode *list ); |
---|
| 318 | DeclarationNode *addIdList( DeclarationNode *list ); // old-style functions |
---|
| 319 | DeclarationNode *addInitializer( InitializerNode *init ); |
---|
| 320 | |
---|
| 321 | DeclarationNode *cloneType( std::string *newName ); |
---|
| 322 | DeclarationNode *cloneType( DeclarationNode *existing ); |
---|
| 323 | DeclarationNode *cloneType( int ) { return cloneType( ( std::string *)0 ); } |
---|
| 324 | DeclarationNode *cloneBaseType( std::string *newName ); |
---|
| 325 | DeclarationNode *cloneBaseType( DeclarationNode *newdecl ); |
---|
| 326 | |
---|
| 327 | DeclarationNode *appendList( DeclarationNode *); |
---|
| 328 | |
---|
| 329 | DeclarationNode *clone() const; |
---|
| 330 | void print( std::ostream &, int indent = 0 ) const; |
---|
| 331 | void printList( std::ostream &, int indent = 0 ) const; |
---|
| 332 | |
---|
| 333 | Declaration *build() const; |
---|
| 334 | ::Type *buildType() const; |
---|
| 335 | |
---|
| 336 | bool get_hasEllipsis() const; |
---|
| 337 | std::string get_name() const { return name; } |
---|
| 338 | LinkageSpec::Type get_linkage() const { return linkage; } |
---|
| 339 | DeclarationNode *extractAggregate() const; |
---|
| 340 | |
---|
| 341 | DeclarationNode(); |
---|
| 342 | ~DeclarationNode(); |
---|
| 343 | private: |
---|
| 344 | Declaration::StorageClass buildStorageClass() const; |
---|
| 345 | bool buildInline() const; |
---|
| 346 | |
---|
| 347 | TypeData *type; |
---|
| 348 | std::string name; |
---|
| 349 | std::list< StorageClass > storageClasses; |
---|
| 350 | ExpressionNode *bitfieldWidth; |
---|
| 351 | InitializerNode *initializer; |
---|
| 352 | bool hasEllipsis; |
---|
| 353 | LinkageSpec::Type linkage; |
---|
| 354 | |
---|
| 355 | static UniqueName anonymous; |
---|
[51b7345] | 356 | }; |
---|
| 357 | |
---|
| 358 | class StatementNode : public ParseNode { |
---|
[bdd516a] | 359 | public: |
---|
| 360 | enum Type { Exp, If, Switch, Case, Default, Choose, Fallthru, |
---|
| 361 | While, Do, For, |
---|
| 362 | Goto, Continue, Break, Return, Throw, |
---|
| 363 | Try, Catch, Finally, Asm, |
---|
| 364 | Decl |
---|
| 365 | }; |
---|
[51b7345] | 366 | |
---|
[bdd516a] | 367 | StatementNode( void ); |
---|
| 368 | StatementNode( std::string ); |
---|
| 369 | StatementNode( Type, ExpressionNode *e = 0, StatementNode *s = 0 ); |
---|
| 370 | StatementNode( Type, std::string *target ); |
---|
| 371 | StatementNode( DeclarationNode *decl ); |
---|
[51b7345] | 372 | |
---|
| 373 | |
---|
[bdd516a] | 374 | ~StatementNode( void ); |
---|
[51b7345] | 375 | |
---|
[bdd516a] | 376 | static StatementNode *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false ); |
---|
[51b7345] | 377 | |
---|
[bdd516a] | 378 | void set_control( ExpressionNode * ); |
---|
| 379 | StatementNode * set_block( StatementNode * ); |
---|
[51b7345] | 380 | |
---|
[bdd516a] | 381 | ExpressionNode *get_control() const ; |
---|
| 382 | StatementNode *get_block() const; |
---|
| 383 | StatementNode::Type get_type( void ) const; |
---|
[51b7345] | 384 | |
---|
[bdd516a] | 385 | StatementNode *add_label( std::string * ); |
---|
| 386 | std::list<std::string> *get_labels() const; |
---|
[51b7345] | 387 | |
---|
[bdd516a] | 388 | void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; } |
---|
| 389 | void setCatchRest( bool newVal ) { isCatchRest = newVal; } |
---|
[51b7345] | 390 | |
---|
[bdd516a] | 391 | std::string get_target() const; |
---|
[51b7345] | 392 | |
---|
[bdd516a] | 393 | StatementNode *add_controlexp( ExpressionNode * ); |
---|
| 394 | StatementNode *append_block( StatementNode * ); |
---|
| 395 | StatementNode *append_last_case( StatementNode * ); |
---|
[51b7345] | 396 | |
---|
[bdd516a] | 397 | void print( std::ostream &, int indent = 0) const; |
---|
[51b7345] | 398 | |
---|
[bdd516a] | 399 | virtual StatementNode *clone() const; |
---|
[51b7345] | 400 | |
---|
[bdd516a] | 401 | virtual Statement *build() const; |
---|
| 402 | private: |
---|
| 403 | static const char *StType[]; |
---|
| 404 | Type type; |
---|
| 405 | ExpressionNode *control; |
---|
| 406 | StatementNode *block; |
---|
| 407 | std::list<std::string> *labels; |
---|
| 408 | std::string *target; // target label for jump statements |
---|
| 409 | DeclarationNode *decl; |
---|
[51b7345] | 410 | |
---|
[bdd516a] | 411 | bool isCatchRest; |
---|
[51b7345] | 412 | }; |
---|
| 413 | |
---|
| 414 | class CompoundStmtNode : public StatementNode { |
---|
[bdd516a] | 415 | public: |
---|
| 416 | CompoundStmtNode( void ); |
---|
| 417 | CompoundStmtNode( std::string * ); |
---|
| 418 | CompoundStmtNode( StatementNode * ); |
---|
| 419 | ~CompoundStmtNode(); |
---|
[51b7345] | 420 | |
---|
[bdd516a] | 421 | void add_statement( StatementNode * ); |
---|
[51b7345] | 422 | |
---|
[bdd516a] | 423 | void print( std::ostream &, int indent = 0 ) const; |
---|
[51b7345] | 424 | |
---|
[bdd516a] | 425 | virtual Statement *build() const; |
---|
| 426 | private: |
---|
| 427 | StatementNode *first, *last; |
---|
[51b7345] | 428 | }; |
---|
| 429 | |
---|
| 430 | class NullStmtNode : public CompoundStmtNode { |
---|
[bdd516a] | 431 | public: |
---|
| 432 | Statement *build() const; |
---|
| 433 | void print( std::ostream &, int indent = 0) const; |
---|
[51b7345] | 434 | }; |
---|
| 435 | |
---|
| 436 | class InitializerNode : public ParseNode { |
---|
[bdd516a] | 437 | public: |
---|
| 438 | InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode *des = 0 ); |
---|
| 439 | InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 ); |
---|
| 440 | ~InitializerNode(); |
---|
[51b7345] | 441 | |
---|
[bdd516a] | 442 | ExpressionNode *get_expression() const { return expr; } |
---|
[51b7345] | 443 | |
---|
[bdd516a] | 444 | InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; } |
---|
| 445 | ExpressionNode *get_designators() const { return designator; } |
---|
[51b7345] | 446 | |
---|
[bdd516a] | 447 | InitializerNode *next_init() const { return kids; } |
---|
[51b7345] | 448 | |
---|
[bdd516a] | 449 | void print( std::ostream &, int indent = 0 ) const; |
---|
| 450 | void printOneLine( std::ostream & ) const; |
---|
[51b7345] | 451 | |
---|
[bdd516a] | 452 | virtual Initializer *build() const; |
---|
| 453 | private: |
---|
| 454 | ExpressionNode *expr; |
---|
| 455 | bool aggregate; |
---|
| 456 | ExpressionNode *designator; // may be list |
---|
| 457 | InitializerNode *kids; |
---|
[51b7345] | 458 | }; |
---|
| 459 | |
---|
| 460 | |
---|
| 461 | |
---|
| 462 | template< typename SynTreeType, typename NodeType > |
---|
| 463 | void |
---|
[bdd516a] | 464 | buildList( const NodeType *firstNode, std::list< SynTreeType *> &outputList ) |
---|
[51b7345] | 465 | { |
---|
[bdd516a] | 466 | SemanticError errors; |
---|
| 467 | std::back_insert_iterator< std::list< SynTreeType *> > out( outputList ); |
---|
| 468 | const NodeType *cur = firstNode; |
---|
| 469 | |
---|
| 470 | while ( cur ) { |
---|
| 471 | try { |
---|
| 472 | SynTreeType *result = dynamic_cast< SynTreeType *>( cur->build() ); |
---|
| 473 | if ( result ) { |
---|
| 474 | *out++ = result; |
---|
| 475 | } else { |
---|
| 476 | } // if |
---|
| 477 | } catch( SemanticError &e ) { |
---|
| 478 | errors.append( e ); |
---|
| 479 | } // try |
---|
| 480 | cur = dynamic_cast< NodeType *>( cur->get_link() ); |
---|
| 481 | } // while |
---|
| 482 | if ( !errors.isEmpty() ) { |
---|
| 483 | throw errors; |
---|
| 484 | } // if |
---|
[51b7345] | 485 | } |
---|
| 486 | |
---|
| 487 | // in DeclarationNode.cc |
---|
[bdd516a] | 488 | void buildList( const DeclarationNode *firstNode, std::list< Declaration *> &outputList ); |
---|
| 489 | void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList ); |
---|
| 490 | void buildTypeList( const DeclarationNode *firstNode, std::list< Type *> &outputList ); |
---|
[51b7345] | 491 | |
---|
| 492 | // in ExpressionNode.cc |
---|
| 493 | ExpressionNode *flattenCommas( ExpressionNode *list ); |
---|
| 494 | ExpressionNode *tupleContents( ExpressionNode *tuple ); |
---|
| 495 | |
---|
[bdd516a] | 496 | #endif // PARSENODE_H |
---|
[51b7345] | 497 | |
---|
| 498 | // Local Variables: // |
---|
| 499 | // mode: C++ // |
---|
| 500 | // compile-command: "gmake" // |
---|
| 501 | // End: // |
---|