Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ParseNode.h

    r2f22cc4 rd1625f8  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 10 13:08:46 2016
    13 // Update Count     : 436
     12// Last Modified On : Tue Aug  9 12:28:12 2016
     13// Update Count     : 389
    1414//
    1515
     
    2626#include "SynTree/Type.h"
    2727#include "SynTree/Expression.h"
    28 #include "SynTree/Statement.h"
    2928//#include "SynTree/Declaration.h"
    3029#include "Common/UniqueName.h"
     
    5857        virtual void printList( std::ostream &os, int indent = 0 ) const;
    5958
    60         ParseNode &operator,( ParseNode & );
     59        ParseNode &operator,( ParseNode &);
    6160  protected:
    6261        std::string name;
     
    135134//##############################################################################
    136135
     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
    137169Expression *build_constantInteger( std::string &str );
    138170Expression *build_constantFloat( std::string &str );
     
    142174//##############################################################################
    143175
     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
    144191NameExpr *build_varref( const std::string *name, bool labelp = false );
    145192
    146193//##############################################################################
    147194
     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
    148228Expression *build_typevalue( DeclarationNode *decl );
    149229
    150230//##############################################################################
     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// };
    151247
    152248enum class OperKinds {
     
    186282//##############################################################################
    187283
     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
    188310Expression *build_asm( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand );
    189311
     
    206328//##############################################################################
    207329
     330class 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
    208371Expression *build_valexpr( StatementNode *s );
    209372
    210373//##############################################################################
     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// };
    211397
    212398Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids );
     
    345531        static StatementNode *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false );
    346532
    347         StatementNode *set_block( StatementNode *b ) { block = b; return this; }
     533        StatementNode *set_block( StatementNode *b ) {  block = b; return this; }
    348534        StatementNode *get_block() const { return block; }
    349535
     
    353539        StatementNode::Type get_type() const { return type; }
    354540
    355         virtual StatementNode *add_label( const std::string * );
    356         virtual std::list<std::string> get_labels() const { return labels; }
     541        StatementNode *add_label( const std::string * );
     542        const std::list<std::string> &get_labels() const { return labels; }
    357543
    358544        void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; }
     
    379565}; // StatementNode
    380566
    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 
    418567//##############################################################################
    419568
     
    453602
    454603template< typename SynTreeType, typename NodeType >
    455 void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) {
     604void buildList( const NodeType *firstNode, std::list< SynTreeType *> &outputList ) {
    456605        SemanticError errors;
    457606        std::back_insert_iterator< std::list< SynTreeType *> > out( outputList );
Note: See TracChangeset for help on using the changeset viewer.