Ignore:
Timestamp:
Aug 10, 2016, 2:24:34 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
3078643, e109716
Parents:
9c98156 (diff), 2f22cc4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ParseNode.h

    r9c98156 ra563f01  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug  9 12:28:12 2016
    13 // Update Count     : 389
     12// Last Modified On : Wed Aug 10 13:08:46 2016
     13// Update Count     : 436
    1414//
    1515
     
    2626#include "SynTree/Type.h"
    2727#include "SynTree/Expression.h"
     28#include "SynTree/Statement.h"
    2829//#include "SynTree/Declaration.h"
    2930#include "Common/UniqueName.h"
     
    5758        virtual void printList( std::ostream &os, int indent = 0 ) const;
    5859
    59         ParseNode &operator,( ParseNode &);
     60        ParseNode &operator,( ParseNode & );
    6061  protected:
    6162        std::string name;
     
    134135//##############################################################################
    135136
    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 
    169137Expression *build_constantInteger( std::string &str );
    170138Expression *build_constantFloat( std::string &str );
     
    174142//##############################################################################
    175143
    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 
    191144NameExpr *build_varref( const std::string *name, bool labelp = false );
    192145
    193146//##############################################################################
    194147
    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 
    228148Expression *build_typevalue( DeclarationNode *decl );
    229149
    230150//##############################################################################
    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 // };
    247151
    248152enum class OperKinds {
     
    282186//##############################################################################
    283187
    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 
    310188Expression *build_asm( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand );
    311189
     
    328206//##############################################################################
    329207
    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 
    371208Expression *build_valexpr( StatementNode *s );
    372209
    373210//##############################################################################
    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 // };
    397211
    398212Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids );
     
    531345        static StatementNode *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false );
    532346
    533         StatementNode *set_block( StatementNode *b ) {  block = b; return this; }
     347        StatementNode *set_block( StatementNode *b ) { block = b; return this; }
    534348        StatementNode *get_block() const { return block; }
    535349
     
    539353        StatementNode::Type get_type() const { return type; }
    540354
    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; }
    543357
    544358        void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; }
     
    565379}; // StatementNode
    566380
     381class 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
     402struct 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
     413Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt );
     414Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt );
     415Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind = false );
     416Statement *build_for( ForCtl *forctl, StatementNode *stmt );
     417
    567418//##############################################################################
    568419
     
    602453
    603454template< typename SynTreeType, typename NodeType >
    604 void buildList( const NodeType *firstNode, std::list< SynTreeType *> &outputList ) {
     455void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) {
    605456        SemanticError errors;
    606457        std::back_insert_iterator< std::list< SynTreeType *> > out( outputList );
Note: See TracChangeset for help on using the changeset viewer.