Changeset f80e0218 for src/Parser/ExpressionNode.cc
- Timestamp:
- Jun 30, 2016, 4:32:56 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, 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:
- ea29e73
- Parents:
- 1b5c81ed (diff), 84d4d6f (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
r1b5c81ed rf80e0218 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // ExpressionNode.cc -- 8 // 7 // ExpressionNode.cc -- 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 8 15:43:05201613 // Update Count : 29614 // 12 // Last Modified On : Mon Jun 13 14:46:17 2016 13 // Update Count : 307 14 // 15 15 16 16 #include <cassert> … … 32 32 using namespace std; 33 33 34 ExpressionNode::ExpressionNode() : ParseNode() , argName( 0 ){}35 36 ExpressionNode::ExpressionNode( const string *name ) : ParseNode( name ) , argName( 0 ){}37 38 ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other.name ) {34 ExpressionNode::ExpressionNode() : ParseNode() {} 35 36 ExpressionNode::ExpressionNode( const string *name ) : ParseNode( name ) {} 37 38 ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other.name ), extension( other.extension ) { 39 39 if ( other.argName ) { 40 40 argName = other.argName->clone(); … … 231 231 // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string. 232 232 value.insert( value.length() - 1, newValue->substr( 1, newValue->length() - 2 ) ); 233 233 234 234 delete newValue; // allocated by lexer 235 235 return this; … … 344 344 345 345 Expression *DesignatorNode::build() const { 346 Expression * ret = get_argName()->build();346 Expression * ret = maybeBuild<Expression>(get_argName()); 347 347 348 348 if ( isArrayIndex ) { 349 // need to traverse entire structure and change any instances of 0 or 1 to 349 // need to traverse entire structure and change any instances of 0 or 1 to 350 350 // ConstantExpr 351 351 DesignatorFixer fixer; … … 389 389 "Cond", "NCond", 390 390 // diadic 391 "SizeOf", "AlignOf", "OffsetOf", "Attr", " CompLit", "?+?", "?-?", "?*?", "?/?", "?%?", "||", "&&",391 "SizeOf", "AlignOf", "OffsetOf", "Attr", "?+?", "?-?", "?*?", "?/?", "?%?", "||", "&&", 392 392 "?|?", "?&?", "?^?", "Cast", "?<<?", "?>>?", "?<?", "?>?", "?<=?", "?>=?", "?==?", "?!=?", 393 393 "?=?", "?*=?", "?/=?", "?%=?", "?+=?", "?-=?", "?<<=?", "?>>=?", "?&=?", "?^=?", "?|=?", … … 440 440 } 441 441 442 CompositeExprNode::CompositeExprNode( const CompositeExprNode &other ) : ExpressionNode( other ), function( maybeClone( other.function ) ) {442 CompositeExprNode::CompositeExprNode( const CompositeExprNode &other ) : ExpressionNode( other ), function( maybeClone( other.function ) ), arguments( 0 ) { 443 443 ParseNode *cur = other.arguments; 444 444 while ( cur ) { … … 466 466 467 467 if ( ! ( op = dynamic_cast<OperatorNode *>( function ) ) ) { // function as opposed to operator 468 return new UntypedExpr( function->build(), args, maybeBuild< Expression >( get_argName() ));468 return new UntypedExpr( maybeBuild<Expression>(function), args, maybeBuild< Expression >( get_argName() )); 469 469 } // if 470 470 … … 550 550 if ( dynamic_cast< VoidType* >( targetType ) ) { 551 551 delete targetType; 552 return new CastExpr( expr_node->build(), maybeBuild< Expression >( get_argName() ) );552 return new CastExpr( maybeBuild<Expression>(expr_node), maybeBuild< Expression >( get_argName() ) ); 553 553 } else { 554 return new CastExpr( expr_node->build(),targetType, maybeBuild< Expression >( get_argName() ) );554 return new CastExpr( maybeBuild<Expression>(expr_node),targetType, maybeBuild< Expression >( get_argName() ) ); 555 555 } // if 556 556 } … … 608 608 { 609 609 assert( args.size() == 2 ); 610 610 611 611 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args() ) ) { 612 612 NameExpr *member = dynamic_cast<NameExpr *>( args.back() ); … … 621 621 assert( var ); 622 622 if ( ! get_args()->get_link() ) { 623 return new AttrExpr( var->build(), ( Expression*)0);623 return new AttrExpr( maybeBuild<Expression>(var), ( Expression*)0); 624 624 } else if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()->get_link()) ) { 625 return new AttrExpr( var->build(), arg->get_decl()->buildType());625 return new AttrExpr( maybeBuild<Expression>(var), arg->get_decl()->buildType()); 626 626 } else { 627 return new AttrExpr( var->build(), args.back()); 628 } // if 629 } 630 case OperatorNode::CompLit: 631 throw UnimplementedError( "C99 compound literals" ); 632 // the short-circuited operators 627 return new AttrExpr( maybeBuild<Expression>(var), args.back()); 628 } // if 629 } 633 630 case OperatorNode::Or: 634 631 case OperatorNode::And: … … 719 716 720 717 Expression *AsmExprNode::build() const { 721 return new AsmExpr( maybeBuild< Expression >( inout ), (ConstantExpr *) constraint->build(), operand->build() );718 return new AsmExpr( maybeBuild< Expression >( inout ), (ConstantExpr *)maybeBuild<Expression>(constraint), maybeBuild<Expression>(operand) ); 722 719 } 723 720 … … 796 793 797 794 Expression *ValofExprNode::build() const { 798 return new UntypedValofExpr ( get_body()->build(), maybeBuild< Expression >( get_argName() ) );795 return new UntypedValofExpr ( maybeBuild<Statement>(get_body()), maybeBuild< Expression >( get_argName() ) ); 799 796 } 800 797 … … 908 905 909 906 Expression *CompoundLiteralNode::build() const { 910 Declaration * newDecl = type->build();// compound literal type907 Declaration * newDecl = maybeBuild<Declaration>(type); // compound literal type 911 908 if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type 912 return new CompoundLiteralExpr( newDeclWithType->get_type(), kids->build() );909 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeBuild<Initializer>(kids) ); 913 910 // these types do not have associated type information 914 911 } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl ) ) { 915 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), kids->build() );912 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeBuild<Initializer>(kids) ); 916 913 } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl ) ) { 917 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), kids->build() );914 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeBuild<Initializer>(kids) ); 918 915 } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl ) ) { 919 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), kids->build() );916 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeBuild<Initializer>(kids) ); 920 917 } else { 921 918 assert( false );
Note:
See TracChangeset
for help on using the changeset viewer.