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