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