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