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