[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 |
---|
[51b1202] | 12 | // Last Modified On : Tue Aug 11 15:11:29 2015 |
---|
| 13 | // Update Count : 145 |
---|
[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 ); |
---|
[7f5566b] | 69 | virtual ~ExpressionNode() { delete argName; } // cannot delete argName 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; } |
---|
[7f5566b] | 76 | ExpressionNode *set_argName( const std::string *aName ); |
---|
| 77 | ExpressionNode *set_argName( 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 * ); |
---|
[7f5566b] | 107 | ~ConstantNode() { delete &value; } |
---|
[bdd516a] | 108 | |
---|
[b87a5ed] | 109 | virtual ConstantNode *clone() const { return new ConstantNode( *this ); } |
---|
[cd623a4] | 110 | Type get_type( void ) const { return type; } |
---|
[b87a5ed] | 111 | virtual void print( std::ostream &, int indent = 0) const; |
---|
| 112 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
[bdd516a] | 113 | |
---|
[59db689] | 114 | const std::string &get_value() const { return value; } |
---|
| 115 | ConstantNode *appendstr( const std::string *newValue ); |
---|
[bdd516a] | 116 | |
---|
[b87a5ed] | 117 | Expression *build() const; |
---|
[bdd516a] | 118 | private: |
---|
[b87a5ed] | 119 | Type type; |
---|
[59db689] | 120 | BasicType::Kind btype; |
---|
| 121 | std::string &value; |
---|
[51b7345] | 122 | }; |
---|
| 123 | |
---|
| 124 | class VarRefNode : public ExpressionNode { |
---|
[bdd516a] | 125 | public: |
---|
[b87a5ed] | 126 | VarRefNode(); |
---|
[59db689] | 127 | VarRefNode( const std::string *, bool isLabel = false ); |
---|
[b87a5ed] | 128 | VarRefNode( const VarRefNode &other ); |
---|
[51b7345] | 129 | |
---|
[b87a5ed] | 130 | virtual Expression *build() const ; |
---|
[51b7345] | 131 | |
---|
[b87a5ed] | 132 | virtual VarRefNode *clone() const { return new VarRefNode( *this ); } |
---|
[51b7345] | 133 | |
---|
[59db689] | 134 | virtual void print( std::ostream &, int indent = 0 ) const; |
---|
| 135 | virtual void printOneLine( std::ostream &, int indent = 0 ) const; |
---|
[bdd516a] | 136 | private: |
---|
[b87a5ed] | 137 | bool isLabel; |
---|
[51b7345] | 138 | }; |
---|
| 139 | |
---|
[51b1202] | 140 | class DesignatorNode : public ExpressionNode { |
---|
| 141 | public: |
---|
| 142 | DesignatorNode( ExpressionNode *expr, bool isArrayIndex = false ); |
---|
| 143 | DesignatorNode( const DesignatorNode &other ); |
---|
| 144 | |
---|
| 145 | virtual Expression *build() const ; |
---|
| 146 | virtual DesignatorNode *clone() const { return new DesignatorNode( *this ); } |
---|
| 147 | |
---|
| 148 | virtual void print( std::ostream &, int indent = 0 ) const; |
---|
| 149 | virtual void printOneLine( std::ostream &, int indent = 0 ) const; |
---|
| 150 | private: |
---|
| 151 | bool isArrayIndex; |
---|
| 152 | }; |
---|
| 153 | |
---|
[bdd516a] | 154 | class TypeValueNode : public ExpressionNode { |
---|
| 155 | public: |
---|
[b87a5ed] | 156 | TypeValueNode( DeclarationNode * ); |
---|
| 157 | TypeValueNode( const TypeValueNode &other ); |
---|
[51b7345] | 158 | |
---|
[b87a5ed] | 159 | DeclarationNode *get_decl() const { return decl; } |
---|
[51b7345] | 160 | |
---|
[b87a5ed] | 161 | virtual Expression *build() const ; |
---|
[51b7345] | 162 | |
---|
[b87a5ed] | 163 | virtual TypeValueNode *clone() const { return new TypeValueNode( *this ); } |
---|
[51b7345] | 164 | |
---|
[b87a5ed] | 165 | virtual void print( std::ostream &, int indent = 0) const; |
---|
| 166 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
[bdd516a] | 167 | private: |
---|
[b87a5ed] | 168 | DeclarationNode *decl; |
---|
[51b7345] | 169 | }; |
---|
| 170 | |
---|
| 171 | class OperatorNode : public ExpressionNode { |
---|
[bdd516a] | 172 | public: |
---|
[b87a5ed] | 173 | enum Type { TupleC, Comma, TupleFieldSel, |
---|
| 174 | Cond, NCond, |
---|
| 175 | SizeOf, AlignOf, Attr, CompLit, Plus, Minus, Mul, Div, Mod, Or, And, |
---|
| 176 | BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq, |
---|
| 177 | Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, |
---|
| 178 | ERAssn, OrAssn, Index, FieldSel, PFieldSel, Range, |
---|
| 179 | UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress |
---|
| 180 | }; |
---|
[51b7345] | 181 | |
---|
[b87a5ed] | 182 | OperatorNode( Type t ); |
---|
| 183 | OperatorNode( const OperatorNode &other ); |
---|
| 184 | virtual ~OperatorNode(); |
---|
[51b7345] | 185 | |
---|
[b87a5ed] | 186 | virtual OperatorNode *clone() const { return new OperatorNode( *this ); } |
---|
[51b7345] | 187 | |
---|
[59db689] | 188 | Type get_type() const; |
---|
| 189 | const char *get_typename() const; |
---|
[51b7345] | 190 | |
---|
[b87a5ed] | 191 | virtual void print( std::ostream &, int indent = 0) const; |
---|
| 192 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
[51b7345] | 193 | |
---|
[b87a5ed] | 194 | virtual Expression *build() const { return 0; } |
---|
[bdd516a] | 195 | private: |
---|
[b87a5ed] | 196 | Type type; |
---|
| 197 | static const char *OpName[]; |
---|
[51b7345] | 198 | }; |
---|
| 199 | |
---|
| 200 | class CompositeExprNode : public ExpressionNode { |
---|
[bdd516a] | 201 | public: |
---|
[59db689] | 202 | CompositeExprNode(); |
---|
| 203 | CompositeExprNode( const std::string * ); |
---|
[b87a5ed] | 204 | CompositeExprNode( ExpressionNode *f, ExpressionNode *args = 0 ); |
---|
| 205 | CompositeExprNode( ExpressionNode *f, ExpressionNode *arg1, ExpressionNode *arg2 ); |
---|
| 206 | CompositeExprNode( const CompositeExprNode &other ); |
---|
| 207 | virtual ~CompositeExprNode(); |
---|
[bdd516a] | 208 | |
---|
[b87a5ed] | 209 | virtual CompositeExprNode *clone() const { return new CompositeExprNode( *this ); } |
---|
| 210 | virtual Expression *build() const; |
---|
[bdd516a] | 211 | |
---|
[b87a5ed] | 212 | virtual void print( std::ostream &, int indent = 0) const; |
---|
| 213 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
[bdd516a] | 214 | |
---|
[b87a5ed] | 215 | void set_function( ExpressionNode * ); |
---|
| 216 | void set_args( ExpressionNode * ); |
---|
[bdd516a] | 217 | |
---|
[b87a5ed] | 218 | void add_arg( ExpressionNode * ); |
---|
[bdd516a] | 219 | |
---|
[b87a5ed] | 220 | ExpressionNode *get_function() const; |
---|
| 221 | ExpressionNode *get_args() const; |
---|
[bdd516a] | 222 | private: |
---|
[b87a5ed] | 223 | ExpressionNode *function; |
---|
| 224 | ExpressionNode *arguments; |
---|
[51b7345] | 225 | }; |
---|
| 226 | |
---|
[7f5566b] | 227 | class AsmExprNode : public ExpressionNode { |
---|
| 228 | public: |
---|
| 229 | AsmExprNode(); |
---|
| 230 | AsmExprNode( ExpressionNode *inout, ConstantNode *constraint, ExpressionNode *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {} |
---|
| 231 | virtual ~AsmExprNode() { delete inout; delete constraint; delete operand; } |
---|
| 232 | |
---|
| 233 | virtual AsmExprNode *clone() const { return new AsmExprNode( *this ); } |
---|
| 234 | virtual Expression *build() const; |
---|
| 235 | |
---|
| 236 | virtual void print( std::ostream &, int indent = 0) const; |
---|
| 237 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
| 238 | |
---|
| 239 | ExpressionNode *get_inout() const { return inout; }; |
---|
| 240 | void set_inout( ExpressionNode *newValue ) { inout = newValue; } |
---|
| 241 | |
---|
| 242 | ConstantNode *get_constraint() const { return constraint; }; |
---|
| 243 | void set_constraint( ConstantNode *newValue ) { constraint = newValue; } |
---|
| 244 | |
---|
| 245 | ExpressionNode *get_operand() const { return operand; }; |
---|
| 246 | void set_operand( ExpressionNode *newValue ) { operand = newValue; } |
---|
| 247 | private: |
---|
| 248 | ExpressionNode *inout; |
---|
| 249 | ConstantNode *constraint; |
---|
| 250 | ExpressionNode *operand; |
---|
| 251 | }; |
---|
| 252 | |
---|
| 253 | class LabelNode : public ExpressionNode { |
---|
| 254 | public: |
---|
| 255 | virtual Expression *build() const { return NULL; } |
---|
| 256 | virtual LabelNode *clone() const { return new LabelNode( *this ); } |
---|
| 257 | |
---|
| 258 | virtual void print( std::ostream &, int indent = 0) const; |
---|
| 259 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
| 260 | |
---|
| 261 | const std::list< std::string > &get_labels() const { return labels; }; |
---|
| 262 | void append_label( std::string *label ) { labels.push_back( *label ); delete label; } |
---|
| 263 | private: |
---|
| 264 | std::list< std::string > labels; |
---|
| 265 | }; |
---|
| 266 | |
---|
[51b7345] | 267 | class CommaExprNode : public CompositeExprNode { |
---|
[bdd516a] | 268 | public: |
---|
[b87a5ed] | 269 | CommaExprNode(); |
---|
| 270 | CommaExprNode( ExpressionNode * ); |
---|
| 271 | CommaExprNode( ExpressionNode *, ExpressionNode * ); |
---|
| 272 | CommaExprNode( const CommaExprNode &other ); |
---|
[bdd516a] | 273 | |
---|
[b87a5ed] | 274 | virtual CommaExprNode *add_to_list( ExpressionNode * ); |
---|
| 275 | virtual CommaExprNode *clone() const { return new CommaExprNode( *this ); } |
---|
[51b7345] | 276 | }; |
---|
| 277 | |
---|
| 278 | class ForCtlExprNode : public ExpressionNode { |
---|
[bdd516a] | 279 | public: |
---|
[b87a5ed] | 280 | ForCtlExprNode( ParseNode *, ExpressionNode *, ExpressionNode * ) throw ( SemanticError ); |
---|
| 281 | ForCtlExprNode( const ForCtlExprNode &other ); |
---|
| 282 | ~ForCtlExprNode(); |
---|
[bdd516a] | 283 | |
---|
[b87a5ed] | 284 | StatementNode *get_init() const { return init; } |
---|
| 285 | ExpressionNode *get_condition() const { return condition; } |
---|
| 286 | ExpressionNode *get_change() const { return change; } |
---|
[bdd516a] | 287 | |
---|
[b87a5ed] | 288 | virtual ForCtlExprNode *clone() const { return new ForCtlExprNode( *this ); } |
---|
| 289 | virtual Expression *build() const; |
---|
[bdd516a] | 290 | |
---|
[b87a5ed] | 291 | virtual void print( std::ostream &, int indent = 0 ) const; |
---|
| 292 | virtual void printOneLine( std::ostream &, int indent = 0 ) const; |
---|
[bdd516a] | 293 | private: |
---|
[b87a5ed] | 294 | StatementNode *init; |
---|
| 295 | ExpressionNode *condition; |
---|
| 296 | ExpressionNode *change; |
---|
[51b7345] | 297 | }; |
---|
| 298 | |
---|
| 299 | class ValofExprNode : public ExpressionNode { |
---|
[bdd516a] | 300 | public: |
---|
[b87a5ed] | 301 | ValofExprNode(); |
---|
| 302 | ValofExprNode( StatementNode *s = 0 ); |
---|
| 303 | ValofExprNode( const ValofExprNode &other ); |
---|
| 304 | ~ValofExprNode(); |
---|
[51b7345] | 305 | |
---|
[b87a5ed] | 306 | virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); } |
---|
[51b7345] | 307 | |
---|
[b87a5ed] | 308 | StatementNode *get_body() const { return body; } |
---|
| 309 | void print( std::ostream &, int indent = 0 ) const; |
---|
| 310 | void printOneLine( std::ostream &, int indent = 0 ) const; |
---|
| 311 | Expression *build() const; |
---|
[51b7345] | 312 | |
---|
[bdd516a] | 313 | private: |
---|
[b87a5ed] | 314 | StatementNode *body; |
---|
[51b7345] | 315 | }; |
---|
| 316 | |
---|
| 317 | class TypeData; |
---|
| 318 | |
---|
[bdd516a] | 319 | class DeclarationNode : public ParseNode { |
---|
| 320 | public: |
---|
[1db21619] | 321 | enum Qualifier { Const, Restrict, Volatile, Lvalue, Atomic }; |
---|
[68cd1ce] | 322 | enum StorageClass { Extern, Static, Auto, Register, Inline, Fortran, Noreturn, Threadlocal, NoStorageClass, }; |
---|
[b87a5ed] | 323 | enum BasicType { Char, Int, Float, Double, Void, Bool, Complex, Imaginary }; |
---|
[68cd1ce] | 324 | enum Modifier { Signed, Unsigned, Short, Long }; |
---|
| 325 | enum Aggregate { Struct, Union, Context }; |
---|
[b87a5ed] | 326 | enum TypeClass { Type, Dtype, Ftype }; |
---|
| 327 | |
---|
[68cd1ce] | 328 | static const char *storageName[]; |
---|
[b87a5ed] | 329 | static const char *qualifierName[]; |
---|
| 330 | static const char *basicTypeName[]; |
---|
| 331 | static const char *modifierName[]; |
---|
[68cd1ce] | 332 | static const char *aggregateName[]; |
---|
[b87a5ed] | 333 | static const char *typeClassName[]; |
---|
| 334 | |
---|
[7f5566b] | 335 | static DeclarationNode *newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle = false ); |
---|
[b87a5ed] | 336 | static DeclarationNode *newQualifier( Qualifier ); |
---|
| 337 | static DeclarationNode *newStorageClass( StorageClass ); |
---|
| 338 | static DeclarationNode *newBasicType( BasicType ); |
---|
| 339 | static DeclarationNode *newModifier( Modifier ); |
---|
| 340 | static DeclarationNode *newForall( DeclarationNode *); |
---|
| 341 | static DeclarationNode *newFromTypedef( std::string *); |
---|
[2871210] | 342 | static DeclarationNode *newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields ); |
---|
[b87a5ed] | 343 | static DeclarationNode *newEnum( std::string *name, DeclarationNode *constants ); |
---|
| 344 | static DeclarationNode *newEnumConstant( std::string *name, ExpressionNode *constant ); |
---|
| 345 | static DeclarationNode *newName( std::string *); |
---|
[59db689] | 346 | static DeclarationNode *newFromTypeGen( std::string *, ExpressionNode *params ); |
---|
[b87a5ed] | 347 | static DeclarationNode *newTypeParam( TypeClass, std::string *); |
---|
| 348 | static DeclarationNode *newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts ); |
---|
| 349 | static DeclarationNode *newContextUse( std::string *name, ExpressionNode *params ); |
---|
| 350 | static DeclarationNode *newTypeDecl( std::string *name, DeclarationNode *typeParams ); |
---|
| 351 | static DeclarationNode *newPointer( DeclarationNode *qualifiers ); |
---|
| 352 | static DeclarationNode *newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ); |
---|
| 353 | static DeclarationNode *newVarArray( DeclarationNode *qualifiers ); |
---|
| 354 | static DeclarationNode *newBitfield( ExpressionNode *size ); |
---|
| 355 | static DeclarationNode *newTuple( DeclarationNode *members ); |
---|
| 356 | static DeclarationNode *newTypeof( ExpressionNode *expr ); |
---|
[59db689] | 357 | static DeclarationNode *newAttr( std::string *, ExpressionNode *expr ); |
---|
| 358 | static DeclarationNode *newAttr( std::string *, DeclarationNode *type ); |
---|
[b87a5ed] | 359 | |
---|
| 360 | DeclarationNode *addQualifiers( DeclarationNode *); |
---|
| 361 | DeclarationNode *copyStorageClasses( DeclarationNode *); |
---|
| 362 | DeclarationNode *addType( DeclarationNode *); |
---|
| 363 | DeclarationNode *addTypedef(); |
---|
| 364 | DeclarationNode *addAssertions( DeclarationNode *); |
---|
| 365 | DeclarationNode *addName( std::string *); |
---|
| 366 | DeclarationNode *addBitfield( ExpressionNode *size ); |
---|
| 367 | DeclarationNode *addVarArgs(); |
---|
| 368 | DeclarationNode *addFunctionBody( StatementNode *body ); |
---|
| 369 | DeclarationNode *addOldDeclList( DeclarationNode *list ); |
---|
| 370 | DeclarationNode *addPointer( DeclarationNode *qualifiers ); |
---|
| 371 | DeclarationNode *addArray( DeclarationNode *array ); |
---|
| 372 | DeclarationNode *addNewPointer( DeclarationNode *pointer ); |
---|
| 373 | DeclarationNode *addNewArray( DeclarationNode *array ); |
---|
| 374 | DeclarationNode *addParamList( DeclarationNode *list ); |
---|
| 375 | DeclarationNode *addIdList( DeclarationNode *list ); // old-style functions |
---|
| 376 | DeclarationNode *addInitializer( InitializerNode *init ); |
---|
| 377 | |
---|
| 378 | DeclarationNode *cloneType( std::string *newName ); |
---|
| 379 | DeclarationNode *cloneType( DeclarationNode *existing ); |
---|
| 380 | DeclarationNode *cloneType( int ) { return cloneType( ( std::string *)0 ); } |
---|
| 381 | DeclarationNode *cloneBaseType( std::string *newName ); |
---|
| 382 | DeclarationNode *cloneBaseType( DeclarationNode *newdecl ); |
---|
| 383 | |
---|
[de62360d] | 384 | DeclarationNode *appendList( DeclarationNode * ); |
---|
[b87a5ed] | 385 | |
---|
| 386 | DeclarationNode *clone() const; |
---|
| 387 | void print( std::ostream &, int indent = 0 ) const; |
---|
| 388 | void printList( std::ostream &, int indent = 0 ) const; |
---|
| 389 | |
---|
| 390 | Declaration *build() const; |
---|
| 391 | ::Type *buildType() const; |
---|
| 392 | |
---|
| 393 | bool get_hasEllipsis() const; |
---|
[5f2f2d7] | 394 | const std::string &get_name() const { return name; } |
---|
[b87a5ed] | 395 | LinkageSpec::Type get_linkage() const { return linkage; } |
---|
| 396 | DeclarationNode *extractAggregate() const; |
---|
| 397 | |
---|
| 398 | DeclarationNode(); |
---|
| 399 | ~DeclarationNode(); |
---|
[bdd516a] | 400 | private: |
---|
[68cd1ce] | 401 | StorageClass buildStorageClass() const; |
---|
[de62360d] | 402 | bool buildFuncSpecifier( StorageClass key ) const; |
---|
[b87a5ed] | 403 | |
---|
| 404 | TypeData *type; |
---|
| 405 | std::string name; |
---|
| 406 | std::list< StorageClass > storageClasses; |
---|
[1db21619] | 407 | std::list< std::string > attributes; |
---|
[b87a5ed] | 408 | ExpressionNode *bitfieldWidth; |
---|
| 409 | InitializerNode *initializer; |
---|
| 410 | bool hasEllipsis; |
---|
| 411 | LinkageSpec::Type linkage; |
---|
| 412 | |
---|
| 413 | static UniqueName anonymous; |
---|
[1db21619] | 414 | }; // DeclarationNode |
---|
[51b7345] | 415 | |
---|
| 416 | class StatementNode : public ParseNode { |
---|
[bdd516a] | 417 | public: |
---|
[b87a5ed] | 418 | enum Type { Exp, If, Switch, Case, Default, Choose, Fallthru, |
---|
| 419 | While, Do, For, |
---|
| 420 | Goto, Continue, Break, Return, Throw, |
---|
| 421 | Try, Catch, Finally, Asm, |
---|
| 422 | Decl |
---|
| 423 | }; |
---|
[51b7345] | 424 | |
---|
[59db689] | 425 | StatementNode(); |
---|
[7f5566b] | 426 | StatementNode( const std::string *name ); |
---|
| 427 | StatementNode( Type t, ExpressionNode *control = 0, StatementNode *block = 0 ); |
---|
| 428 | StatementNode( Type t, std::string *target ); |
---|
[b87a5ed] | 429 | StatementNode( DeclarationNode *decl ); |
---|
[51b7345] | 430 | |
---|
[59db689] | 431 | ~StatementNode(); |
---|
[51b7345] | 432 | |
---|
[59db689] | 433 | static StatementNode *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false ); |
---|
[51b7345] | 434 | |
---|
[1db21619] | 435 | StatementNode *set_block( StatementNode *b ) { block = b; return this; } |
---|
| 436 | StatementNode *get_block() const { return block; } |
---|
| 437 | |
---|
| 438 | void set_control( ExpressionNode *c ) { control = c; } |
---|
| 439 | ExpressionNode *get_control() const { return control; } |
---|
[51b7345] | 440 | |
---|
[1db21619] | 441 | StatementNode::Type get_type() const { return type; } |
---|
[51b7345] | 442 | |
---|
[59db689] | 443 | StatementNode *add_label( const std::string * ); |
---|
[1db21619] | 444 | const std::list<std::string> &get_labels() const { return labels; } |
---|
[51b7345] | 445 | |
---|
[b87a5ed] | 446 | void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; } |
---|
| 447 | void setCatchRest( bool newVal ) { isCatchRest = newVal; } |
---|
[51b7345] | 448 | |
---|
[b87a5ed] | 449 | std::string get_target() const; |
---|
[51b7345] | 450 | |
---|
[b87a5ed] | 451 | StatementNode *add_controlexp( ExpressionNode * ); |
---|
| 452 | StatementNode *append_block( StatementNode * ); |
---|
| 453 | StatementNode *append_last_case( StatementNode * ); |
---|
[51b7345] | 454 | |
---|
[b87a5ed] | 455 | void print( std::ostream &, int indent = 0) const; |
---|
| 456 | virtual StatementNode *clone() const; |
---|
| 457 | virtual Statement *build() const; |
---|
[bdd516a] | 458 | private: |
---|
[b87a5ed] | 459 | static const char *StType[]; |
---|
| 460 | Type type; |
---|
| 461 | ExpressionNode *control; |
---|
| 462 | StatementNode *block; |
---|
[1db21619] | 463 | std::list<std::string> labels; |
---|
[b87a5ed] | 464 | std::string *target; // target label for jump statements |
---|
| 465 | DeclarationNode *decl; |
---|
| 466 | bool isCatchRest; |
---|
[1db21619] | 467 | }; // StatementNode |
---|
[51b7345] | 468 | |
---|
| 469 | class CompoundStmtNode : public StatementNode { |
---|
[bdd516a] | 470 | public: |
---|
[59db689] | 471 | CompoundStmtNode(); |
---|
| 472 | CompoundStmtNode( const std::string * ); |
---|
[b87a5ed] | 473 | CompoundStmtNode( StatementNode * ); |
---|
| 474 | ~CompoundStmtNode(); |
---|
[51b7345] | 475 | |
---|
[b87a5ed] | 476 | void add_statement( StatementNode * ); |
---|
[51b7345] | 477 | |
---|
[b87a5ed] | 478 | void print( std::ostream &, int indent = 0 ) const; |
---|
| 479 | virtual Statement *build() const; |
---|
[bdd516a] | 480 | private: |
---|
[b87a5ed] | 481 | StatementNode *first, *last; |
---|
[51b7345] | 482 | }; |
---|
| 483 | |
---|
[7f5566b] | 484 | class AsmStmtNode : public StatementNode { |
---|
| 485 | public: |
---|
| 486 | AsmStmtNode( Type, bool voltile, ConstantNode *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ConstantNode *clobber = 0, LabelNode *gotolabels = 0 ); |
---|
| 487 | ~AsmStmtNode(); |
---|
| 488 | |
---|
| 489 | void print( std::ostream &, int indent = 0 ) const; |
---|
| 490 | Statement *build() const; |
---|
| 491 | private: |
---|
| 492 | bool voltile; |
---|
| 493 | ConstantNode *instruction; |
---|
| 494 | ExpressionNode *output, *input; |
---|
| 495 | ConstantNode *clobber; |
---|
| 496 | std::list<std::string> gotolabels; |
---|
| 497 | }; |
---|
| 498 | |
---|
[51b7345] | 499 | class NullStmtNode : public CompoundStmtNode { |
---|
[bdd516a] | 500 | public: |
---|
[b87a5ed] | 501 | Statement *build() const; |
---|
[7f5566b] | 502 | void print( std::ostream &, int indent = 0 ) const; |
---|
[51b7345] | 503 | }; |
---|
| 504 | |
---|
| 505 | class InitializerNode : public ParseNode { |
---|
[bdd516a] | 506 | public: |
---|
[b87a5ed] | 507 | InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode *des = 0 ); |
---|
| 508 | InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 ); |
---|
| 509 | ~InitializerNode(); |
---|
[51b7345] | 510 | |
---|
[b87a5ed] | 511 | ExpressionNode *get_expression() const { return expr; } |
---|
[51b7345] | 512 | |
---|
[b87a5ed] | 513 | InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; } |
---|
| 514 | ExpressionNode *get_designators() const { return designator; } |
---|
[51b7345] | 515 | |
---|
[b87a5ed] | 516 | InitializerNode *next_init() const { return kids; } |
---|
[51b7345] | 517 | |
---|
[b87a5ed] | 518 | void print( std::ostream &, int indent = 0 ) const; |
---|
| 519 | void printOneLine( std::ostream & ) const; |
---|
[51b7345] | 520 | |
---|
[b87a5ed] | 521 | virtual Initializer *build() const; |
---|
[bdd516a] | 522 | private: |
---|
[b87a5ed] | 523 | ExpressionNode *expr; |
---|
| 524 | bool aggregate; |
---|
| 525 | ExpressionNode *designator; // may be list |
---|
| 526 | InitializerNode *kids; |
---|
[51b7345] | 527 | }; |
---|
| 528 | |
---|
| 529 | template< typename SynTreeType, typename NodeType > |
---|
[b87a5ed] | 530 | void buildList( const NodeType *firstNode, std::list< SynTreeType *> &outputList ) { |
---|
| 531 | SemanticError errors; |
---|
| 532 | std::back_insert_iterator< std::list< SynTreeType *> > out( outputList ); |
---|
| 533 | const NodeType *cur = firstNode; |
---|
| 534 | |
---|
| 535 | while ( cur ) { |
---|
| 536 | try { |
---|
| 537 | SynTreeType *result = dynamic_cast< SynTreeType *>( cur->build() ); |
---|
| 538 | if ( result ) { |
---|
| 539 | *out++ = result; |
---|
| 540 | } else { |
---|
| 541 | } // if |
---|
| 542 | } catch( SemanticError &e ) { |
---|
| 543 | errors.append( e ); |
---|
| 544 | } // try |
---|
| 545 | cur = dynamic_cast< NodeType *>( cur->get_link() ); |
---|
| 546 | } // while |
---|
[a32b204] | 547 | if ( ! errors.isEmpty() ) { |
---|
[b87a5ed] | 548 | throw errors; |
---|
| 549 | } // if |
---|
[51b7345] | 550 | } |
---|
| 551 | |
---|
| 552 | // in DeclarationNode.cc |
---|
[59db689] | 553 | void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ); |
---|
[bdd516a] | 554 | void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList ); |
---|
[59db689] | 555 | void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ); |
---|
[51b7345] | 556 | |
---|
| 557 | // in ExpressionNode.cc |
---|
| 558 | ExpressionNode *flattenCommas( ExpressionNode *list ); |
---|
| 559 | ExpressionNode *tupleContents( ExpressionNode *tuple ); |
---|
| 560 | |
---|
[bdd516a] | 561 | #endif // PARSENODE_H |
---|
[51b7345] | 562 | |
---|
| 563 | // Local Variables: // |
---|
[b87a5ed] | 564 | // tab-width: 4 // |
---|
| 565 | // mode: c++ // |
---|
| 566 | // compile-command: "make install" // |
---|
[51b7345] | 567 | // End: // |
---|