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