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