Changeset 2f22cc4 for src/Parser/ParseNode.h
- Timestamp:
- Aug 10, 2016, 2:02:10 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 321f55d, a563f01
- Parents:
- a6dd5b0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ParseNode.h
ra6dd5b0 r2f22cc4 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Aug 9 12:28:12201613 // Update Count : 38912 // Last Modified On : Wed Aug 10 13:08:46 2016 13 // Update Count : 436 14 14 // 15 15 … … 26 26 #include "SynTree/Type.h" 27 27 #include "SynTree/Expression.h" 28 #include "SynTree/Statement.h" 28 29 //#include "SynTree/Declaration.h" 29 30 #include "Common/UniqueName.h" … … 57 58 virtual void printList( std::ostream &os, int indent = 0 ) const; 58 59 59 ParseNode &operator,( ParseNode & );60 ParseNode &operator,( ParseNode & ); 60 61 protected: 61 62 std::string name; … … 134 135 //############################################################################## 135 136 136 // NullExprNode is used in tuples as a place-holder where a tuple component is omitted e.g., [ 2, , 3 ]137 // class NullExprNode : public ExpressionNode {138 // public:139 // NullExprNode() {}140 141 // virtual NullExprNode *clone() const { assert( false ); }142 143 // virtual void print( std::ostream &os, int indent = 0) const {}144 // virtual void printOneLine( std::ostream &os, int indent = 0) const {}145 146 // virtual Expression *build() const { assert( false ); return 0; }147 // };148 149 //##############################################################################150 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() {}156 157 // virtual ConstantNode *clone() const { assert( false ); return new ConstantNode( *this ); }158 159 // ConstantExpr *get_expr() const { return expr; }160 161 // virtual void print( std::ostream &os, int indent = 0 ) const {}162 // virtual void printOneLine( std::ostream &os, int indent = 0 ) const {}163 164 // Expression *build() const { return expr; }165 // private:166 // ConstantExpr *expr;167 // };168 169 137 Expression *build_constantInteger( std::string &str ); 170 138 Expression *build_constantFloat( std::string &str ); … … 174 142 //############################################################################## 175 143 176 // class VarRefNode : public ExpressionNode {177 // public:178 // VarRefNode( const std::string *, bool isLabel = false );179 // VarRefNode( const VarRefNode &other );180 181 // virtual Expression *build() const ;182 183 // virtual VarRefNode *clone() const { return new VarRefNode( *this ); }184 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 144 NameExpr *build_varref( const std::string *name, bool labelp = false ); 192 145 193 146 //############################################################################## 194 147 195 // class DesignatorNode : public ExpressionNode {196 // public:197 // DesignatorNode( ExpressionNode *expr, bool isArrayIndex = false );198 // DesignatorNode( const DesignatorNode &other );199 200 // virtual Expression *build() const ;201 // virtual DesignatorNode *clone() const { return new DesignatorNode( *this ); }202 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 // };208 209 //##############################################################################210 211 // class TypeValueNode : public ExpressionNode {212 // public:213 // TypeValueNode( DeclarationNode * );214 // TypeValueNode( const TypeValueNode &other );215 216 // DeclarationNode *get_decl() const { return decl; }217 218 // virtual Expression *build() const ;219 220 // virtual TypeValueNode *clone() const { return new TypeValueNode( *this ); }221 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 148 Expression *build_typevalue( DeclarationNode *decl ); 229 149 230 150 //############################################################################## 231 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() {}237 238 // CompositeExprNode *clone() const { assert( false ); return new CompositeExprNode( *this ); }239 240 // Expression *build() const { return expr; }241 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 // };247 151 248 152 enum class OperKinds { … … 282 186 //############################################################################## 283 187 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; }289 290 // virtual AsmExprNode *clone() const { return new AsmExprNode( *this ); }291 // virtual Expression *build() const;292 293 // virtual void print( std::ostream &os, int indent = 0) const;294 // virtual void printOneLine( std::ostream &os, int indent = 0) const;295 296 // ExpressionNode *get_inout() const { return inout; };297 // void set_inout( ExpressionNode *newValue ) { inout = newValue; }298 299 // ConstantNode *get_constraint() const { return constraint; };300 // void set_constraint( ConstantNode *newValue ) { constraint = newValue; }301 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 188 Expression *build_asm( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ); 311 189 … … 328 206 //############################################################################## 329 207 330 class ForCtlExprNode : public ExpressionNode {331 public:332 ForCtlExprNode( ParseNode *, ExpressionNode *, ExpressionNode * ) throw ( SemanticError );333 ForCtlExprNode( const ForCtlExprNode &other );334 ~ForCtlExprNode();335 336 StatementNode *get_init() const { return init; }337 ExpressionNode *get_condition() const { return condition; }338 ExpressionNode *get_change() const { return change; }339 340 virtual ForCtlExprNode *clone() const { return new ForCtlExprNode( *this ); }341 virtual Expression *build() const;342 343 virtual void print( std::ostream &os, int indent = 0 ) const;344 virtual void printOneLine( std::ostream &os, int indent = 0 ) const;345 private:346 StatementNode *init;347 ExpressionNode *condition;348 ExpressionNode *change;349 };350 351 //##############################################################################352 353 // class ValofExprNode : public ExpressionNode {354 // public:355 // ValofExprNode();356 // ValofExprNode( StatementNode *s = 0 );357 // ValofExprNode( const ValofExprNode &other );358 // ~ValofExprNode();359 360 // virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); }361 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;366 367 // private:368 // StatementNode *body;369 // };370 371 208 Expression *build_valexpr( StatementNode *s ); 372 209 373 210 //############################################################################## 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 211 398 212 Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ); … … 531 345 static StatementNode *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false ); 532 346 533 StatementNode *set_block( StatementNode *b ) { 347 StatementNode *set_block( StatementNode *b ) { block = b; return this; } 534 348 StatementNode *get_block() const { return block; } 535 349 … … 539 353 StatementNode::Type get_type() const { return type; } 540 354 541 StatementNode *add_label( const std::string * );542 const std::list<std::string> &get_labels() const { return labels; }355 virtual StatementNode *add_label( const std::string * ); 356 virtual std::list<std::string> get_labels() const { return labels; } 543 357 544 358 void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; } … … 565 379 }; // StatementNode 566 380 381 class StatementNode2 : public StatementNode { 382 public: 383 StatementNode2() {} 384 StatementNode2( Statement *stmt ) : stmt( stmt ) {} 385 virtual ~StatementNode2() {} 386 387 virtual StatementNode2 *clone() const { assert( false ); return nullptr; } 388 virtual Statement *build() const { return stmt; } 389 390 virtual StatementNode2 *add_label( const std::string * name ) { 391 stmt->get_labels().emplace_back( *name ); 392 return this; 393 } 394 virtual std::list<std::string> get_labels() const { assert( false ); return StatementNode::get_labels(); } 395 396 virtual void print( std::ostream &os, int indent = 0 ) {} 397 virtual void printList( std::ostream &os, int indent = 0 ) {} 398 private: 399 Statement *stmt; 400 }; // StatementNode 401 402 struct ForCtl { 403 ForCtl( ExpressionNode *expr, ExpressionNode *condition, ExpressionNode *change ) : 404 init( new StatementNode( StatementNode::Exp, expr ) ), condition( condition ), change( change ) {} 405 ForCtl( DeclarationNode *decl, ExpressionNode *condition, ExpressionNode *change ) : 406 init( new StatementNode( decl ) ), condition( condition ), change( change ) {} 407 408 StatementNode *init; 409 ExpressionNode *condition; 410 ExpressionNode *change; 411 }; 412 413 Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt ); 414 Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ); 415 Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind = false ); 416 Statement *build_for( ForCtl *forctl, StatementNode *stmt ); 417 567 418 //############################################################################## 568 419 … … 602 453 603 454 template< typename SynTreeType, typename NodeType > 604 void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) {455 void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) { 605 456 SemanticError errors; 606 457 std::back_insert_iterator< std::list< SynTreeType *> > out( outputList );
Note: See TracChangeset
for help on using the changeset viewer.