[b87a5ed] | 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 |
|
---|
[51b73452] | 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 {
|
---|
[bdd516a] | 37 | public:
|
---|
[b87a5ed] | 38 | ParseNode( void );
|
---|
| 39 | ParseNode ( std::string );
|
---|
| 40 | virtual ~ParseNode( void );
|
---|
[51b73452] | 41 |
|
---|
[b87a5ed] | 42 | ParseNode *set_name ( std::string ) ;
|
---|
| 43 | ParseNode *set_name ( std::string * ) ;
|
---|
[51b73452] | 44 |
|
---|
[b87a5ed] | 45 | std::string get_name( void );
|
---|
[51b73452] | 46 |
|
---|
[b87a5ed] | 47 | ParseNode *get_link( void ) const;
|
---|
| 48 | ParseNode *get_last( void );
|
---|
| 49 | ParseNode *set_link( ParseNode * );
|
---|
| 50 | void set_next( ParseNode *newlink ) { next = newlink; }
|
---|
[51b73452] | 51 |
|
---|
[b87a5ed] | 52 | virtual ParseNode *clone() const { return 0; };
|
---|
[51b73452] | 53 |
|
---|
[b87a5ed] | 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;
|
---|
[51b73452] | 57 |
|
---|
[b87a5ed] | 58 | ParseNode &operator,( ParseNode &);
|
---|
[bdd516a] | 59 | protected:
|
---|
[b87a5ed] | 60 | std::string name;
|
---|
| 61 | ParseNode *next;
|
---|
| 62 | static int indent_by;
|
---|
[51b73452] | 63 | };
|
---|
| 64 |
|
---|
[bdd516a] | 65 | ParseNode *mkList( ParseNode & );
|
---|
[51b73452] | 66 |
|
---|
| 67 | class ExpressionNode : public ParseNode {
|
---|
[bdd516a] | 68 | public:
|
---|
[b87a5ed] | 69 | ExpressionNode();
|
---|
| 70 | ExpressionNode( std::string * );
|
---|
| 71 | ExpressionNode( const ExpressionNode &other );
|
---|
| 72 | virtual ~ExpressionNode() {} // cannot delete asArgName because it might be referenced elsewhere
|
---|
[51b73452] | 73 |
|
---|
[b87a5ed] | 74 | virtual ExpressionNode *clone() const = 0;
|
---|
[51b73452] | 75 |
|
---|
[b87a5ed] | 76 | virtual CommaExprNode *add_to_list( ExpressionNode * );
|
---|
[51b73452] | 77 |
|
---|
[b87a5ed] | 78 | ExpressionNode *get_argName() const { return argName; }
|
---|
| 79 | ExpressionNode *set_asArgName( std::string *aName );
|
---|
| 80 | ExpressionNode *set_asArgName( ExpressionNode *aDesignator );
|
---|
[51b73452] | 81 |
|
---|
[b87a5ed] | 82 | virtual void print( std::ostream &, int indent = 0) const = 0;
|
---|
| 83 | virtual void printOneLine( std::ostream &, int indent = 0) const = 0;
|
---|
[51b73452] | 84 |
|
---|
[b87a5ed] | 85 | virtual Expression *build() const = 0;
|
---|
[bdd516a] | 86 | protected:
|
---|
[b87a5ed] | 87 | void printDesignation ( std::ostream &, int indent = 0) const;
|
---|
[bdd516a] | 88 | private:
|
---|
[b87a5ed] | 89 | ExpressionNode *argName;
|
---|
[51b73452] | 90 | };
|
---|
| 91 |
|
---|
[bdd516a] | 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:
|
---|
[b87a5ed] | 95 | NullExprNode();
|
---|
[51b73452] | 96 |
|
---|
[b87a5ed] | 97 | virtual NullExprNode *clone() const;
|
---|
[51b73452] | 98 |
|
---|
[b87a5ed] | 99 | virtual void print( std::ostream &, int indent = 0) const;
|
---|
| 100 | virtual void printOneLine( std::ostream &, int indent = 0) const;
|
---|
[51b73452] | 101 |
|
---|
[b87a5ed] | 102 | virtual Expression *build() const;
|
---|
[51b73452] | 103 | };
|
---|
| 104 |
|
---|
| 105 | class ConstantNode : public ExpressionNode {
|
---|
[bdd516a] | 106 | public:
|
---|
[b87a5ed] | 107 | enum Type {
|
---|
| 108 | Integer, Float, Character, String /* , Range, EnumConstant */
|
---|
| 109 | };
|
---|
[bdd516a] | 110 |
|
---|
[b87a5ed] | 111 | ConstantNode( void );
|
---|
| 112 | ConstantNode( std::string * );
|
---|
| 113 | ConstantNode( Type, std::string * );
|
---|
| 114 | ConstantNode( const ConstantNode &other );
|
---|
[bdd516a] | 115 |
|
---|
[b87a5ed] | 116 | virtual ConstantNode *clone() const { return new ConstantNode( *this ); }
|
---|
[bdd516a] | 117 |
|
---|
[b87a5ed] | 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;
|
---|
[bdd516a] | 121 |
|
---|
[b87a5ed] | 122 | std::string get_value() const { return value; }
|
---|
| 123 | ConstantNode *append( std::string *newValue );
|
---|
[bdd516a] | 124 |
|
---|
[b87a5ed] | 125 | Expression *build() const;
|
---|
[bdd516a] | 126 | private:
|
---|
[b87a5ed] | 127 | void classify( std::string &);
|
---|
| 128 | Type type;
|
---|
| 129 | std::string value;
|
---|
| 130 | bool sign;
|
---|
| 131 | short base;
|
---|
| 132 | int longs, size;
|
---|
[51b73452] | 133 | };
|
---|
| 134 |
|
---|
| 135 | class VarRefNode : public ExpressionNode {
|
---|
[bdd516a] | 136 | public:
|
---|
[b87a5ed] | 137 | VarRefNode();
|
---|
| 138 | VarRefNode( std::string *, bool isLabel = false );
|
---|
| 139 | VarRefNode( const VarRefNode &other );
|
---|
[51b73452] | 140 |
|
---|
[b87a5ed] | 141 | virtual Expression *build() const ;
|
---|
[51b73452] | 142 |
|
---|
[b87a5ed] | 143 | virtual VarRefNode *clone() const { return new VarRefNode( *this ); }
|
---|
[51b73452] | 144 |
|
---|
[b87a5ed] | 145 | virtual void print( std::ostream &, int indent = 0) const;
|
---|
| 146 | virtual void printOneLine( std::ostream &, int indent = 0) const;
|
---|
[bdd516a] | 147 | private:
|
---|
[b87a5ed] | 148 | bool isLabel;
|
---|
[51b73452] | 149 | };
|
---|
| 150 |
|
---|
[bdd516a] | 151 | class TypeValueNode : public ExpressionNode {
|
---|
| 152 | public:
|
---|
[b87a5ed] | 153 | TypeValueNode( DeclarationNode * );
|
---|
| 154 | TypeValueNode( const TypeValueNode &other );
|
---|
[51b73452] | 155 |
|
---|
[b87a5ed] | 156 | DeclarationNode *get_decl() const { return decl; }
|
---|
[51b73452] | 157 |
|
---|
[b87a5ed] | 158 | virtual Expression *build() const ;
|
---|
[51b73452] | 159 |
|
---|
[b87a5ed] | 160 | virtual TypeValueNode *clone() const { return new TypeValueNode( *this ); }
|
---|
[51b73452] | 161 |
|
---|
[b87a5ed] | 162 | virtual void print( std::ostream &, int indent = 0) const;
|
---|
| 163 | virtual void printOneLine( std::ostream &, int indent = 0) const;
|
---|
[bdd516a] | 164 | private:
|
---|
[b87a5ed] | 165 | DeclarationNode *decl;
|
---|
[51b73452] | 166 | };
|
---|
| 167 |
|
---|
| 168 | class OperatorNode : public ExpressionNode {
|
---|
[bdd516a] | 169 | public:
|
---|
[b87a5ed] | 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 | };
|
---|
[51b73452] | 178 |
|
---|
[b87a5ed] | 179 | OperatorNode( Type t );
|
---|
| 180 | OperatorNode( const OperatorNode &other );
|
---|
| 181 | virtual ~OperatorNode();
|
---|
[51b73452] | 182 |
|
---|
[b87a5ed] | 183 | virtual OperatorNode *clone() const { return new OperatorNode( *this ); }
|
---|
[51b73452] | 184 |
|
---|
[b87a5ed] | 185 | Type get_type( void ) const;
|
---|
| 186 | std::string get_typename( void ) const;
|
---|
[51b73452] | 187 |
|
---|
[b87a5ed] | 188 | virtual void print( std::ostream &, int indent = 0) const;
|
---|
| 189 | virtual void printOneLine( std::ostream &, int indent = 0) const;
|
---|
[51b73452] | 190 |
|
---|
[b87a5ed] | 191 | virtual Expression *build() const { return 0; }
|
---|
[bdd516a] | 192 | private:
|
---|
[b87a5ed] | 193 | Type type;
|
---|
| 194 | static const char *OpName[];
|
---|
[51b73452] | 195 | };
|
---|
| 196 |
|
---|
| 197 |
|
---|
| 198 | class CompositeExprNode : public ExpressionNode {
|
---|
[bdd516a] | 199 | public:
|
---|
[b87a5ed] | 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();
|
---|
[bdd516a] | 206 |
|
---|
[b87a5ed] | 207 | virtual CompositeExprNode *clone() const { return new CompositeExprNode( *this ); }
|
---|
| 208 | virtual Expression *build() const;
|
---|
[bdd516a] | 209 |
|
---|
[b87a5ed] | 210 | virtual void print( std::ostream &, int indent = 0) const;
|
---|
| 211 | virtual void printOneLine( std::ostream &, int indent = 0) const;
|
---|
[bdd516a] | 212 |
|
---|
[b87a5ed] | 213 | void set_function( ExpressionNode * );
|
---|
| 214 | void set_args( ExpressionNode * );
|
---|
[bdd516a] | 215 |
|
---|
[b87a5ed] | 216 | void add_arg( ExpressionNode * );
|
---|
[bdd516a] | 217 |
|
---|
[b87a5ed] | 218 | ExpressionNode *get_function() const;
|
---|
| 219 | ExpressionNode *get_args() const;
|
---|
[bdd516a] | 220 | private:
|
---|
[b87a5ed] | 221 | ExpressionNode *function;
|
---|
| 222 | ExpressionNode *arguments;
|
---|
[51b73452] | 223 | };
|
---|
| 224 |
|
---|
| 225 | class CommaExprNode : public CompositeExprNode {
|
---|
[bdd516a] | 226 | public:
|
---|
[b87a5ed] | 227 | CommaExprNode();
|
---|
| 228 | CommaExprNode( ExpressionNode * );
|
---|
| 229 | CommaExprNode( ExpressionNode *, ExpressionNode * );
|
---|
| 230 | CommaExprNode( const CommaExprNode &other );
|
---|
[bdd516a] | 231 |
|
---|
[b87a5ed] | 232 | virtual CommaExprNode *add_to_list( ExpressionNode * );
|
---|
| 233 | virtual CommaExprNode *clone() const { return new CommaExprNode( *this ); }
|
---|
[51b73452] | 234 | };
|
---|
| 235 |
|
---|
| 236 | class ForCtlExprNode : public ExpressionNode {
|
---|
[bdd516a] | 237 | public:
|
---|
[b87a5ed] | 238 | ForCtlExprNode( ParseNode *, ExpressionNode *, ExpressionNode * ) throw ( SemanticError );
|
---|
| 239 | ForCtlExprNode( const ForCtlExprNode &other );
|
---|
| 240 | ~ForCtlExprNode();
|
---|
[bdd516a] | 241 |
|
---|
[b87a5ed] | 242 | StatementNode *get_init() const { return init; }
|
---|
| 243 | ExpressionNode *get_condition() const { return condition; }
|
---|
| 244 | ExpressionNode *get_change() const { return change; }
|
---|
[bdd516a] | 245 |
|
---|
[b87a5ed] | 246 | virtual ForCtlExprNode *clone() const { return new ForCtlExprNode( *this ); }
|
---|
| 247 | virtual Expression *build() const;
|
---|
[bdd516a] | 248 |
|
---|
[b87a5ed] | 249 | virtual void print( std::ostream &, int indent = 0 ) const;
|
---|
| 250 | virtual void printOneLine( std::ostream &, int indent = 0 ) const;
|
---|
[bdd516a] | 251 | private:
|
---|
[b87a5ed] | 252 | StatementNode *init;
|
---|
| 253 | ExpressionNode *condition;
|
---|
| 254 | ExpressionNode *change;
|
---|
[51b73452] | 255 | };
|
---|
| 256 |
|
---|
| 257 | class ValofExprNode : public ExpressionNode {
|
---|
[bdd516a] | 258 | public:
|
---|
[b87a5ed] | 259 | ValofExprNode();
|
---|
| 260 | ValofExprNode( StatementNode *s = 0 );
|
---|
| 261 | ValofExprNode( const ValofExprNode &other );
|
---|
| 262 | ~ValofExprNode();
|
---|
[51b73452] | 263 |
|
---|
[b87a5ed] | 264 | virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); }
|
---|
[51b73452] | 265 |
|
---|
[b87a5ed] | 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;
|
---|
[51b73452] | 270 |
|
---|
[bdd516a] | 271 | private:
|
---|
[b87a5ed] | 272 | StatementNode *body;
|
---|
[51b73452] | 273 | };
|
---|
| 274 |
|
---|
| 275 | class TypeData;
|
---|
| 276 |
|
---|
[bdd516a] | 277 | class DeclarationNode : public ParseNode {
|
---|
| 278 | public:
|
---|
[b87a5ed] | 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();
|
---|
[bdd516a] | 358 | private:
|
---|
[b87a5ed] | 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;
|
---|
[51b73452] | 371 | };
|
---|
| 372 |
|
---|
| 373 | class StatementNode : public ParseNode {
|
---|
[bdd516a] | 374 | public:
|
---|
[b87a5ed] | 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 | };
|
---|
[51b73452] | 381 |
|
---|
[b87a5ed] | 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 );
|
---|
[51b73452] | 387 |
|
---|
| 388 |
|
---|
[b87a5ed] | 389 | ~StatementNode( void );
|
---|
[51b73452] | 390 |
|
---|
[b87a5ed] | 391 | static StatementNode *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false );
|
---|
[51b73452] | 392 |
|
---|
[b87a5ed] | 393 | void set_control( ExpressionNode * );
|
---|
| 394 | StatementNode * set_block( StatementNode * );
|
---|
[51b73452] | 395 |
|
---|
[b87a5ed] | 396 | ExpressionNode *get_control() const ;
|
---|
| 397 | StatementNode *get_block() const;
|
---|
| 398 | StatementNode::Type get_type( void ) const;
|
---|
[51b73452] | 399 |
|
---|
[b87a5ed] | 400 | StatementNode *add_label( std::string * );
|
---|
| 401 | std::list<std::string> *get_labels() const;
|
---|
[51b73452] | 402 |
|
---|
[b87a5ed] | 403 | void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; }
|
---|
| 404 | void setCatchRest( bool newVal ) { isCatchRest = newVal; }
|
---|
[51b73452] | 405 |
|
---|
[b87a5ed] | 406 | std::string get_target() const;
|
---|
[51b73452] | 407 |
|
---|
[b87a5ed] | 408 | StatementNode *add_controlexp( ExpressionNode * );
|
---|
| 409 | StatementNode *append_block( StatementNode * );
|
---|
| 410 | StatementNode *append_last_case( StatementNode * );
|
---|
[51b73452] | 411 |
|
---|
[b87a5ed] | 412 | void print( std::ostream &, int indent = 0) const;
|
---|
[51b73452] | 413 |
|
---|
[b87a5ed] | 414 | virtual StatementNode *clone() const;
|
---|
[51b73452] | 415 |
|
---|
[b87a5ed] | 416 | virtual Statement *build() const;
|
---|
[bdd516a] | 417 | private:
|
---|
[b87a5ed] | 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;
|
---|
[51b73452] | 427 | };
|
---|
| 428 |
|
---|
| 429 | class CompoundStmtNode : public StatementNode {
|
---|
[bdd516a] | 430 | public:
|
---|
[b87a5ed] | 431 | CompoundStmtNode( void );
|
---|
| 432 | CompoundStmtNode( std::string * );
|
---|
| 433 | CompoundStmtNode( StatementNode * );
|
---|
| 434 | ~CompoundStmtNode();
|
---|
[51b73452] | 435 |
|
---|
[b87a5ed] | 436 | void add_statement( StatementNode * );
|
---|
[51b73452] | 437 |
|
---|
[b87a5ed] | 438 | void print( std::ostream &, int indent = 0 ) const;
|
---|
[51b73452] | 439 |
|
---|
[b87a5ed] | 440 | virtual Statement *build() const;
|
---|
[bdd516a] | 441 | private:
|
---|
[b87a5ed] | 442 | StatementNode *first, *last;
|
---|
[51b73452] | 443 | };
|
---|
| 444 |
|
---|
| 445 | class NullStmtNode : public CompoundStmtNode {
|
---|
[bdd516a] | 446 | public:
|
---|
[b87a5ed] | 447 | Statement *build() const;
|
---|
| 448 | void print( std::ostream &, int indent = 0) const;
|
---|
[51b73452] | 449 | };
|
---|
| 450 |
|
---|
| 451 | class InitializerNode : public ParseNode {
|
---|
[bdd516a] | 452 | public:
|
---|
[b87a5ed] | 453 | InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode *des = 0 );
|
---|
| 454 | InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 );
|
---|
| 455 | ~InitializerNode();
|
---|
[51b73452] | 456 |
|
---|
[b87a5ed] | 457 | ExpressionNode *get_expression() const { return expr; }
|
---|
[51b73452] | 458 |
|
---|
[b87a5ed] | 459 | InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; }
|
---|
| 460 | ExpressionNode *get_designators() const { return designator; }
|
---|
[51b73452] | 461 |
|
---|
[b87a5ed] | 462 | InitializerNode *next_init() const { return kids; }
|
---|
[51b73452] | 463 |
|
---|
[b87a5ed] | 464 | void print( std::ostream &, int indent = 0 ) const;
|
---|
| 465 | void printOneLine( std::ostream & ) const;
|
---|
[51b73452] | 466 |
|
---|
[b87a5ed] | 467 | virtual Initializer *build() const;
|
---|
[bdd516a] | 468 | private:
|
---|
[b87a5ed] | 469 | ExpressionNode *expr;
|
---|
| 470 | bool aggregate;
|
---|
| 471 | ExpressionNode *designator; // may be list
|
---|
| 472 | InitializerNode *kids;
|
---|
[51b73452] | 473 | };
|
---|
| 474 |
|
---|
| 475 |
|
---|
| 476 |
|
---|
| 477 | template< typename SynTreeType, typename NodeType >
|
---|
[b87a5ed] | 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
|
---|
[a32b204] | 495 | if ( ! errors.isEmpty() ) {
|
---|
[b87a5ed] | 496 | throw errors;
|
---|
| 497 | } // if
|
---|
[51b73452] | 498 | }
|
---|
| 499 |
|
---|
| 500 | // in DeclarationNode.cc
|
---|
[bdd516a] | 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 );
|
---|
[51b73452] | 504 |
|
---|
| 505 | // in ExpressionNode.cc
|
---|
| 506 | ExpressionNode *flattenCommas( ExpressionNode *list );
|
---|
| 507 | ExpressionNode *tupleContents( ExpressionNode *tuple );
|
---|
| 508 |
|
---|
[bdd516a] | 509 | #endif // PARSENODE_H
|
---|
[51b73452] | 510 |
|
---|
| 511 | // Local Variables: //
|
---|
[b87a5ed] | 512 | // tab-width: 4 //
|
---|
| 513 | // mode: c++ //
|
---|
| 514 | // compile-command: "make install" //
|
---|
[51b73452] | 515 | // End: //
|
---|