Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r2f22cc4 rd1625f8  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 10 11:07:38 2016
    13 // Update Count     : 486
     12// Last Modified On : Tue Aug  9 12:28:40 2016
     13// Update Count     : 482
    1414//
    1515
     
    168168//##############################################################################
    169169
     170//Expression *build_varref( ExpressionNode expr ) {
     171//      return new NameExpr( get_name(), maybeBuild<Expression>( get_argName() ) );
     172//}
     173
     174// VarRefNode::VarRefNode( const string *name, bool labelp ) : ExpressionNode( nullptr, name ), isLabel( labelp ) {}
     175
     176// VarRefNode::VarRefNode( const VarRefNode &other ) : ExpressionNode( other ), isLabel( other.isLabel ) {}
     177
     178// Expression *VarRefNode::build() const {
     179//      return new NameExpr( get_name(), maybeBuild< Expression >( get_argName() ) );
     180// }
     181
     182// void VarRefNode::printOneLine( std::ostream &os, int indent ) const {
     183//      printDesignation( os );
     184//      os << get_name() << ' ';
     185// }
     186
     187// void VarRefNode::print( std::ostream &os, int indent ) const {
     188//      printDesignation( os );
     189//      os << string( indent, ' ' ) << "Referencing: ";
     190//      os << "Variable: " << get_name();
     191//      os << endl;
     192// }
     193
    170194NameExpr * build_varref( const string *name, bool labelp ) {
    171195        return new NameExpr( *name, nullptr );
    172196}
     197
     198//##############################################################################
     199
     200// DesignatorNode::DesignatorNode( ExpressionNode *expr, bool isArrayIndex, bool isVarRef ) : isArrayIndex( isArrayIndex ) {
     201//      set_argName( expr );
     202// }
     203
     204// DesignatorNode::DesignatorNode( const DesignatorNode &other ) : ExpressionNode( other ), isArrayIndex( other.isArrayIndex ) {}
     205
     206// class DesignatorFixer : public Mutator {
     207//   public:
     208//      virtual Expression* mutate( NameExpr *nameExpr ) {
     209//              if ( nameExpr->get_name() == "0" || nameExpr->get_name() == "1" ) {
     210//                      Constant val( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nameExpr->get_name() );
     211//                      delete nameExpr;
     212//                      return new ConstantExpr( val );
     213//              }
     214//              return nameExpr;
     215//      }
     216// };
     217
     218// Expression *DesignatorNode::build() const {
     219//      return maybeBuild<Expression>(get_argName());
     220// }
     221
     222// void DesignatorNode::printOneLine( std::ostream &os, int indent ) const {
     223//      if ( get_argName() ) {
     224//              if ( isArrayIndex ) {
     225//                      os << "[";
     226//                      get_argName()->printOneLine( os, indent );
     227//                      os << "]";
     228//              } else {
     229//                      os << ".";
     230//                      get_argName()->printOneLine( os, indent );
     231//              }
     232//      } // if
     233// }
     234
     235// void DesignatorNode::print( std::ostream &os, int indent ) const {
     236//      if ( get_argName() ) {
     237//              if ( isArrayIndex ) {
     238//                      os << "[";
     239//                      get_argName()->print( os, indent );
     240//                      os << "]";
     241//              } else {
     242//                      os << ".";
     243//                      get_argName()->print( os, indent );
     244//              }
     245//      } // if
     246// }
    173247
    174248//##############################################################################
     
    292366//##############################################################################
    293367
     368// Expression *AsmExprNode::build() const {
     369//      return new AsmExpr( maybeBuild< Expression >( inout ), (ConstantExpr *)maybeBuild<Expression>(constraint), maybeBuild<Expression>(operand) );
     370// }
     371
     372// void AsmExprNode::print( std::ostream &os, int indent ) const {
     373//      os << string( indent, ' ' ) << "Assembler Expression:" << endl;
     374//      if ( inout ) {
     375//              os << string( indent, ' ' ) << "inout: " << std::endl;
     376//              inout->print( os, indent + 2 );
     377//      } // if
     378//      if ( constraint ) {
     379//              os << string( indent, ' ' ) << "constraint: " << std::endl;
     380//              constraint->print( os, indent + 2 );
     381//      } // if
     382//      if ( operand ) {
     383//              os << string( indent, ' ' ) << "operand: " << std::endl;
     384//              operand->print( os, indent + 2 );
     385//      } // if
     386// }
     387
     388// void AsmExprNode::printOneLine( std::ostream &os, int indent ) const {
     389//      printDesignation( os );
     390//      os << "( ";
     391//      if ( inout ) inout->printOneLine( os, indent + 2 );
     392//      os << ", ";
     393//      if ( constraint ) constraint->printOneLine( os, indent + 2 );
     394//      os << ", ";
     395//      if ( operand ) operand->printOneLine( os, indent + 2 );
     396//      os << ") ";
     397// }
     398
    294399Expression *build_asm( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ) {
    295400        return new AsmExpr( maybeBuild< Expression >( inout ), constraint, maybeBuild<Expression>(operand) );
     
    304409//##############################################################################
    305410
     411// ValofExprNode::ValofExprNode( StatementNode *s ): body( s ) {}
     412
     413// ValofExprNode::ValofExprNode( const ValofExprNode &other ) : ExpressionNode( other ), body( maybeClone( body ) ) {
     414// }
     415
     416// ValofExprNode::~ValofExprNode() {
     417//      delete body;
     418// }
     419
     420// void ValofExprNode::print( std::ostream &os, int indent ) const {
     421//      os << string( indent, ' ' ) << "Valof Expression:" << std::endl;
     422//      get_body()->print( os, indent + 4);
     423// }
     424
     425// void ValofExprNode::printOneLine( std::ostream &, int indent ) const {
     426//      assert( false );
     427// }
     428
     429// Expression *ValofExprNode::build() const {
     430//      return new UntypedValofExpr( maybeBuild<Statement>(get_body()), nullptr );
     431// }
     432
    306433Expression *build_valexpr( StatementNode *s ) {
    307434        return new UntypedValofExpr( maybeBuild<Statement>(s), nullptr );
     
    309436
    310437//##############################################################################
    311  
    312 // ForCtlExprNode::ForCtlExprNode( ParseNode *init_, ExpressionNode *cond, ExpressionNode *incr ) throw ( SemanticError ) : condition( cond ), change( incr ) {
    313 //      if ( init_ == 0 )
    314 //              init = 0;
    315 //      else {
    316 //              DeclarationNode *decl;
    317 //              ExpressionNode *exp;
    318 
    319 //              if (( decl = dynamic_cast<DeclarationNode *>(init_) ) != 0)
    320 //                      init = new StatementNode( decl );
    321 //              else if (( exp = dynamic_cast<ExpressionNode *>( init_)) != 0)
    322 //                      init = new StatementNode( StatementNode::Exp, exp );
    323 //              else
    324 //                      throw SemanticError("Error in for control expression");
    325 //      }
    326 // }
    327 
    328 // ForCtlExprNode::ForCtlExprNode( const ForCtlExprNode &other )
    329 //      : ExpressionNode( other ), init( maybeClone( other.init ) ), condition( maybeClone( other.condition ) ), change( maybeClone( other.change ) ) {
    330 // }
    331 
    332 // ForCtlExprNode::~ForCtlExprNode() {
    333 //      delete init;
    334 //      delete condition;
    335 //      delete change;
    336 // }
    337 
    338 // Expression *ForCtlExprNode::build() const {
    339 //      // this shouldn't be used!
    340 //      assert( false );
    341 //      return 0;
    342 // }
    343 
    344 // void ForCtlExprNode::print( std::ostream &os, int indent ) const{
    345 //      os << string( indent,' ' ) << "For Control Expression -- :" << endl;
    346 
    347 //      os << string( indent + 2, ' ' ) << "initialization:" << endl;
    348 //      if ( init != 0 )
    349 //              init->printList( os, indent + 4 );
    350 
    351 //      os << string( indent + 2, ' ' ) << "condition: " << endl;
    352 //      if ( condition != 0 )
    353 //              condition->print( os, indent + 4 );
    354 //      os << string( indent + 2, ' ' ) << "increment: " << endl;
    355 //      if ( change != 0 )
    356 //              change->print( os, indent + 4 );
    357 // }
    358 
    359 // void ForCtlExprNode::printOneLine( std::ostream &, int indent ) const {
    360 //      assert( false );
    361 // }
    362 
    363 //##############################################################################
     438
     439ForCtlExprNode::ForCtlExprNode( ParseNode *init_, ExpressionNode *cond, ExpressionNode *incr ) throw ( SemanticError ) : condition( cond ), change( incr ) {
     440        if ( init_ == 0 )
     441                init = 0;
     442        else {
     443                DeclarationNode *decl;
     444                ExpressionNode *exp;
     445
     446                if (( decl = dynamic_cast<DeclarationNode *>(init_) ) != 0)
     447                        init = new StatementNode( decl );
     448                else if (( exp = dynamic_cast<ExpressionNode *>( init_)) != 0)
     449                        init = new StatementNode( StatementNode::Exp, exp );
     450                else
     451                        throw SemanticError("Error in for control expression");
     452        }
     453}
     454
     455ForCtlExprNode::ForCtlExprNode( const ForCtlExprNode &other )
     456        : ExpressionNode( other ), init( maybeClone( other.init ) ), condition( maybeClone( other.condition ) ), change( maybeClone( other.change ) ) {
     457}
     458
     459ForCtlExprNode::~ForCtlExprNode() {
     460        delete init;
     461        delete condition;
     462        delete change;
     463}
     464
     465Expression *ForCtlExprNode::build() const {
     466        // this shouldn't be used!
     467        assert( false );
     468        return 0;
     469}
     470
     471void ForCtlExprNode::print( std::ostream &os, int indent ) const{
     472        os << string( indent,' ' ) << "For Control Expression -- :" << endl;
     473
     474        os << string( indent + 2, ' ' ) << "initialization:" << endl;
     475        if ( init != 0 )
     476                init->printList( os, indent + 4 );
     477
     478        os << string( indent + 2, ' ' ) << "condition: " << endl;
     479        if ( condition != 0 )
     480                condition->print( os, indent + 4 );
     481        os << string( indent + 2, ' ' ) << "increment: " << endl;
     482        if ( change != 0 )
     483                change->print( os, indent + 4 );
     484}
     485
     486void ForCtlExprNode::printOneLine( std::ostream &, int indent ) const {
     487        assert( false );
     488}
     489
     490//##############################################################################
     491
     492// TypeValueNode::TypeValueNode( DeclarationNode *decl ) : decl( decl ) {
     493// }
     494
     495// TypeValueNode::TypeValueNode( const TypeValueNode &other ) : ExpressionNode( other ), decl( maybeClone( other.decl ) ) {
     496// }
     497
     498// Expression *TypeValueNode::build() const {
     499//      return new TypeExpr( decl->buildType() );
     500// }
     501
     502// void TypeValueNode::print( std::ostream &os, int indent ) const {
     503//      os << std::string( indent, ' ' ) << "Type:";
     504//      get_decl()->print( os, indent + 2);
     505// }
     506
     507// void TypeValueNode::printOneLine( std::ostream &os, int indent ) const {
     508//      os << "Type:";
     509//      get_decl()->print( os, indent + 2);
     510// }
    364511
    365512Expression *build_typevalue( DeclarationNode *decl ) {
     
    368515
    369516//##############################################################################
     517
     518// CompoundLiteralNode::CompoundLiteralNode( DeclarationNode *type, InitializerNode *kids ) : type( type ), kids( kids ) {}
     519// CompoundLiteralNode::CompoundLiteralNode( const CompoundLiteralNode &other ) : ExpressionNode( other ), type( other.type ), kids( other.kids ) {}
     520
     521// CompoundLiteralNode::~CompoundLiteralNode() {
     522//      delete kids;
     523//      delete type;
     524// }
     525
     526// CompoundLiteralNode *CompoundLiteralNode::clone() const {
     527//      return new CompoundLiteralNode( *this );
     528// }
     529
     530// void CompoundLiteralNode::print( std::ostream &os, int indent ) const {
     531//      os << string( indent,' ' ) << "CompoundLiteralNode:" << endl;
     532
     533//      os << string( indent + 2, ' ' ) << "type:" << endl;
     534//      if ( type != 0 )
     535//              type->print( os, indent + 4 );
     536
     537//      os << string( indent + 2, ' ' ) << "initialization:" << endl;
     538//      if ( kids != 0 )
     539//              kids->printList( os, indent + 4 );
     540// }
     541
     542// void CompoundLiteralNode::printOneLine( std::ostream &os, int indent ) const {
     543//      os << "( ";
     544//      if ( type ) type->print( os );
     545//      os << ", ";
     546//      if ( kids ) kids->printOneLine( os );
     547//      os << ") ";
     548// }
     549
     550// Expression *CompoundLiteralNode::build() const {
     551//      Declaration * newDecl = maybeBuild<Declaration>(type); // compound literal type
     552//      if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type
     553//              return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeBuild<Initializer>(kids) );
     554//      // these types do not have associated type information
     555//      } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl )  ) {
     556//              return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeBuild<Initializer>(kids) );
     557//      } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl )  ) {
     558//              return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeBuild<Initializer>(kids) );
     559//      } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl )  ) {
     560//              return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeBuild<Initializer>(kids) );
     561//      } else {
     562//              assert( false );
     563//      } // if
     564// }
    370565
    371566Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ) {
Note: See TracChangeset for help on using the changeset viewer.