Changeset bdd516a for translator/Parser
- Timestamp:
- Apr 28, 2015, 4:21:36 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, string, with_gc
- Children:
- 42e2ad7
- Parents:
- ad17ba6a
- Location:
- translator/Parser
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/Parser/DeclarationNode.cc
rad17ba6a rbdd516a 5 5 #include <cassert> 6 6 7 #include "ParseNode.h"8 7 #include "TypeData.h" 9 #include "utility.h"10 #include "SynTree/Declaration.h"11 8 #include "SynTree/Expression.h" 12 #include "SynTree/Initializer.h" 13 #include "SemanticError.h" 14 #include "UniqueName.h" 15 #include "LinkageSpec.h" 9 16 10 17 11 using namespace std; 18 12 19 / * these must remain in the same order as the corresponding DeclarationNode enumerations */20 const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue" };13 // These must remain in the same order as the corresponding DeclarationNode enumerations. 14 const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" }; 21 15 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary" }; 22 16 const char *DeclarationNode::modifierName[] = { "signed", "unsigned", "short", "long" }; … … 67 61 os << string(indent, ' ' ); 68 62 if ( name == "" ) { 69 /// os << "An unnamed";63 os << "unnamed: "; 70 64 } else { 71 os << name << ": a";65 os << name << ": "; 72 66 } 73 67 … … 862 856 ret = new StructInstType( type->buildQualifiers(), type->aggregate->name ); 863 857 break; 864 865 858 case DeclarationNode::Union: 866 859 ret = new UnionInstType( type->buildQualifiers(), type->aggregate->name ); 867 860 break; 868 869 861 case DeclarationNode::Context: 870 862 ret = new ContextInstType( type->buildQualifiers(), type->aggregate->name ); 871 863 break; 872 873 864 default: 874 865 assert( false ); 875 } 866 } // switch 876 867 buildList( type->aggregate->actuals, ret->get_parameters() ); 877 868 return ret; … … 884 875 default: 885 876 return type->build(); 886 } 877 } // switch 887 878 } 888 879 -
translator/Parser/ExpressionNode.cc
rad17ba6a rbdd516a 16 16 ExpressionNode::ExpressionNode() : ParseNode(), argName( 0 ) {} 17 17 18 ExpressionNode::ExpressionNode( string *name_) : ParseNode( *name_ ), argName( 0 ) {18 ExpressionNode::ExpressionNode( string *name_) : ParseNode( *name_ ), argName( 0 ) { 19 19 delete name_; 20 20 } … … 25 25 } else { 26 26 argName = 0; 27 } 27 } // if 28 28 } 29 29 30 30 ExpressionNode * ExpressionNode::set_asArgName( std::string *aName ) { 31 argName = new VarRefNode( aName);31 argName = new VarRefNode( aName ); 32 32 return this; 33 33 } … … 40 40 void ExpressionNode::printDesignation( std::ostream &os, int indent ) const { 41 41 if ( argName ) { 42 os << string(' ', indent ) << "(designated by: ";43 argName->printOneLine( os, indent );42 os << string(' ', indent ) << "(designated by: "; 43 argName->printOneLine( os, indent ); 44 44 os << ")" << std::endl; 45 } 45 } // if 46 46 } 47 47 … … 52 52 } 53 53 54 void NullExprNode::print( std::ostream & os, int indent) const {55 printDesignation( os);54 void NullExprNode::print( std::ostream & os, int indent ) const { 55 printDesignation( os ); 56 56 os << "null expression"; 57 57 } 58 58 59 void NullExprNode::printOneLine( std::ostream & os, int indent) const {60 printDesignation( os);59 void NullExprNode::printOneLine( std::ostream & os, int indent ) const { 60 printDesignation( os ); 61 61 os << "null"; 62 62 } … … 66 66 } 67 67 68 CommaExprNode *ExpressionNode::add_to_list( ExpressionNode *exp){69 return new CommaExprNode( this, exp );68 CommaExprNode *ExpressionNode::add_to_list( ExpressionNode *exp ){ 69 return new CommaExprNode( this, exp ); 70 70 } 71 71 72 72 // enum ConstantNode::Type = { Integer, Float, Character, String, Range } 73 73 74 ConstantNode::ConstantNode( void) : ExpressionNode(), sign(true), longs(0), size(0) {}75 76 ConstantNode::ConstantNode( string *name_) : ExpressionNode(name_), sign(true), longs(0), size(0) {}77 78 ConstantNode::ConstantNode( Type t, string *inVal) : type(t), sign(true), longs(0), size(0) {74 ConstantNode::ConstantNode( void ) : ExpressionNode(), sign( true ), longs(0), size(0) {} 75 76 ConstantNode::ConstantNode( string *name_) : ExpressionNode( name_), sign( true ), longs(0), size(0) {} 77 78 ConstantNode::ConstantNode( Type t, string *inVal ) : type( t ), sign( true ), longs(0), size(0) { 79 79 if ( inVal ) { 80 80 value = *inVal; … … 82 82 } else { 83 83 value = ""; 84 } 85 86 classify( value);84 } // if 85 86 classify( value ); 87 87 } 88 88 … … 96 96 } 97 97 98 void ConstantNode::classify( std::string &str){99 switch ( type){98 void ConstantNode::classify( std::string &str ){ 99 switch ( type ){ 100 100 case Integer: 101 101 case Float: … … 105 105 int i = str.length() - 1; 106 106 107 while ( i >= 0 && !isxdigit( c = str.at(i--)) )107 while ( i >= 0 && !isxdigit( c = str.at( i--)) ) 108 108 sfx += c; 109 109 … … 111 111 112 112 // get rid of underscores 113 value.erase( remove(value.begin(), value.end(), '_'), value.end());114 115 std::transform( sfx.begin(), sfx.end(), sfx.begin(), tolower_hack);113 value.erase( remove( value.begin(), value.end(), '_'), value.end()); 114 115 std::transform( sfx.begin(), sfx.end(), sfx.begin(), tolower_hack ); 116 116 117 117 if ( sfx.find("ll") != string::npos ){ 118 118 longs = 2; 119 } else if ( sfx.find("l") != string::npos ){119 } else if ( sfx.find("l") != string::npos ){ 120 120 longs = 1; 121 } 122 123 assert(( longs >= 0) && (longs <= 2));121 } // if 122 123 assert(( longs >= 0) && ( longs <= 2)); 124 124 125 125 if ( sfx.find("u") != string::npos ) … … 131 131 { 132 132 // remove underscores from hex and oct escapes 133 if ( str.substr(1,2) == "\\x")134 value.erase( remove(value.begin(), value.end(), '_'), value.end());133 if ( str.substr(1,2) == "\\x") 134 value.erase( remove( value.begin(), value.end(), '_'), value.end()); 135 135 136 136 break; … … 142 142 } 143 143 144 ConstantNode::Type ConstantNode::get_type( void) const {144 ConstantNode::Type ConstantNode::get_type( void ) const { 145 145 return type; 146 146 } … … 148 148 ConstantNode *ConstantNode::append( std::string *newValue ) { 149 149 if ( newValue ) { 150 if ( type == String){150 if ( type == String ){ 151 151 std::string temp = *newValue; 152 152 value.resize( value.size() - 1 ); … … 156 156 157 157 delete newValue; 158 } 158 } // if 159 159 return this; 160 160 } 161 161 162 void ConstantNode::printOneLine( std::ostream &os, int indent ) const {163 os << string( indent, ' ');164 printDesignation( os);162 void ConstantNode::printOneLine( std::ostream &os, int indent ) const { 163 os << string( indent, ' '); 164 printDesignation( os ); 165 165 166 166 switch ( type ) { … … 185 185 } 186 186 187 void ConstantNode::print( std::ostream &os, int indent ) const {187 void ConstantNode::print( std::ostream &os, int indent ) const { 188 188 printOneLine( os, indent ); 189 189 os << endl; … … 194 194 BasicType *bt; 195 195 196 switch ( get_type()){196 switch ( get_type()){ 197 197 case Integer: 198 198 /* Cfr. standard 6.4.4.1 */ 199 //bt.set_kind( BasicType::SignedInt);200 bt = new BasicType( q, BasicType::SignedInt);199 //bt.set_kind( BasicType::SignedInt ); 200 bt = new BasicType( q, BasicType::SignedInt ); 201 201 break; 202 202 case Float: 203 bt = new BasicType( q, BasicType::Float);203 bt = new BasicType( q, BasicType::Float ); 204 204 break; 205 205 case Character: 206 bt = new BasicType( q, BasicType::Char);206 bt = new BasicType( q, BasicType::Char ); 207 207 break; 208 208 case String: … … 210 210 ArrayType *at; 211 211 std::string value = get_value(); 212 at = new ArrayType( q, new BasicType(q, BasicType::Char),213 new ConstantExpr( Constant( new BasicType( q, BasicType::SignedInt),212 at = new ArrayType( q, new BasicType( q, BasicType::Char ), 213 new ConstantExpr( Constant( new BasicType( q, BasicType::SignedInt ), 214 214 toString( value.size() - 1 ) ) ), // account for '\0' 215 215 false, false ); 216 return new ConstantExpr( Constant( at, value), maybeBuild< Expression >( get_argName() ) );216 return new ConstantExpr( Constant( at, value ), maybeBuild< Expression >( get_argName() ) ); 217 217 } 218 return new ConstantExpr( Constant( bt, get_value()), maybeBuild< Expression >( get_argName() ) );219 } 220 221 VarRefNode::VarRefNode() : isLabel( false) {}222 223 VarRefNode::VarRefNode( string *name_, bool labelp) : ExpressionNode(name_), isLabel(labelp) {}218 return new ConstantExpr( Constant( bt, get_value()), maybeBuild< Expression >( get_argName() ) ); 219 } 220 221 VarRefNode::VarRefNode() : isLabel( false ) {} 222 223 VarRefNode::VarRefNode( string *name_, bool labelp ) : ExpressionNode( name_), isLabel( labelp ) {} 224 224 225 225 VarRefNode::VarRefNode( const VarRefNode &other ) : ExpressionNode( other ), isLabel( other.isLabel ) { … … 230 230 } 231 231 232 void VarRefNode::printOneLine( std::ostream &os, int indent ) const {233 printDesignation( os);232 void VarRefNode::printOneLine( std::ostream &os, int indent ) const { 233 printDesignation( os ); 234 234 os << get_name() << ' '; 235 235 } 236 236 237 void VarRefNode::print( std::ostream &os, int indent ) const {238 printDesignation( os);239 os << '\r' << string( indent, ' ') << "Referencing: ";237 void VarRefNode::print( std::ostream &os, int indent ) const { 238 printDesignation( os ); 239 os << '\r' << string( indent, ' ') << "Referencing: "; 240 240 os << "Variable: " << get_name(); 241 241 os << endl; 242 242 } 243 243 244 OperatorNode::OperatorNode( Type t) : type(t) {}244 OperatorNode::OperatorNode( Type t ) : type( t ) {} 245 245 246 246 OperatorNode::OperatorNode( const OperatorNode &other ) : ExpressionNode( other ), type( other.type ) { … … 249 249 OperatorNode::~OperatorNode() {} 250 250 251 OperatorNode::Type OperatorNode::get_type( void) const{251 OperatorNode::Type OperatorNode::get_type( void ) const{ 252 252 return type; 253 253 } 254 254 255 255 void OperatorNode::printOneLine( std::ostream &os, int indent ) const { 256 printDesignation( os);256 printDesignation( os ); 257 257 os << OpName[ type ] << ' '; 258 258 } 259 259 260 260 void OperatorNode::print( std::ostream &os, int indent ) const{ 261 printDesignation( os);262 os << '\r' << string( indent, ' ') << "Operator: " << OpName[type] << endl;261 printDesignation( os ); 262 os << '\r' << string( indent, ' ') << "Operator: " << OpName[type] << endl; 263 263 return; 264 264 } 265 265 266 std::string OperatorNode::get_typename( void) const{267 return string( OpName[ type ]);266 std::string OperatorNode::get_typename( void ) const{ 267 return string( OpName[ type ]); 268 268 } 269 269 … … 282 282 }; 283 283 284 CompositeExprNode::CompositeExprNode( void) : ExpressionNode(), function( 0 ), arguments( 0 ) {285 } 286 287 CompositeExprNode::CompositeExprNode( string *name_) : ExpressionNode(name_), function( 0 ), arguments( 0 ) {288 } 289 290 CompositeExprNode::CompositeExprNode( ExpressionNode *f, ExpressionNode *args):291 function( f), arguments(args) {292 } 293 294 CompositeExprNode::CompositeExprNode( ExpressionNode *f, ExpressionNode *arg1, ExpressionNode *arg2):295 function( f), arguments(arg1) {296 arguments->set_link( arg2);284 CompositeExprNode::CompositeExprNode( void ) : ExpressionNode(), function( 0 ), arguments( 0 ) { 285 } 286 287 CompositeExprNode::CompositeExprNode( string *name_) : ExpressionNode( name_), function( 0 ), arguments( 0 ) { 288 } 289 290 CompositeExprNode::CompositeExprNode( ExpressionNode *f, ExpressionNode *args ): 291 function( f ), arguments( args ) { 292 } 293 294 CompositeExprNode::CompositeExprNode( ExpressionNode *f, ExpressionNode *arg1, ExpressionNode *arg2): 295 function( f ), arguments( arg1) { 296 arguments->set_link( arg2); 297 297 } 298 298 … … 303 303 arguments->set_link( cur->clone() ); 304 304 } else { 305 arguments = ( ExpressionNode*)cur->clone();306 } 305 arguments = ( ExpressionNode*)cur->clone(); 306 } // if 307 307 cur = cur->get_link(); 308 308 } … … 333 333 std::list<Expression *> args; 334 334 335 buildList( get_args(), args);336 337 if ( ! ( op = dynamic_cast<OperatorNode *>( function)) ) {335 buildList( get_args(), args ); 336 337 if ( ! ( op = dynamic_cast<OperatorNode *>( function )) ) { 338 338 // a function as opposed to an operator 339 return new UntypedExpr( function->build(), args, maybeBuild< Expression >( get_argName() ));339 return new UntypedExpr( function->build(), args, maybeBuild< Expression >( get_argName() )); 340 340 } else { 341 switch ( op->get_type()){341 switch ( op->get_type()){ 342 342 case OperatorNode::Incr: 343 343 case OperatorNode::Decr: … … 412 412 case OperatorNode::Cast: 413 413 { 414 TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args());414 TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()); 415 415 assert( arg ); 416 416 417 417 DeclarationNode *decl_node = arg->get_decl(); 418 ExpressionNode *expr_node = dynamic_cast<ExpressionNode *>( arg->get_link());418 ExpressionNode *expr_node = dynamic_cast<ExpressionNode *>( arg->get_link()); 419 419 420 420 Type *targetType = decl_node->buildType(); … … 423 423 return new CastExpr( expr_node->build(), maybeBuild< Expression >( get_argName() ) ); 424 424 } else { 425 return new CastExpr( expr_node->build(),targetType, maybeBuild< Expression >( get_argName() ) );426 } 425 return new CastExpr( expr_node->build(),targetType, maybeBuild< Expression >( get_argName() ) ); 426 } // if 427 427 } 428 428 case OperatorNode::FieldSel: … … 430 430 assert( args.size() == 2 ); 431 431 432 NameExpr *member = dynamic_cast<NameExpr *>(args.back()); 433 // TupleExpr *memberTup = dynamic_cast<TupleExpr *>(args.back()); 434 435 if ( member != 0 ) 436 { 437 UntypedMemberExpr *ret = new UntypedMemberExpr(member->get_name(), args.front()); 438 delete member; 439 return ret; 440 } 432 NameExpr *member = dynamic_cast<NameExpr *>( args.back()); 433 // TupleExpr *memberTup = dynamic_cast<TupleExpr *>( args.back()); 434 435 if ( member != 0 ) { 436 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), args.front()); 437 delete member; 438 return ret; 441 439 /* else if ( memberTup != 0 ) 442 440 { 443 UntypedMemberExpr *ret = new UntypedMemberExpr( memberTup->get_name(), args.front());441 UntypedMemberExpr *ret = new UntypedMemberExpr( memberTup->get_name(), args.front()); 444 442 delete member; 445 443 return ret; 446 444 } */ 447 else445 } else 448 446 assert( false ); 449 447 } … … 452 450 assert( args.size() == 2 ); 453 451 454 NameExpr *member = dynamic_cast<NameExpr *>( args.back()); // modify for Tuples xxx452 NameExpr *member = dynamic_cast<NameExpr *>( args.back()); // modify for Tuples xxx 455 453 assert( member != 0 ); 456 454 … … 458 456 deref->get_args().push_back( args.front() ); 459 457 460 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), deref);458 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), deref ); 461 459 delete member; 462 460 return ret; … … 465 463 case OperatorNode::SizeOf: 466 464 { 467 /// bool isSizeOf = ( op->get_type() == OperatorNode::SizeOf);468 469 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) {470 return new SizeofExpr( arg->get_decl()->buildType());465 /// bool isSizeOf = ( op->get_type() == OperatorNode::SizeOf ); 466 467 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) { 468 return new SizeofExpr( arg->get_decl()->buildType()); 471 469 } else { 472 return new SizeofExpr( args.front());473 } 470 return new SizeofExpr( args.front()); 471 } // if 474 472 } 475 473 case OperatorNode::Attr: 476 474 { 477 VarRefNode *var = dynamic_cast<VarRefNode *>( get_args());475 VarRefNode *var = dynamic_cast<VarRefNode *>( get_args()); 478 476 assert( var ); 479 477 if ( !get_args()->get_link() ) { 480 return new AttrExpr( var->build(), (Expression*)0);481 } else if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()->get_link()) ) {482 return new AttrExpr( var->build(), arg->get_decl()->buildType());478 return new AttrExpr( var->build(), ( Expression*)0); 479 } else if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()->get_link()) ) { 480 return new AttrExpr( var->build(), arg->get_decl()->buildType()); 483 481 } else { 484 return new AttrExpr( var->build(), args.back());485 } 482 return new AttrExpr( var->build(), args.back()); 483 } // if 486 484 } 487 485 case OperatorNode::CompLit: … … 490 488 case OperatorNode::Or: 491 489 case OperatorNode::And: 492 assert( args.size() == 2);493 return new LogicalExpr( notZeroExpr( args.front() ), notZeroExpr( args.back() ), ( op->get_type() == OperatorNode::And) );490 assert( args.size() == 2); 491 return new LogicalExpr( notZeroExpr( args.front() ), notZeroExpr( args.back() ), ( op->get_type() == OperatorNode::And ) ); 494 492 case OperatorNode::Cond: 495 493 { 496 assert( args.size() == 3);494 assert( args.size() == 3); 497 495 std::list< Expression* >::const_iterator i = args.begin(); 498 496 Expression *arg1 = notZeroExpr( *i++ ); … … 505 503 case OperatorNode::Comma: 506 504 { 507 assert( args.size() == 2);505 assert( args.size() == 2); 508 506 std::list< Expression* >::const_iterator i = args.begin(); 509 507 Expression *ret = *i++; … … 527 525 } 528 526 529 void CompositeExprNode::printOneLine( std::ostream &os, int indent) const {530 printDesignation( os);527 void CompositeExprNode::printOneLine( std::ostream &os, int indent ) const { 528 printDesignation( os ); 531 529 os << "( "; 532 530 function->printOneLine( os, indent ); 533 for ( ExpressionNode *cur = arguments; cur != 0; cur = dynamic_cast< ExpressionNode* >( cur->get_link() ) ) {531 for ( ExpressionNode *cur = arguments; cur != 0; cur = dynamic_cast< ExpressionNode* >( cur->get_link() ) ) { 534 532 cur->printOneLine( os, indent ); 535 533 } … … 537 535 } 538 536 539 void CompositeExprNode::print( std::ostream &os, int indent) const {540 printDesignation( os);541 os << '\r' << string( indent, ' ') << "Application of: " << endl;537 void CompositeExprNode::print( std::ostream &os, int indent ) const { 538 printDesignation( os ); 539 os << '\r' << string( indent, ' ') << "Application of: " << endl; 542 540 function->print( os, indent + ParseNode::indent_by ); 543 541 544 os << '\r' << string( indent, ' ') ;542 os << '\r' << string( indent, ' ') ; 545 543 if ( arguments ) { 546 544 os << "... on arguments: " << endl; 547 arguments->printList( os, indent + ParseNode::indent_by);545 arguments->printList( os, indent + ParseNode::indent_by ); 548 546 } else 549 547 os << "... on no arguments: " << endl; 550 548 } 551 549 552 void CompositeExprNode::set_function( ExpressionNode *f){550 void CompositeExprNode::set_function( ExpressionNode *f ){ 553 551 function = f; 554 552 } 555 553 556 void CompositeExprNode::set_args( ExpressionNode *args){554 void CompositeExprNode::set_args( ExpressionNode *args ){ 557 555 arguments = args; 558 556 } 559 557 560 ExpressionNode *CompositeExprNode::get_function( void) const {558 ExpressionNode *CompositeExprNode::get_function( void ) const { 561 559 return function; 562 560 } 563 561 564 ExpressionNode *CompositeExprNode::get_args( void) const {562 ExpressionNode *CompositeExprNode::get_args( void ) const { 565 563 return arguments; 566 564 } 567 565 568 void CompositeExprNode::add_arg( ExpressionNode *arg){569 if ( arguments)570 arguments->set_link( arg);566 void CompositeExprNode::add_arg( ExpressionNode *arg ){ 567 if ( arguments ) 568 arguments->set_link( arg ); 571 569 else 572 set_args( arg);573 } 574 575 CommaExprNode::CommaExprNode(): CompositeExprNode( new OperatorNode(OperatorNode::Comma)) {}576 577 CommaExprNode::CommaExprNode( ExpressionNode *exp) : CompositeExprNode( new OperatorNode(OperatorNode::Comma), exp ) {578 } 579 580 CommaExprNode::CommaExprNode( ExpressionNode *exp1, ExpressionNode *exp2) : CompositeExprNode(new OperatorNode(OperatorNode::Comma), exp1, exp2) {581 } 582 583 CommaExprNode *CommaExprNode::add_to_list( ExpressionNode *exp){584 add_arg( exp);570 set_args( arg ); 571 } 572 573 CommaExprNode::CommaExprNode(): CompositeExprNode( new OperatorNode( OperatorNode::Comma )) {} 574 575 CommaExprNode::CommaExprNode( ExpressionNode *exp ) : CompositeExprNode( new OperatorNode( OperatorNode::Comma ), exp ) { 576 } 577 578 CommaExprNode::CommaExprNode( ExpressionNode *exp1, ExpressionNode *exp2) : CompositeExprNode( new OperatorNode( OperatorNode::Comma ), exp1, exp2) { 579 } 580 581 CommaExprNode *CommaExprNode::add_to_list( ExpressionNode *exp ){ 582 add_arg( exp ); 585 583 586 584 return this; … … 590 588 } 591 589 592 ValofExprNode::ValofExprNode( StatementNode *s): body(s) {}590 ValofExprNode::ValofExprNode( StatementNode *s ): body( s ) {} 593 591 594 592 ValofExprNode::ValofExprNode( const ValofExprNode &other ) : ExpressionNode( other ), body( maybeClone( body ) ) { … … 600 598 601 599 void ValofExprNode::print( std::ostream &os, int indent ) const { 602 printDesignation( os);603 os << string( indent, ' ') << "Valof Expression:" << std::endl;604 get_body()->print( os, indent + 4);600 printDesignation( os ); 601 os << string( indent, ' ') << "Valof Expression:" << std::endl; 602 get_body()->print( os, indent + 4); 605 603 } 606 604 … … 613 611 } 614 612 615 ForCtlExprNode::ForCtlExprNode( ParseNode *init_, ExpressionNode *cond, ExpressionNode *incr) throw (SemanticError) : condition(cond), change(incr) {613 ForCtlExprNode::ForCtlExprNode( ParseNode *init_, ExpressionNode *cond, ExpressionNode *incr ) throw ( SemanticError ) : condition( cond ), change( incr ) { 616 614 if ( init_ == 0 ) 617 615 init = 0; … … 620 618 ExpressionNode *exp; 621 619 622 if (( decl = dynamic_cast<DeclarationNode *>(init_)) != 0)623 init = new StatementNode( decl);624 else if (( exp = dynamic_cast<ExpressionNode *>(init_)) != 0)625 init = new StatementNode( StatementNode::Exp, exp);620 if (( decl = dynamic_cast<DeclarationNode *>( init_)) != 0) 621 init = new StatementNode( decl ); 622 else if (( exp = dynamic_cast<ExpressionNode *>( init_)) != 0) 623 init = new StatementNode( StatementNode::Exp, exp ); 626 624 else 627 625 throw SemanticError("Error in for control expression"); … … 646 644 647 645 void ForCtlExprNode::print( std::ostream &os, int indent ) const{ 648 os << string( indent,' ') << "For Control Expression -- : " << endl;649 650 os << "\r" << string( indent + 2,' ') << "initialization: ";651 if ( init != 0)652 init->print( os, indent + 4);653 654 os << "\n\r" << string( indent + 2,' ') << "condition: ";655 if ( condition != 0)656 condition->print( os, indent + 4);657 os << "\n\r" << string( indent + 2,' ') << "increment: ";658 if ( change != 0)659 change->print( os, indent + 4);646 os << string( indent,' ') << "For Control Expression -- : " << endl; 647 648 os << "\r" << string( indent + 2,' ') << "initialization: "; 649 if ( init != 0) 650 init->print( os, indent + 4); 651 652 os << "\n\r" << string( indent + 2,' ') << "condition: "; 653 if ( condition != 0) 654 condition->print( os, indent + 4); 655 os << "\n\r" << string( indent + 2,' ') << "increment: "; 656 if ( change != 0) 657 change->print( os, indent + 4); 660 658 } 661 659 … … 664 662 } 665 663 666 TypeValueNode::TypeValueNode( DeclarationNode *decl)664 TypeValueNode::TypeValueNode( DeclarationNode *decl ) 667 665 : decl( decl ) { 668 666 } … … 676 674 } 677 675 678 void TypeValueNode::print( std::ostream &os, int indent) const {676 void TypeValueNode::print( std::ostream &os, int indent ) const { 679 677 os << std::string( indent, ' ' ) << "Type:"; 680 get_decl()->print( os, indent + 2);681 } 682 683 void TypeValueNode::printOneLine( std::ostream &os, int indent) const {678 get_decl()->print( os, indent + 2); 679 } 680 681 void TypeValueNode::printOneLine( std::ostream &os, int indent ) const { 684 682 os << "Type:"; 685 get_decl()->print( os, indent + 2);683 get_decl()->print( os, indent + 2); 686 684 } 687 685 … … 690 688 { 691 689 OperatorNode *op; 692 if ( ( op = dynamic_cast< OperatorNode * >( composite->get_function() )) && (op->get_type() == OperatorNode::Comma) )690 if ( ( op = dynamic_cast< OperatorNode * >( composite->get_function() )) && ( op->get_type() == OperatorNode::Comma ) ) 693 691 { 694 692 if ( ExpressionNode *next = dynamic_cast< ExpressionNode * >( list->get_link() ) ) … … 707 705 if ( CompositeExprNode *composite = dynamic_cast< CompositeExprNode * >( tuple ) ) { 708 706 OperatorNode *op = 0; 709 if ( ( op = dynamic_cast< OperatorNode * >( composite->get_function() )) && (op->get_type() == OperatorNode::TupleC) )707 if ( ( op = dynamic_cast< OperatorNode * >( composite->get_function() )) && ( op->get_type() == OperatorNode::TupleC ) ) 710 708 return composite->get_args(); 711 709 } -
translator/Parser/InitializerNode.cc
rad17ba6a rbdd516a 1 #include <cassert> 2 #include <iostream> 3 using namespace std; 4 1 5 #include "ParseNode.h" 2 6 #include "SynTree/Expression.h" 3 7 #include "SynTree/Initializer.h" 4 #include "utility.h"5 #include "SemanticError.h"6 // #include <cstdlib> // for strtol7 #include <cassert>8 9 #include <iostream>10 using namespace std;11 8 12 9 InitializerNode::InitializerNode( ExpressionNode *_expr, bool aggrp, ExpressionNode *des ) -
translator/Parser/ParseNode.cc
rad17ba6a rbdd516a 73 73 } 74 74 75 ParseNode *mkList( ParseNode &pn){75 ParseNode *mkList( ParseNode &pn ) { 76 76 /* it just relies on `operator,' to take care of the "arguments" and provides 77 77 a nice interface to an awful-looking address-of, rendering, for example 78 78 (StatementNode *)(&(*$5 + *$7)) into (StatementNode *)mkList(($5, $7)) 79 (although "nice" 79 (although "nice" is probably not the word) 80 80 */ 81 81 return &pn; -
translator/Parser/ParseNode.h
rad17ba6a rbdd516a 2 2 #define PARSENODE_H 3 3 4 #include <iostream>5 4 #include <string> 6 5 #include <list> … … 8 7 9 8 #include "utility.h" 10 #include "SynTree/SynTree.h"11 9 #include "SynTree/Declaration.h" 12 #include "SemanticError.h"13 10 #include "UniqueName.h" 14 11 … … 23 20 // Builder 24 21 class ParseNode { 25 public: 26 ParseNode(void); 27 ParseNode (std::string); 28 virtual ~ParseNode(void); 29 30 ParseNode *set_name (std::string) ; 31 ParseNode *set_name (std::string *) ; 32 33 std::string get_name(void); 34 35 ParseNode *get_link(void) const; 36 ParseNode *get_last(void); 37 ParseNode *set_link(ParseNode *); 38 void set_next( ParseNode *newlink ) { next = newlink; } 39 40 virtual ParseNode *clone() const { return 0; }; 41 42 const std::string get_name(void) const; 43 virtual void print( std::ostream &, int indent = 0 ) const; 44 virtual void printList( std::ostream &, int indent = 0 ) const; 45 46 ParseNode &operator,(ParseNode &); 47 48 protected: 49 std::string name; 50 ParseNode *next; 51 static int indent_by; 52 }; 53 54 ParseNode *mkList(ParseNode &); 22 public: 23 ParseNode( void ); 24 ParseNode ( std::string ); 25 virtual ~ParseNode( void ); 26 27 ParseNode *set_name ( std::string ) ; 28 ParseNode *set_name ( std::string * ) ; 29 30 std::string get_name( void ); 31 32 ParseNode *get_link( void ) const; 33 ParseNode *get_last( void ); 34 ParseNode *set_link( ParseNode * ); 35 void set_next( ParseNode *newlink ) { next = newlink; } 36 37 virtual ParseNode *clone() const { return 0; }; 38 39 const std::string get_name( void ) const; 40 virtual void print( std::ostream &, int indent = 0 ) const; 41 virtual void printList( std::ostream &, int indent = 0 ) const; 42 43 ParseNode &operator,( ParseNode &); 44 protected: 45 std::string name; 46 ParseNode *next; 47 static int indent_by; 48 }; 49 50 ParseNode *mkList( ParseNode & ); 55 51 56 52 class ExpressionNode : public ParseNode { 57 public: 58 ExpressionNode(); 59 ExpressionNode(std::string *); 60 ExpressionNode( const ExpressionNode &other ); 61 virtual ~ExpressionNode() { /* can't delete asArgName because it might be referenced elsewhere */ }; 62 63 virtual ExpressionNode *clone() const = 0; 64 65 virtual CommaExprNode *add_to_list(ExpressionNode *); 66 67 ExpressionNode *get_argName() const { return argName; } 68 ExpressionNode *set_asArgName( std::string *aName ); 69 ExpressionNode *set_asArgName( ExpressionNode *aDesignator ); 70 71 virtual void print(std::ostream &, int indent = 0) const = 0; 72 virtual void printOneLine(std::ostream &, int indent = 0) const = 0; 73 74 virtual Expression *build() const = 0; 75 protected: 76 void printDesignation (std::ostream &, int indent = 0) const; 77 78 private: 79 ExpressionNode *argName; 80 }; 81 82 // NullExprNode is used in tuples as a place-holder where a tuple component is omitted 83 // e.g., [ 2, , 3 ] 84 class NullExprNode : public ExpressionNode 85 { 86 public: 87 NullExprNode(); 88 89 virtual NullExprNode *clone() const; 90 91 virtual void print(std::ostream &, int indent = 0) const; 92 virtual void printOneLine(std::ostream &, int indent = 0) const; 93 94 virtual Expression *build() const; 53 public: 54 ExpressionNode(); 55 ExpressionNode( std::string * ); 56 ExpressionNode( const ExpressionNode &other ); 57 virtual ~ExpressionNode() { /* can't delete asArgName because it might be referenced elsewhere */ }; 58 59 virtual ExpressionNode *clone() const = 0; 60 61 virtual CommaExprNode *add_to_list( ExpressionNode * ); 62 63 ExpressionNode *get_argName() const { return argName; } 64 ExpressionNode *set_asArgName( std::string *aName ); 65 ExpressionNode *set_asArgName( ExpressionNode *aDesignator ); 66 67 virtual void print( std::ostream &, int indent = 0) const = 0; 68 virtual void printOneLine( std::ostream &, int indent = 0) const = 0; 69 70 virtual Expression *build() const = 0; 71 protected: 72 void printDesignation ( std::ostream &, int indent = 0) const; 73 private: 74 ExpressionNode *argName; 75 }; 76 77 // NullExprNode is used in tuples as a place-holder where a tuple component is omitted e.g., [ 2, , 3 ] 78 class NullExprNode : public ExpressionNode { 79 public: 80 NullExprNode(); 81 82 virtual NullExprNode *clone() const; 83 84 virtual void print( std::ostream &, int indent = 0) const; 85 virtual void printOneLine( std::ostream &, int indent = 0) const; 86 87 virtual Expression *build() const; 95 88 }; 96 89 97 90 class ConstantNode : public ExpressionNode { 98 public: 99 enum Type { 100 Integer, Float, Character, String /* , Range, EnumConstant */ 101 }; 102 103 ConstantNode(void); 104 ConstantNode(std::string *); 105 ConstantNode(Type, std::string *); 106 ConstantNode( const ConstantNode &other ); 107 108 virtual ConstantNode *clone() const { return new ConstantNode( *this ); } 109 110 Type get_type(void) const ; 111 virtual void print(std::ostream &, int indent = 0) const; 112 virtual void printOneLine(std::ostream &, int indent = 0) const; 113 114 std::string get_value() const { return value; } 115 ConstantNode *append( std::string *newValue ); 116 117 Expression *build() const; 118 119 private: 120 void classify(std::string &); 121 Type type; 122 std::string value; 123 bool sign; 124 short base; 125 int longs, size; 91 public: 92 enum Type { 93 Integer, Float, Character, String /* , Range, EnumConstant */ 94 }; 95 96 ConstantNode( void ); 97 ConstantNode( std::string * ); 98 ConstantNode( Type, std::string * ); 99 ConstantNode( const ConstantNode &other ); 100 101 virtual ConstantNode *clone() const { return new ConstantNode( *this ); } 102 103 Type get_type( void ) const ; 104 virtual void print( std::ostream &, int indent = 0) const; 105 virtual void printOneLine( std::ostream &, int indent = 0) const; 106 107 std::string get_value() const { return value; } 108 ConstantNode *append( std::string *newValue ); 109 110 Expression *build() const; 111 private: 112 void classify( std::string &); 113 Type type; 114 std::string value; 115 bool sign; 116 short base; 117 int longs, size; 126 118 }; 127 119 128 120 class VarRefNode : public ExpressionNode { 129 public: 130 VarRefNode(); 131 VarRefNode(std::string *, bool isLabel = false ); 132 VarRefNode( const VarRefNode &other ); 133 134 virtual Expression *build() const ; 135 136 virtual VarRefNode *clone() const { return new VarRefNode( *this ); } 137 138 virtual void print(std::ostream &, int indent = 0) const; 139 virtual void printOneLine(std::ostream &, int indent = 0) const; 140 private: 141 bool isLabel; 142 }; 143 144 class TypeValueNode : public ExpressionNode 145 { 146 public: 147 TypeValueNode(DeclarationNode *); 148 TypeValueNode( const TypeValueNode &other ); 149 150 DeclarationNode *get_decl() const { return decl; } 151 152 virtual Expression *build() const ; 153 154 virtual TypeValueNode *clone() const { return new TypeValueNode( *this ); } 155 156 virtual void print(std::ostream &, int indent = 0) const; 157 virtual void printOneLine(std::ostream &, int indent = 0) const; 158 private: 159 DeclarationNode *decl; 121 public: 122 VarRefNode(); 123 VarRefNode( std::string *, bool isLabel = false ); 124 VarRefNode( const VarRefNode &other ); 125 126 virtual Expression *build() const ; 127 128 virtual VarRefNode *clone() const { return new VarRefNode( *this ); } 129 130 virtual void print( std::ostream &, int indent = 0) const; 131 virtual void printOneLine( std::ostream &, int indent = 0) const; 132 private: 133 bool isLabel; 134 }; 135 136 class TypeValueNode : public ExpressionNode { 137 public: 138 TypeValueNode( DeclarationNode * ); 139 TypeValueNode( const TypeValueNode &other ); 140 141 DeclarationNode *get_decl() const { return decl; } 142 143 virtual Expression *build() const ; 144 145 virtual TypeValueNode *clone() const { return new TypeValueNode( *this ); } 146 147 virtual void print( std::ostream &, int indent = 0) const; 148 virtual void printOneLine( std::ostream &, int indent = 0) const; 149 private: 150 DeclarationNode *decl; 160 151 }; 161 152 162 153 class OperatorNode : public ExpressionNode { 163 public:164 enum Type { TupleC, Comma, TupleFieldSel,165 166 154 public: 155 enum Type { TupleC, Comma, TupleFieldSel, 156 Cond, NCond, 157 SizeOf, AlignOf, Attr, CompLit, Plus, Minus, Mul, Div, Mod, Or, And, 167 158 BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq, 168 159 Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, 169 160 ERAssn, OrAssn, Index, FieldSel, PFieldSel, Range, 170 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress 171 }; 172 173 OperatorNode(Type t); 174 OperatorNode( const OperatorNode &other ); 175 virtual ~OperatorNode(); 176 177 virtual OperatorNode *clone() const { return new OperatorNode( *this ); } 178 179 Type get_type(void) const; 180 std::string get_typename(void) const; 181 182 virtual void print(std::ostream &, int indent = 0) const; 183 virtual void printOneLine(std::ostream &, int indent = 0) const; 184 185 virtual Expression *build() const { return 0; } 161 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress 162 }; 163 164 OperatorNode( Type t ); 165 OperatorNode( const OperatorNode &other ); 166 virtual ~OperatorNode(); 167 168 virtual OperatorNode *clone() const { return new OperatorNode( *this ); } 169 170 Type get_type( void ) const; 171 std::string get_typename( void ) const; 172 173 virtual void print( std::ostream &, int indent = 0) const; 174 virtual void printOneLine( std::ostream &, int indent = 0) const; 175 176 virtual Expression *build() const { return 0; } 177 private: 178 Type type; 179 static const char *OpName[]; 180 }; 181 182 183 class CompositeExprNode : public ExpressionNode { 184 public: 185 CompositeExprNode( void ); 186 CompositeExprNode( std::string * ); 187 CompositeExprNode( ExpressionNode *f, ExpressionNode *args = 0 ); 188 CompositeExprNode( ExpressionNode *f, ExpressionNode *arg1, ExpressionNode *arg2 ); 189 CompositeExprNode( const CompositeExprNode &other ); 190 virtual ~CompositeExprNode(); 191 192 virtual CompositeExprNode *clone() const { return new CompositeExprNode( *this ); } 193 virtual Expression *build() const; 194 195 virtual void print( std::ostream &, int indent = 0) const; 196 virtual void printOneLine( std::ostream &, int indent = 0) const; 197 198 void set_function( ExpressionNode * ); 199 void set_args( ExpressionNode * ); 200 201 void add_arg( ExpressionNode * ); 202 203 ExpressionNode *get_function() const; 204 ExpressionNode *get_args() const; 205 private: 206 ExpressionNode *function; 207 ExpressionNode *arguments; 208 }; 209 210 class CommaExprNode : public CompositeExprNode { 211 public: 212 CommaExprNode(); 213 CommaExprNode( ExpressionNode * ); 214 CommaExprNode( ExpressionNode *, ExpressionNode * ); 215 CommaExprNode( const CommaExprNode &other ); 216 217 virtual CommaExprNode *add_to_list( ExpressionNode * ); 218 virtual CommaExprNode *clone() const { return new CommaExprNode( *this ); } 219 }; 220 221 class ForCtlExprNode : public ExpressionNode { 222 public: 223 ForCtlExprNode( ParseNode *, ExpressionNode *, ExpressionNode * ) throw ( SemanticError ); 224 ForCtlExprNode( const ForCtlExprNode &other ); 225 ~ForCtlExprNode(); 226 227 StatementNode *get_init() const { return init; } 228 ExpressionNode *get_condition() const { return condition; } 229 ExpressionNode *get_change() const { return change; } 230 231 virtual ForCtlExprNode *clone() const { return new ForCtlExprNode( *this ); } 232 virtual Expression *build() const; 233 234 virtual void print( std::ostream &, int indent = 0 ) const; 235 virtual void printOneLine( std::ostream &, int indent = 0 ) const; 236 private: 237 StatementNode *init; 238 ExpressionNode *condition; 239 ExpressionNode *change; 240 }; 241 242 class ValofExprNode : public ExpressionNode { 243 public: 244 ValofExprNode(); 245 ValofExprNode( StatementNode *s = 0 ); 246 ValofExprNode( const ValofExprNode &other ); 247 ~ValofExprNode(); 186 248 187 private: 188 Type type; 189 static const char *OpName[]; 190 }; 191 192 193 class CompositeExprNode : public ExpressionNode { 194 public: 195 CompositeExprNode(void); 196 CompositeExprNode(std::string *); 197 CompositeExprNode(ExpressionNode *f, ExpressionNode *args = 0); 198 CompositeExprNode(ExpressionNode *f, ExpressionNode *arg1, ExpressionNode *arg2); 199 CompositeExprNode( const CompositeExprNode &other ); 200 virtual ~CompositeExprNode(); 201 202 virtual CompositeExprNode *clone() const { return new CompositeExprNode( *this ); } 203 virtual Expression *build() const; 204 205 virtual void print(std::ostream &, int indent = 0) const; 206 virtual void printOneLine(std::ostream &, int indent = 0) const; 207 208 void set_function(ExpressionNode *); 209 void set_args(ExpressionNode *); 210 211 void add_arg(ExpressionNode *); 212 213 ExpressionNode *get_function() const; 214 ExpressionNode *get_args() const; 215 216 private: 217 ExpressionNode *function; 218 ExpressionNode *arguments; 219 }; 220 221 class CommaExprNode : public CompositeExprNode { 222 public: 223 CommaExprNode(); 224 CommaExprNode(ExpressionNode *); 225 CommaExprNode(ExpressionNode *, ExpressionNode *); 226 CommaExprNode( const CommaExprNode &other ); 227 228 virtual CommaExprNode *add_to_list(ExpressionNode *); 229 virtual CommaExprNode *clone() const { return new CommaExprNode( *this ); } 230 }; 231 232 class ForCtlExprNode : public ExpressionNode { 233 public: 234 ForCtlExprNode(ParseNode *, ExpressionNode *, ExpressionNode *) throw (SemanticError); 235 ForCtlExprNode( const ForCtlExprNode &other ); 236 ~ForCtlExprNode(); 237 238 StatementNode *get_init() const { return init; } 239 ExpressionNode *get_condition() const { return condition; } 240 ExpressionNode *get_change() const { return change; } 241 242 virtual ForCtlExprNode *clone() const { return new ForCtlExprNode( *this ); } 243 virtual Expression *build() const; 244 245 virtual void print( std::ostream &, int indent = 0 ) const; 246 virtual void printOneLine( std::ostream &, int indent = 0 ) const; 247 private: 248 StatementNode *init; 249 ExpressionNode *condition; 250 ExpressionNode *change; 251 }; 252 253 class ValofExprNode : public ExpressionNode { 254 public: 255 ValofExprNode(); 256 ValofExprNode( StatementNode *s = 0 ); 257 ValofExprNode( const ValofExprNode &other ); 258 ~ValofExprNode(); 259 260 virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); } 261 262 StatementNode *get_body() const { return body; } 263 void print( std::ostream &, int indent = 0 ) const; 264 void printOneLine( std::ostream &, int indent = 0 ) const; 265 Expression *build() const; 266 267 private: 268 StatementNode *body; 249 virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); } 250 251 StatementNode *get_body() const { return body; } 252 void print( std::ostream &, int indent = 0 ) const; 253 void printOneLine( std::ostream &, int indent = 0 ) const; 254 Expression *build() const; 255 256 private: 257 StatementNode *body; 269 258 }; 270 259 271 260 class TypeData; 272 261 273 class DeclarationNode : public ParseNode 274 { 275 public: 276 enum Qualifier { Const, Restrict, Volatile, Lvalue }; 277 enum StorageClass { Static, Auto, Extern, Register, Inline, Fortran }; 278 enum BasicType { Char, Int, Float, Double, Void, Bool, Complex, Imaginary }; 279 enum Modifier { Signed, Unsigned, Short, Long }; 280 enum TyCon { Struct, Union, Context }; 281 enum TypeClass { Type, Dtype, Ftype }; 282 283 static const char *qualifierName[]; 284 static const char *basicTypeName[]; 285 static const char *modifierName[]; 286 static const char *tyConName[]; 287 static const char *typeClassName[]; 288 289 static DeclarationNode *newFunction( std::string* name, DeclarationNode *ret, DeclarationNode *param, 290 StatementNode *body, bool newStyle = false ); 291 static DeclarationNode *newQualifier( Qualifier ); 292 static DeclarationNode *newStorageClass( StorageClass ); 293 static DeclarationNode *newBasicType( BasicType ); 294 static DeclarationNode *newModifier( Modifier ); 295 static DeclarationNode *newForall( DeclarationNode* ); 296 static DeclarationNode *newFromTypedef( std::string* ); 297 static DeclarationNode *newAggregate( TyCon kind, std::string* name, DeclarationNode *formals, ExpressionNode *actuals, DeclarationNode *fields ); 298 static DeclarationNode *newEnum( std::string *name, DeclarationNode *constants ); 299 static DeclarationNode *newEnumConstant( std::string* name, ExpressionNode *constant ); 300 static DeclarationNode *newName( std::string* ); 301 static DeclarationNode *newFromTypeGen( std::string*, ExpressionNode *params ); 302 static DeclarationNode *newTypeParam( TypeClass, std::string* ); 303 static DeclarationNode *newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts ); 304 static DeclarationNode *newContextUse( std::string *name, ExpressionNode *params ); 305 static DeclarationNode *newTypeDecl( std::string *name, DeclarationNode *typeParams ); 306 static DeclarationNode *newPointer( DeclarationNode *qualifiers ); 307 static DeclarationNode *newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ); 308 static DeclarationNode *newVarArray( DeclarationNode *qualifiers ); 309 static DeclarationNode *newBitfield( ExpressionNode *size ); 310 static DeclarationNode *newTuple( DeclarationNode *members ); 311 static DeclarationNode *newTypeof( ExpressionNode *expr ); 312 static DeclarationNode *newAttr( std::string*, ExpressionNode *expr ); 313 static DeclarationNode *newAttr( std::string*, DeclarationNode *type ); 314 315 DeclarationNode *addQualifiers( DeclarationNode* ); 316 DeclarationNode *copyStorageClasses( DeclarationNode* ); 317 DeclarationNode *addType( DeclarationNode* ); 318 DeclarationNode *addTypedef(); 319 DeclarationNode *addAssertions( DeclarationNode* ); 320 DeclarationNode *addName( std::string* ); 321 DeclarationNode *addBitfield( ExpressionNode *size ); 322 DeclarationNode *addVarArgs(); 323 DeclarationNode *addFunctionBody( StatementNode *body ); 324 DeclarationNode *addOldDeclList( DeclarationNode *list ); 325 DeclarationNode *addPointer( DeclarationNode *qualifiers ); 326 DeclarationNode *addArray( DeclarationNode *array ); 327 DeclarationNode *addNewPointer( DeclarationNode *pointer ); 328 DeclarationNode *addNewArray( DeclarationNode *array ); 329 DeclarationNode *addParamList( DeclarationNode *list ); 330 DeclarationNode *addIdList( DeclarationNode *list ); // old-style functions 331 DeclarationNode *addInitializer( InitializerNode *init ); 332 333 DeclarationNode *cloneType( std::string *newName ); 334 DeclarationNode *cloneType( DeclarationNode *existing ); 335 DeclarationNode *cloneType( int ) { return cloneType( (std::string*)0 ); } 336 DeclarationNode *cloneBaseType( std::string *newName ); 337 DeclarationNode *cloneBaseType( DeclarationNode *newdecl ); 338 339 DeclarationNode *appendList( DeclarationNode * ); 340 341 DeclarationNode *clone() const; 342 void print( std::ostream &, int indent = 0 ) const; 343 void printList( std::ostream &, int indent = 0 ) const; 344 345 Declaration *build() const; 346 ::Type *buildType() const; 347 348 bool get_hasEllipsis() const; 349 std::string get_name() const { return name; } 350 LinkageSpec::Type get_linkage() const { return linkage; } 351 DeclarationNode *extractAggregate() const; 352 353 DeclarationNode(); 354 ~DeclarationNode(); 355 private: 356 Declaration::StorageClass buildStorageClass() const; 357 bool buildInline() const; 358 359 TypeData *type; 360 std::string name; 361 std::list< StorageClass > storageClasses; 362 ExpressionNode *bitfieldWidth; 363 InitializerNode *initializer; 364 bool hasEllipsis; 365 LinkageSpec::Type linkage; 366 367 static UniqueName anonymous; 262 class DeclarationNode : public ParseNode { 263 public: 264 enum Qualifier { Const, Restrict, Volatile, Lvalue, Atomic }; 265 enum StorageClass { Static, Auto, Extern, Register, Inline, Fortran }; 266 enum BasicType { Char, Int, Float, Double, Void, Bool, Complex, Imaginary }; 267 enum Modifier { Signed, Unsigned, Short, Long }; 268 enum TyCon { Struct, Union, Context }; 269 enum TypeClass { Type, Dtype, Ftype }; 270 271 static const char *qualifierName[]; 272 static const char *basicTypeName[]; 273 static const char *modifierName[]; 274 static const char *tyConName[]; 275 static const char *typeClassName[]; 276 277 static DeclarationNode *newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, 278 StatementNode *body, bool newStyle = false ); 279 static DeclarationNode *newQualifier( Qualifier ); 280 static DeclarationNode *newStorageClass( StorageClass ); 281 static DeclarationNode *newBasicType( BasicType ); 282 static DeclarationNode *newModifier( Modifier ); 283 static DeclarationNode *newForall( DeclarationNode *); 284 static DeclarationNode *newFromTypedef( std::string *); 285 static DeclarationNode *newAggregate( TyCon kind, std::string *name, DeclarationNode *formals, ExpressionNode *actuals, DeclarationNode *fields ); 286 static DeclarationNode *newEnum( std::string *name, DeclarationNode *constants ); 287 static DeclarationNode *newEnumConstant( std::string *name, ExpressionNode *constant ); 288 static DeclarationNode *newName( std::string *); 289 static DeclarationNode *newFromTypeGen( std::string*, ExpressionNode *params ); 290 static DeclarationNode *newTypeParam( TypeClass, std::string *); 291 static DeclarationNode *newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts ); 292 static DeclarationNode *newContextUse( std::string *name, ExpressionNode *params ); 293 static DeclarationNode *newTypeDecl( std::string *name, DeclarationNode *typeParams ); 294 static DeclarationNode *newPointer( DeclarationNode *qualifiers ); 295 static DeclarationNode *newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ); 296 static DeclarationNode *newVarArray( DeclarationNode *qualifiers ); 297 static DeclarationNode *newBitfield( ExpressionNode *size ); 298 static DeclarationNode *newTuple( DeclarationNode *members ); 299 static DeclarationNode *newTypeof( ExpressionNode *expr ); 300 static DeclarationNode *newAttr( std::string*, ExpressionNode *expr ); 301 static DeclarationNode *newAttr( std::string*, DeclarationNode *type ); 302 303 DeclarationNode *addQualifiers( DeclarationNode *); 304 DeclarationNode *copyStorageClasses( DeclarationNode *); 305 DeclarationNode *addType( DeclarationNode *); 306 DeclarationNode *addTypedef(); 307 DeclarationNode *addAssertions( DeclarationNode *); 308 DeclarationNode *addName( std::string *); 309 DeclarationNode *addBitfield( ExpressionNode *size ); 310 DeclarationNode *addVarArgs(); 311 DeclarationNode *addFunctionBody( StatementNode *body ); 312 DeclarationNode *addOldDeclList( DeclarationNode *list ); 313 DeclarationNode *addPointer( DeclarationNode *qualifiers ); 314 DeclarationNode *addArray( DeclarationNode *array ); 315 DeclarationNode *addNewPointer( DeclarationNode *pointer ); 316 DeclarationNode *addNewArray( DeclarationNode *array ); 317 DeclarationNode *addParamList( DeclarationNode *list ); 318 DeclarationNode *addIdList( DeclarationNode *list ); // old-style functions 319 DeclarationNode *addInitializer( InitializerNode *init ); 320 321 DeclarationNode *cloneType( std::string *newName ); 322 DeclarationNode *cloneType( DeclarationNode *existing ); 323 DeclarationNode *cloneType( int ) { return cloneType( ( std::string *)0 ); } 324 DeclarationNode *cloneBaseType( std::string *newName ); 325 DeclarationNode *cloneBaseType( DeclarationNode *newdecl ); 326 327 DeclarationNode *appendList( DeclarationNode *); 328 329 DeclarationNode *clone() const; 330 void print( std::ostream &, int indent = 0 ) const; 331 void printList( std::ostream &, int indent = 0 ) const; 332 333 Declaration *build() const; 334 ::Type *buildType() const; 335 336 bool get_hasEllipsis() const; 337 std::string get_name() const { return name; } 338 LinkageSpec::Type get_linkage() const { return linkage; } 339 DeclarationNode *extractAggregate() const; 340 341 DeclarationNode(); 342 ~DeclarationNode(); 343 private: 344 Declaration::StorageClass buildStorageClass() const; 345 bool buildInline() const; 346 347 TypeData *type; 348 std::string name; 349 std::list< StorageClass > storageClasses; 350 ExpressionNode *bitfieldWidth; 351 InitializerNode *initializer; 352 bool hasEllipsis; 353 LinkageSpec::Type linkage; 354 355 static UniqueName anonymous; 368 356 }; 369 357 370 358 class StatementNode : public ParseNode { 371 public: 372 enum Type { Exp, If, Switch, Case, Default, Choose, Fallthru, 373 While, Do, For, 374 Goto, Continue, Break, Return, Throw, 375 Try, Catch, Finally, Asm, 376 Decl 377 }; 378 379 StatementNode( void ); 380 StatementNode( std::string ); 381 StatementNode( Type, ExpressionNode *e = 0, StatementNode *s = 0 ); 382 StatementNode( Type, std::string *target ); 383 StatementNode( DeclarationNode *decl ); 384 385 386 ~StatementNode(void); 387 388 static StatementNode * newCatchStmt(DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false ); 389 390 void set_control(ExpressionNode *); 391 StatementNode * set_block(StatementNode *); 392 393 ExpressionNode *get_control() const ; 394 StatementNode *get_block() const; 395 StatementNode::Type get_type(void) const; 396 397 StatementNode *add_label(std::string *); 398 std::list<std::string> *get_labels() const; 399 400 void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; } 401 void setCatchRest( bool newVal ) { isCatchRest = newVal; } 402 403 std::string get_target() const; 404 405 StatementNode *add_controlexp(ExpressionNode *); 406 StatementNode *append_block(StatementNode *); 407 StatementNode *append_last_case(StatementNode *); 408 409 void print( std::ostream &, int indent = 0) const; 410 411 virtual StatementNode *clone() const; 412 413 virtual Statement *build() const; 414 415 private: 416 static const char *StType[]; 417 Type type; 418 ExpressionNode *control; 419 StatementNode *block; 420 std::list<std::string> *labels; 421 std::string *target; // target label for jump statements 422 DeclarationNode *decl; 423 424 bool isCatchRest; 359 public: 360 enum Type { Exp, If, Switch, Case, Default, Choose, Fallthru, 361 While, Do, For, 362 Goto, Continue, Break, Return, Throw, 363 Try, Catch, Finally, Asm, 364 Decl 365 }; 366 367 StatementNode( void ); 368 StatementNode( std::string ); 369 StatementNode( Type, ExpressionNode *e = 0, StatementNode *s = 0 ); 370 StatementNode( Type, std::string *target ); 371 StatementNode( DeclarationNode *decl ); 372 373 374 ~StatementNode( void ); 375 376 static StatementNode *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false ); 377 378 void set_control( ExpressionNode * ); 379 StatementNode * set_block( StatementNode * ); 380 381 ExpressionNode *get_control() const ; 382 StatementNode *get_block() const; 383 StatementNode::Type get_type( void ) const; 384 385 StatementNode *add_label( std::string * ); 386 std::list<std::string> *get_labels() const; 387 388 void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; } 389 void setCatchRest( bool newVal ) { isCatchRest = newVal; } 390 391 std::string get_target() const; 392 393 StatementNode *add_controlexp( ExpressionNode * ); 394 StatementNode *append_block( StatementNode * ); 395 StatementNode *append_last_case( StatementNode * ); 396 397 void print( std::ostream &, int indent = 0) const; 398 399 virtual StatementNode *clone() const; 400 401 virtual Statement *build() const; 402 private: 403 static const char *StType[]; 404 Type type; 405 ExpressionNode *control; 406 StatementNode *block; 407 std::list<std::string> *labels; 408 std::string *target; // target label for jump statements 409 DeclarationNode *decl; 410 411 bool isCatchRest; 425 412 }; 426 413 427 414 class CompoundStmtNode : public StatementNode { 428 public: 429 CompoundStmtNode(void); 430 CompoundStmtNode(std::string *); 431 CompoundStmtNode(StatementNode *); 432 ~CompoundStmtNode(); 433 434 void add_statement(StatementNode *); 435 436 void print( std::ostream &, int indent = 0 ) const; 437 438 virtual Statement *build() const; 439 440 private: 441 StatementNode *first, *last; 415 public: 416 CompoundStmtNode( void ); 417 CompoundStmtNode( std::string * ); 418 CompoundStmtNode( StatementNode * ); 419 ~CompoundStmtNode(); 420 421 void add_statement( StatementNode * ); 422 423 void print( std::ostream &, int indent = 0 ) const; 424 425 virtual Statement *build() const; 426 private: 427 StatementNode *first, *last; 442 428 }; 443 429 444 430 class NullStmtNode : public CompoundStmtNode { 445 public:446 Statement *build() const;447 void print(std::ostream &, int indent = 0) const;431 public: 432 Statement *build() const; 433 void print( std::ostream &, int indent = 0) const; 448 434 }; 449 435 450 436 class InitializerNode : public ParseNode { 451 public: 452 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode *des = 0 ); 453 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 ); 454 ~InitializerNode(); 455 456 ExpressionNode *get_expression() const { return expr; } 457 458 InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; } 459 ExpressionNode *get_designators() const { return designator; } 460 461 InitializerNode *next_init() const { return kids; } 462 463 void print( std::ostream &, int indent = 0 ) const; 464 void printOneLine( std::ostream & ) const; 465 466 virtual Initializer *build() const; 467 468 private: 469 ExpressionNode *expr; 470 bool aggregate; 471 ExpressionNode *designator; // may be list 472 InitializerNode *kids; 437 public: 438 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode *des = 0 ); 439 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 ); 440 ~InitializerNode(); 441 442 ExpressionNode *get_expression() const { return expr; } 443 444 InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; } 445 ExpressionNode *get_designators() const { return designator; } 446 447 InitializerNode *next_init() const { return kids; } 448 449 void print( std::ostream &, int indent = 0 ) const; 450 void printOneLine( std::ostream & ) const; 451 452 virtual Initializer *build() const; 453 private: 454 ExpressionNode *expr; 455 bool aggregate; 456 ExpressionNode *designator; // may be list 457 InitializerNode *kids; 473 458 }; 474 459 … … 477 462 template< typename SynTreeType, typename NodeType > 478 463 void 479 buildList( const NodeType *firstNode, std::list< SynTreeType *> &outputList )464 buildList( const NodeType *firstNode, std::list< SynTreeType *> &outputList ) 480 465 { 481 SemanticError errors;482 std::back_insert_iterator< std::list< SynTreeType*> > out( outputList );483 const NodeType *cur = firstNode;484 485 while( cur ) {486 487 SynTreeType *result = dynamic_cast< SynTreeType*>( cur->build() );488 if( result ) {489 490 491 } 492 493 494 } 495 cur = dynamic_cast< NodeType*>( cur->get_link() );496 }497 if( !errors.isEmpty() ) {498 499 }466 SemanticError errors; 467 std::back_insert_iterator< std::list< SynTreeType *> > out( outputList ); 468 const NodeType *cur = firstNode; 469 470 while ( cur ) { 471 try { 472 SynTreeType *result = dynamic_cast< SynTreeType *>( cur->build() ); 473 if ( result ) { 474 *out++ = result; 475 } else { 476 } // if 477 } catch( SemanticError &e ) { 478 errors.append( e ); 479 } // try 480 cur = dynamic_cast< NodeType *>( cur->get_link() ); 481 } // while 482 if ( !errors.isEmpty() ) { 483 throw errors; 484 } // if 500 485 } 501 486 502 487 // in DeclarationNode.cc 503 void buildList( const DeclarationNode *firstNode, std::list< Declaration *> &outputList );504 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList );505 void buildTypeList( const DeclarationNode *firstNode, std::list< Type *> &outputList );488 void buildList( const DeclarationNode *firstNode, std::list< Declaration *> &outputList ); 489 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList ); 490 void buildTypeList( const DeclarationNode *firstNode, std::list< Type *> &outputList ); 506 491 507 492 // in ExpressionNode.cc … … 509 494 ExpressionNode *tupleContents( ExpressionNode *tuple ); 510 495 511 #endif / * #ifndef PARSENODE_H */496 #endif // PARSENODE_H 512 497 513 498 // Local Variables: // -
translator/Parser/TypeData.cc
rad17ba6a rbdd516a 541 541 case DeclarationNode::Lvalue: 542 542 q.isLvalue = true; 543 break; 544 case DeclarationNode::Atomic: 545 q.isAtomic = true; 543 546 break; 544 547 } -
translator/Parser/TypeData.h
rad17ba6a rbdd516a 3 3 4 4 #include <list> 5 5 6 #include "ParseNode.h" 6 #include "SynTree/SynTree.h"7 7 #include "SynTree/Type.h" 8 #include "SynTree/Declaration.h"9 #include "SemanticError.h"10 #include "LinkageSpec.h"11 8 12 9 struct TypeData { -
translator/Parser/cfa.y
rad17ba6a rbdd516a 10 10 * Created On : Sat Sep 1 20:22:55 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Sat Jan 17 09:23:45201513 * Update Count : 9 0812 * Last Modified On : Wed Apr 15 15:11:16 2015 13 * Update Count : 913 14 14 */ 15 15 … … 1144 1144 declaration_specifier declarator asm_name_opt initializer_opt 1145 1145 { 1146 typedefTable.addToEnclosingScope( TypedefTable::ID );1146 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1147 1147 $$ = ($2->addType( $1 ))->addInitializer($4); 1148 1148 } … … 1201 1201 | LVALUE /* CFA */ 1202 1202 { $$ = DeclarationNode::newQualifier( DeclarationNode::Lvalue ); } 1203 | ATOMIC 1204 { $$ = DeclarationNode::newQualifier( DeclarationNode::Atomic ); } 1203 1205 | FORALL '(' 1204 1206 { -
translator/Parser/parseutility.cc
rad17ba6a rbdd516a 1 /*2 * This file is part of the Cforall project3 *4 * $Id: parseutility.cc,v 1.2 2005/08/29 20:14:15 rcbilson Exp $5 *6 */7 8 1 #include "parseutility.h" 9 2 #include "SynTree/Type.h" … … 11 4 12 5 13 Expression * 14 notZeroExpr( Expression *orig ) 15 { 6 Expression *notZeroExpr( Expression *orig ) { 16 7 UntypedExpr *comparison = new UntypedExpr( new NameExpr( "?!=?" ) ); 17 8 comparison->get_args().push_back( orig ); -
translator/Parser/parseutility.h
rad17ba6a rbdd516a 1 /*2 * This file is part of the Cforall project3 *4 * $Id: parseutility.h,v 1.2 2005/08/29 20:14:15 rcbilson Exp $5 *6 */7 8 1 #ifndef PARSER_PARSEUTILITY_H 9 2 #define PARSER_PARSEUTILITY_H … … 13 6 Expression *notZeroExpr( Expression *orig ); 14 7 15 #endif / * #ifndef PARSER_PARSEUTILITY_H */8 #endif // PARSER_PARSEUTILITY_H
Note: See TracChangeset
for help on using the changeset viewer.