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