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