Changeset bdd516a
- Timestamp:
- Apr 28, 2015, 4:21:36 PM (10 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
- Files:
-
- 3 added
- 1 deleted
- 42 edited
Legend:
- Unmodified
- Added
- Removed
-
driver/cc1.cc
rad17ba6a rbdd516a 8 8 // Created On : Fri Aug 26 14:23:51 2005 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Sat Jan 10 14:16:06201511 // Update Count : 1510 // Last Modified On : Mon Apr 27 23:11:52 2015 11 // Update Count : 39 12 12 // 13 13 … … 34 34 string D__CFA_FLAGPREFIX__( "-D__CFA_FLAG__=" ); 35 35 36 char tmpname[] = P_tmpdir "/CFAXXXXXX"; 37 int tmpfilefd = -1; 38 36 39 37 40 bool prefix( string arg, string pre ) { … … 69 72 } // if 70 73 } // checkEnv 74 75 76 void rmtmpfile() { 77 if ( unlink( tmpname ) == -1 ) { // remove tmpname 78 perror ( "CFA Translator error: cpp failed" ); 79 exit( EXIT_FAILURE ); 80 } // if 81 tmpfilefd = -1; // mark closed 82 } // rmtmpfile 83 84 85 void sigTermHandler( int signal ) { 86 if ( tmpfilefd != -1 ) { // RACE, file created ? 87 rmtmpfile(); // remove 88 exit( EXIT_FAILURE ); // terminate 89 } // if 90 } // sigTermHandler 71 91 72 92 … … 89 109 const char *uargs[20]; // leave space for 20 additional cfa-cpp command line values 90 110 int nuargs = 1; // 0 => command name 111 112 signal( SIGINT, sigTermHandler ); 113 signal( SIGTERM, sigTermHandler ); 91 114 92 115 // process all the arguments … … 116 139 i += 1; // and the argument 117 140 118 // strip cfa flags controlling cpp step 119 141 // strip flags controlling cpp step 142 143 } else if ( arg == "-D__CPP__" ) { 144 cpp_flag = true; 145 } else if ( arg == "-D" && string( argv[i + 1] ) == "__CPP__" ) { 146 i += 1; // and the argument 147 cpp_flag = true; 120 148 } else if ( arg == "-D__CFA__" ) { 121 149 CFA_flag = true; … … 123 151 i += 1; // and the argument 124 152 CFA_flag = true; 125 } else if ( arg == "-D__CPP__" ) {126 cpp_flag = true;127 } else if ( arg == "-D" && string( argv[i + 1] ) == "__CPP__" ) {128 i += 1; // and the argument129 cpp_flag = true;130 153 } else if ( prefix( arg, D__CFA_FLAGPREFIX__ ) ) { 131 154 uargs[nuargs] = ( *new string( arg.substr( D__CFA_FLAGPREFIX__.size() ) ) ).c_str(); … … 233 256 // Create a temporary file to store output of the C preprocessor. 234 257 235 char tmpname[] = P_tmpdir "/CFAXXXXXX"; 236 int tmpfile = mkstemp( tmpname ); 237 if ( tmpfile == -1 ) { 258 tmpfilefd = mkstemp( tmpname ); 259 if ( tmpfilefd == -1 ) { 238 260 perror( "CFA Translator error: cpp level, mkstemp" ); 239 261 exit( EXIT_FAILURE ); … … 241 263 242 264 #ifdef __DEBUG_H__ 243 cerr << "tmpname:" << tmpname << " tmpfile :" << tmpfile<< endl;265 cerr << "tmpname:" << tmpname << " tmpfilefd:" << tmpfilefd << endl; 244 266 #endif // __DEBUG_H__ 245 267 … … 280 302 281 303 if ( WIFSIGNALED(code) != 0 ) { // child failed ? 282 unlink( tmpname );// remove tmpname304 rmtmpfile(); // remove tmpname 283 305 cerr << "CFA Translator error: cpp failed with signal " << WTERMSIG(code) << endl; 284 306 exit( EXIT_FAILURE ); … … 286 308 287 309 if ( WEXITSTATUS(code) != 0 ) { // child error ? 288 unlink( tmpname );// remove tmpname310 rmtmpfile(); // remove tmpname 289 311 exit( WEXITSTATUS( code ) ); // do not continue 290 312 } // if … … 293 315 // output. Otherwise, run the cfa-cpp preprocessor on the temporary file and save the result into the output file. 294 316 295 if ( CFA_flag || fork() == 0 ) { // conditional fork ?317 if ( fork() == 0 ) { // child runs CFA 296 318 uargs[0] = ( *new string( bprefix + "/cfa-cpp" ) ).c_str(); 297 319 … … 330 352 331 353 // Must unlink here because file must exist across execvp. 332 if ( unlink( tmpname ) == -1 ) { 333 perror( "CFA Translator error: cpp level, unlink" ); 334 exit( EXIT_FAILURE ); 335 } // if 354 rmtmpfile(); // remove tmpname 336 355 337 356 if ( WIFSIGNALED(code) ) { // child failed ? -
driver/cpp.cc
rad17ba6a rbdd516a 8 8 // Created On : Thu Aug 29 12:24:06 2002 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Sat Dec 6 08:31:49 201411 // Update Count : 5 110 // Last Modified On : Tue Apr 21 07:23:38 2015 11 // Update Count : 52 12 12 // 13 13 … … 218 218 if ( cpp_flag && CFA_flag ) { 219 219 cerr << argv[0] << " Error cannot use -E and -CFA flags together." << endl; 220 exit( -1);220 exit( EXIT_FAILURE ); 221 221 } // if 222 222 … … 234 234 if ( freopen( cpp_out.c_str(), "w", stdout ) == NULL ) { // redirect stdout if not -E 235 235 cerr << argv[0] << ": Error can't write to " << cpp_out << endl; 236 exit( -1);236 exit( EXIT_FAILURE ); 237 237 } // if 238 238 … … 274 274 execvp( args[0], (char *const *)args ); // should not return 275 275 perror( "CFA translator error: cpp level, exec" ); 276 exit( -1);276 exit( EXIT_FAILURE ); 277 277 } // if 278 278 … … 282 282 if ( freopen( tmpfile, "w", stdout ) == NULL) { // redirect output to tmpfile 283 283 cerr << argv[0] << ": Error can't write to " << tmpfile << endl; 284 exit( -1);284 exit( EXIT_FAILURE ); 285 285 } // if 286 286 … … 308 308 execvp( args[0], (char *const *)args ); // should not return 309 309 perror( "CFA translator error: cpp level, exec" ); 310 exit( -1);310 exit( EXIT_FAILURE ); 311 311 } // if 312 312 … … 316 316 unlink( tmpfile ); 317 317 cerr << "CFA translator error: cpp failed with signal " << WTERMSIG(code) << endl; 318 exit( -1);318 exit( EXIT_FAILURE ); 319 319 } // if 320 320 … … 357 357 wait( &code ); // wait for child to finish 358 358 359 unlink( tmpfile ); 359 if ( unlink( tmpfile ) == -1 ) { 360 cerr << "CFA translator error: cfa-cpp failed " << errno << " to remove temporary file \"" << tmpfile << "\"" << endl; 361 exit( EXIT_FAILURE ); 362 } // if 360 363 361 364 if ( WIFSIGNALED(code) != 0 ) { // child completed successfully ? 362 365 cerr << "CFA translator error: cfa-cpp failed with signal " << WTERMSIG(code) << endl; 363 exit( -1);366 exit( EXIT_FAILURE ); 364 367 } // if 365 368 366 369 if ( CFA_flag ) { // -CFA flag ? 367 exit( -1 );// tell gcc not to go any further370 exit( EXIT_FAILURE ); // tell gcc not to go any further 368 371 } else { 369 372 exit( WEXITSTATUS(code) ); -
libcfa/prelude.cf
rad17ba6a rbdd516a 8 8 // Created On : Sat Nov 29 07:23:41 2014 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Mon Jan 19 22:20:57201511 // Update Count : 5110 // Last Modified On : Wed Mar 18 11:36:59 2015 11 // Update Count : 69 12 12 // 13 13 … … 35 35 // ------------------------------------------------------------ 36 36 37 _Bool ?++( _Bool * ), ?--( _Bool * ); 38 signed int ?++( signed int * ), ?--( signed int * ); 39 unsigned int ?++( unsigned int * ), ?--( unsigned int * ); 40 signed long int ?++( signed long int * ), ?--( signed long int * ); 41 unsigned long int ?++( unsigned long int * ), ?--( unsigned long int * ); 42 signed long long int ?++( signed long long int * ), ?--( signed long long int * ); 43 unsigned long long int ?++( unsigned long long int * ), ?--( unsigned long long int * ); 44 float ?++( float * ), ?--( float * ); 45 double ?++( double * ), ?--( double * ); 46 long double ?++( long double * ), ?--( long double * ); 47 float _Complex ?++( float _Complex * ), ?--( float _Complex * ); 48 double _Complex ?++( double _Complex * ), ?--( double _Complex * ); 49 long double _Complex ?++( long double _Complex * ), ?--( long double _Complex * ); 37 _Bool ?++( _Bool * ), ?++( volatile _Bool * ); 38 _Bool ?--( _Bool * ), ?--( volatile _Bool * ); 39 unsigned char ?++( unsigned char * ), ?++( volatile unsigned char * ); 40 signed int ?++( signed int * ), ?++( volatile signed int * ); 41 signed int ?--( signed int * ), ?--( volatile signed int * ); 42 unsigned int ?++( unsigned int * ), ?++( volatile unsigned int * ); 43 unsigned int ?--( unsigned int * ), ?--( volatile unsigned int * ); 44 signed long int ?++( signed long int * ), ?++( volatile signed long int * ); 45 signed long int ?--( signed long int * ), ?--( volatile signed long int * ); 46 unsigned long int ?++( unsigned long int * ), ?++( volatile unsigned long int * ); 47 unsigned long int ?--( unsigned long int * ), ?--( volatile unsigned long int * ); 48 signed long long int ?++( signed long long int * ), ?++( volatile signed long long int * ); 49 signed long long int ?--( signed long long int * ), ?--( volatile signed long long int * ); 50 unsigned long long int ?++( unsigned long long int * ), ?++( volatile unsigned long long int * ); 51 unsigned long long int ?--( unsigned long long int * ), ?--( volatile unsigned long long int * ); 52 float ?++( float * ), ?++( volatile float * ); 53 float ?--( float * ), ?--( volatile float * ); 54 double ?++( double * ), ?++( volatile double * ); 55 double ?--( double * ), ?--( volatile double * ); 56 long double ?++( long double * ), ?++( volatile long double * ); 57 long double ?--( long double * ), ?--( volatile long double * ); 58 float _Complex ?++( float _Complex * ), ?++( volatile float _Complex * ); 59 float _Complex ?--( float _Complex * ), ?--( volatile float _Complex * ); 60 double _Complex ?++( double _Complex * ), ?++( volatile double _Complex * ); 61 double _Complex ?--( double _Complex * ), ?--( volatile double _Complex * ); 62 long double _Complex ?++( long double _Complex * ), ?++( volatile long double _Complex * ); 63 long double _Complex ?--( long double _Complex * ), ?--( volatile long double _Complex * ); 50 64 51 65 forall( type T ) T * ?++( T ** ); … … 203 217 signed int ?<?( _Bool, _Bool ), ?<=?( _Bool, _Bool ), 204 218 ?>?( _Bool, _Bool ), ?>=?( _Bool, _Bool ); 219 signed int ?<?( unsigned char, unsigned char ), ?<=?( unsigned char, unsigned char ), 220 ?>?( unsigned char, unsigned char ), ?>=?( unsigned char, unsigned char ); 205 221 signed int ?<?( signed int, signed int ), ?<=?( signed int, signed int ), 206 222 ?>?( signed int, signed int ), ?>=?( signed int, signed int ); -
libcfa/prototypes.awk
rad17ba6a rbdd516a 1 # http://llvm.org/svn/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def 2 1 3 BEGIN { 2 4 FS = "(" -
translator/CodeGen/GenType.cc
rad17ba6a rbdd516a 74 74 if ( qualifiers.isRestrict ) { 75 75 os << "__restrict "; 76 } // if 77 if ( qualifiers.isAtomic ) { 78 os << "_Atomic "; 76 79 } // if 77 80 if ( isVarLen ) { … … 180 183 typeString = "__restrict " + typeString; 181 184 } // if 185 if ( type->get_isAtomic() ) { 186 typeString = "_Atomic " + typeString; 187 } // if 182 188 } 183 189 } // namespace CodeGen -
translator/GenPoly/Box.cc
rad17ba6a rbdd516a 772 772 Expression *Pass1::mutate( AddressExpr *addrExpr ) { 773 773 assert( !addrExpr->get_arg()->get_results().empty() ); 774 mutateExpression( addrExpr->get_arg() );774 addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) ); 775 775 if ( isPolyType( addrExpr->get_arg()->get_results().front(), env, scopeTyVars ) ) { 776 776 Expression *ret = addrExpr->get_arg(); -
translator/GenPoly/ScrubTyVars.cc
rad17ba6a rbdd516a 4 4 #include "SynTree/Mutator.h" 5 5 #include "SynTree/Type.h" 6 #include "SynTree/Expression.h" 6 7 7 8 8 9 namespace GenPoly { 10 Type * ScrubTyVars::mutate( TypeInstType *typeInst ) { 11 TyVarMap::const_iterator tyVar = tyVars.find( typeInst->get_name() ); 12 if ( doAll || tyVar != tyVars.end() ) { 13 switch( tyVar->second ) { 14 case TypeDecl::Any: 15 case TypeDecl::Dtype: 16 { 17 PointerType *ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) ); 18 delete typeInst; 19 return ret; 20 } 21 case TypeDecl::Ftype: 22 delete typeInst; 23 return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ); 24 } 25 } 26 return typeInst; 27 } 9 28 10 Type* 11 ScrubTyVars::mutate( TypeInstType *typeInst ) 12 { 13 TyVarMap::const_iterator tyVar = tyVars.find( typeInst->get_name() ); 14 if( doAll || tyVar != tyVars.end() ) { 15 switch( tyVar->second ) { 16 case TypeDecl::Any: 17 case TypeDecl::Dtype: 18 { 19 PointerType *ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) ); 20 delete typeInst; 21 return ret; 29 Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) { 30 // sizeof( T ) => T parameter, which is the size of T 31 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( szeof->get_type() ) ) { 32 Expression *expr = new NameExpr( typeInst->get_name() ); 33 return expr; 34 } else { 35 return Mutator::mutate( szeof ); 36 } 22 37 } 23 24 case TypeDecl::Ftype: 25 delete typeInst; 26 return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ); 38 39 Type * ScrubTyVars::mutate( PointerType *pointer ) { 40 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( pointer->get_base() ) ) { 41 if ( doAll || tyVars.find( typeInst->get_name() ) != tyVars.end() ) { 42 Type *ret = mutate( typeInst ); 43 ret->get_qualifiers() += pointer->get_qualifiers(); 44 pointer->set_base( 0 ); 45 delete pointer; 46 return ret; 47 } 48 } 49 return Mutator::mutate( pointer ); 27 50 } 28 }29 return typeInst;30 }31 32 Type*33 ScrubTyVars::mutate( PointerType *pointer )34 {35 if( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( pointer->get_base() ) ) {36 if( doAll || tyVars.find( typeInst->get_name() ) != tyVars.end() ) {37 Type *ret = mutate( typeInst );38 /// std::cout << "pointer is ";39 /// pointer->print( std::cout );40 /// std::cout << std::endl << "ret is ";41 /// ret->print( std::cout );42 /// std::cout << std::endl;43 ret->get_qualifiers() += pointer->get_qualifiers();44 pointer->set_base( 0 );45 delete pointer;46 return ret;47 }48 }49 return Mutator::mutate( pointer );50 }51 52 51 } // namespace GenPoly -
translator/GenPoly/ScrubTyVars.h
rad17ba6a rbdd516a 1 /*2 * This file is part of the Cforall project3 *4 * $Id: ScrubTyVars.h,v 1.4 2005/08/29 20:14:13 rcbilson Exp $5 *6 */7 8 1 #ifndef GENPOLY_SCRUBTYVARS_H 9 2 #define GENPOLY_SCRUBTYVARS_H … … 15 8 16 9 namespace GenPoly { 10 class ScrubTyVars : public Mutator { 11 public: 12 ScrubTyVars( bool doAll, const TyVarMap &tyVars ): doAll( doAll ), tyVars( tyVars ) {} 13 14 template< typename SynTreeClass > 15 static SynTreeClass *scrub( SynTreeClass *target, const TyVarMap &tyVars ); 16 template< typename SynTreeClass > 17 static SynTreeClass *scrub( SynTreeClass *target ); 18 19 virtual Type* mutate( TypeInstType *typeInst ); 20 Expression* mutate( SizeofExpr *szeof ); 21 virtual Type* mutate( PointerType *pointer ); 22 private: 23 bool doAll; 24 const TyVarMap &tyVars; 25 }; 17 26 18 class ScrubTyVars : public Mutator 19 { 20 public: 21 ScrubTyVars( bool doAll, const TyVarMap &tyVars ): doAll( doAll ), tyVars( tyVars ) {} 22 23 template< typename SynTreeClass > 24 static SynTreeClass *scrub( SynTreeClass *target, const TyVarMap &tyVars ); 25 template< typename SynTreeClass > 26 static SynTreeClass *scrub( SynTreeClass *target ); 27 28 virtual Type* mutate( TypeInstType *typeInst ); 29 virtual Type* mutate( PointerType *pointer ); 27 /* static class method */ 28 template< typename SynTreeClass > 29 SynTreeClass * ScrubTyVars::scrub( SynTreeClass *target, const TyVarMap &tyVars ) { 30 ScrubTyVars scrubber( false, tyVars ); 31 return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) ); 32 } 30 33 31 private: 32 bool doAll; 33 const TyVarMap &tyVars; 34 }; 35 36 /* static class method */ 37 template< typename SynTreeClass > 38 SynTreeClass * 39 ScrubTyVars::scrub( SynTreeClass *target, const TyVarMap &tyVars ) 40 { 41 ScrubTyVars scrubber( false, tyVars ); 42 return static_cast< SynTreeClass* >( target->acceptMutator( scrubber ) ); 43 } 44 45 /* static class method */ 46 template< typename SynTreeClass > 47 SynTreeClass * 48 ScrubTyVars::scrub( SynTreeClass *target ) 49 { 50 TyVarMap tyVars; 51 ScrubTyVars scrubber( true, tyVars ); 52 return static_cast< SynTreeClass* >( target->acceptMutator( scrubber ) ); 53 } 54 34 /* static class method */ 35 template< typename SynTreeClass > 36 SynTreeClass * ScrubTyVars::scrub( SynTreeClass *target ) { 37 TyVarMap tyVars; 38 ScrubTyVars scrubber( true, tyVars ); 39 return static_cast< SynTreeClass* >( target->acceptMutator( scrubber ) ); 40 } 55 41 } // namespace GenPoly 56 42 57 #endif / * #ifndef GENPOLY_SCRUBTYVARS_H */43 #endif // GENPOLY_SCRUBTYVARS_H -
translator/InitTweak/InitModel.h
rad17ba6a rbdd516a 12 12 13 13 namespace InitTweak { 14 class InitModelBuilder : public AssociationBuilder, public Visitor { 15 public: 16 InitModelBuilder( Declaration * ); 17 ~InitModelBuilder(); 14 18 15 class InitModelBuilder : public AssociationBuilder, public Visitor { 16 public: 17 InitModelBuilder( Declaration * ); 18 ~InitModelBuilder(); 19 virtual Association *grab_assoc() { taken = true; return building; } 20 virtual Association *get_assoc() { return building; } 21 void set_assoc( Association *newAssoc ) { building = newAssoc; } 19 22 20 virtual Association *grab_assoc() { taken = true; return building; } 21 virtual Association *get_assoc() { return building; } 22 void set_assoc( Association *newAssoc ) { building = newAssoc; } 23 void init(); 24 static int interpretDimension( Expression *exp ) { 25 ConstantFolder folder( exp ); 26 try { 27 return folder.get_constant(); 28 } catch (...) { 29 throw SemanticError("Invalid array dimension"); 30 } 31 } 23 32 24 void init(); 25 static int interpretDimension( Expression *exp ) { 26 ConstantFolder folder( exp ); 27 try { 28 return folder.get_constant(); 29 } catch (...) { 30 throw SemanticError("Invalid array dimension"); 31 } 32 } 33 // types 34 virtual void visit( ArrayType * ); 35 virtual void visit( StructInstType * ); 36 virtual void visit( UnionInstType * ); 37 virtual void visit( EnumInstType * ); 38 virtual void visit( ContextInstType * ) { throw 0; } 39 virtual void visit( TypeInstType * ) { throw 0; } 40 // virtual void visit( TupleType *tupleType ); 41 // declarations 42 virtual void visit( StructDecl *); 43 virtual void visit( UnionDecl *); 44 virtual void visit( EnumDecl *); 45 private: 46 class ConstantFolder : public Visitor { 47 public: 48 ConstantFolder( Expression *_expr = 0 ): expr(_expr) {} 49 int get_constant() throw() { expr->accept( *this ); return value; } 50 void set_constant( Expression *newExp ) { expr = newExp; } 51 // Visitor interface 52 void visit( Expression * ) { throw 0; } 53 void visit( NameExpr * ) { throw 0; } 54 void visit( CastExpr * ) { throw 0; } 55 void visit( UntypedMemberExpr * ) { throw 0; } 56 void visit( VariableExpr * ) { throw 0; } 57 void visit( ConstantExpr * ); 58 void visit( SizeofExpr * ) { throw 0; } 59 void visit( AttrExpr * ) { throw 0; } 60 void visit( LogicalExpr * ) { throw 0; } 61 void visit( ConditionalExpr * ) { throw 0; } 62 void visit( CommaExpr * ) { throw 0; } 63 private: 64 Expression *expr; 65 int value; 66 }; 33 67 34 // types 35 virtual void visit( ArrayType * ); 36 virtual void visit( StructInstType * ); 37 virtual void visit( UnionInstType * ); 38 virtual void visit( EnumInstType * ); 39 virtual void visit( ContextInstType * ) { throw 0; } 40 virtual void visit( TypeInstType * ) { throw 0; } 41 // virtual void visit( TupleType *tupleType ); 42 // declarations 43 virtual void visit( StructDecl *); 44 virtual void visit( UnionDecl *); 45 virtual void visit( EnumDecl *); 46 47 private: 48 class ConstantFolder : public Visitor { 49 public: 50 ConstantFolder( Expression *_expr = 0 ): expr(_expr) {} 51 int get_constant() throw() { expr->accept( *this ); return value; } 52 void set_constant( Expression *newExp ) { expr = newExp; } 53 // Visitor interface 54 void visit( Expression * ) { throw 0; } 55 void visit( NameExpr * ) { throw 0; } 56 void visit( CastExpr * ) { throw 0; } 57 void visit( UntypedMemberExpr * ) { throw 0; } 58 void visit( VariableExpr * ) { throw 0; } 59 void visit( ConstantExpr * ); 60 void visit( SizeofExpr * ) { throw 0; } 61 void visit( AttrExpr * ) { throw 0; } 62 void visit( LogicalExpr * ) { throw 0; } 63 void visit( ConditionalExpr * ) { throw 0; } 64 void visit( CommaExpr * ) { throw 0; } 65 private: 66 Expression *expr; 67 int value; 68 bool taken; 69 Declaration *decl; // ? 70 Association *building; 68 71 }; 69 72 70 bool taken; 71 Declaration *decl; // ? 72 Association *building; 73 }; 73 class InitModelFiller : public AssociationFiller, public Visitor { 74 public: 75 InitModelFiller( Association *, Initializer *, bool _topLevel = false ); 76 ~InitModelFiller() { /* pointers in here are not owned by object (never created by object either) */ } 77 virtual Association *get_assoc() { return model; } 78 virtual void set_assoc( Association *newAssoc ) { model = newAssoc; } 74 79 75 class InitModelFiller : public AssociationFiller, public Visitor { 76 public: 77 InitModelFiller( Association *, Initializer *, bool _topLevel = false ); 78 ~InitModelFiller() { /* pointers in here are not owned by object (never created by object either) */ } 79 virtual Association *get_assoc() { return model; } 80 virtual void set_assoc( Association *newAssoc ) { model = newAssoc; } 80 void init(); 81 // Visitor interface 82 virtual void visit( SingleInit *singleInit ); 83 virtual void visit( ListInit *listInit ); 84 private: 85 Association *model; 86 Initializer *orgInit; 87 bool topLevel; 88 long int next; 89 }; 81 90 82 void init();83 // Visitor interface84 virtual void visit( MemberInit *memberInit ) { throw 0;}85 virtual void visit( ElementInit *elementInit ) { throw 0;}86 virtual void visit( SingleInit *singleInit ); 87 virtual void visit( ListInit *listInit ); 91 class InitUnspooler : public AssociationVisitor { 92 public: 93 InitUnspooler() : init(0), taken( false ) {} 94 virtual ~InitUnspooler() { if (!taken && (init != 0)) { delete init; init = 0; } } 95 Initializer *get_initializer() { return init; } 96 Initializer *grab_initializer() { taken = true; return init; } 88 97 89 private: 90 Association *model; 91 Initializer *orgInit; 92 bool topLevel; 93 long int next; 94 }; 95 96 class InitUnspooler : public AssociationVisitor { 97 public: 98 InitUnspooler() : init(0), taken( false ) {} 99 virtual ~InitUnspooler() { if (!taken && (init != 0)) { delete init; init = 0; } } 100 Initializer *get_initializer() { return init; } 101 Initializer *grab_initializer() { taken = true; return init; } 102 103 virtual void visit( SingleName * ); 104 virtual void visit( PointAssociation * ); 105 virtual void visit( RangeAssociation * ) { std::cerr << "InitUnspooler - In a range assoc" << std::endl; return; } 106 107 private: 108 Initializer *init; 109 bool taken; 110 }; 98 virtual void visit( SingleName * ); 99 virtual void visit( PointAssociation * ); 100 virtual void visit( RangeAssociation * ) { std::cerr << "InitUnspooler - In a range assoc" << std::endl; return; } 101 private: 102 Initializer *init; 103 bool taken; 104 }; 111 105 112 106 } // namespace InitTweak 113 107 114 #endif // #define_INITTWEAK_MODEL_H_108 #endif // _INITTWEAK_MODEL_H_ 115 109 116 110 /* -
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 -
translator/ResolvExpr/AlternativeFinder.cc
rad17ba6a rbdd516a 756 756 alternatives.push_back( Alternative( sizeofExpr->clone(), env, Cost::zero ) ); 757 757 } else { 758 // find all alternatives for the argument to sizeof 758 759 AlternativeFinder finder( indexer, env ); 759 760 finder.find( sizeofExpr->get_expr() ); 760 if ( finder.alternatives.size() != 1 ) { 761 // find the lowest cost alternative among the alternatives, otherwise ambiguous 762 AltList winners; 763 findMinCost( finder.alternatives.begin(), finder.alternatives.end(), back_inserter( winners ) ); 764 if ( winners.size() != 1 ) { 761 765 throw SemanticError( "Ambiguous expression in sizeof operand: ", sizeofExpr->get_expr() ); 762 766 } 763 Alternative &choice = finder.alternatives.front(); 767 // return the lowest cost alternative for the argument 768 Alternative &choice = winners.front(); 764 769 alternatives.push_back( Alternative( new SizeofExpr( choice.expr->clone() ), choice.env, Cost::zero ) ); 765 770 } -
translator/ResolvExpr/Resolver.cc
rad17ba6a rbdd516a 44 44 acceptAll( translationUnit, resolver ); 45 45 #if 0 46 resolver.print( cerr ); 46 47 for ( std::list< Declaration * >::iterator i = translationUnit.begin(); i != translationUnit.end(); ++i ) { 47 48 (*i)->print( std::cerr ); … … 241 242 void Resolver::visit( SingleInit *singleInit ) { 242 243 if ( singleInit->get_value() ) { 244 #if 0 245 if (NameExpr * ne = dynamic_cast<NameExpr*>(singleInit->get_value())) { 246 string n = ne->get_name(); 247 if (n == "0") { 248 initContext = new BasicType(Type::Qualifiers(), 249 BasicType::SignedInt); 250 } else { 251 DeclarationWithType * decl = lookupId(n); 252 initContext = decl->get_type(); 253 } 254 } else if (ConstantExpr * e = 255 dynamic_cast<ConstantExpr*>(singleInit->get_value())) { 256 Constant *c = e->get_constant(); 257 initContext = c->get_type(); 258 } else { 259 assert(0); 260 } 261 #endif 243 262 CastExpr *castExpr = new CastExpr( singleInit->get_value(), initContext->clone() ); 244 263 Expression *newExpr = findSingleExpression( castExpr, *this ); … … 250 269 251 270 void Resolver::visit( ListInit *listInit ) { 271 Visitor::visit(listInit); 272 #if 0 252 273 if ( ArrayType *at = dynamic_cast<ArrayType*>(initContext) ) { 253 initContext = at->get_base(); 254 Visitor::visit( listInit ); 274 std::list<Initializer *>::iterator iter( listInit->begin_initializers() ); 275 for ( ; iter != listInit->end_initializers(); ++iter ) { 276 initContext = at->get_base(); 277 (*iter)->accept( *this ); 278 } // for 255 279 } else if ( StructInstType *st = dynamic_cast<StructInstType*>(initContext) ) { 256 280 StructDecl *baseStruct = st->get_baseStruct(); … … 295 319 (*listInit->begin_initializers())->accept( *this ); 296 320 } // if 321 #endif 297 322 } 298 323 } // namespace ResolvExpr -
translator/SymTab/IdTable.cc
rad17ba6a rbdd516a 82 82 } 83 83 } 84 for( InnerTableType::const_iterator i = declTable.begin(); i != declTable.end(); ++i ) { 84 // ensure the set of routines with C linkage cannot be overloaded 85 for( InnerTableType::iterator i = declTable.begin(); i != declTable.end(); ++i ) { 85 86 if( !i->second.empty() && i->second.top().first->get_linkage() == LinkageSpec::C && declTable.size() > 1 ) { 86 throw SemanticError( "invalid overload of C function ", i->second.top().first ); 87 InnerTableType::iterator j = i; 88 for( j++; j != declTable.end(); ++j ) { 89 if( !j->second.empty() && j->second.top().first->get_linkage() == LinkageSpec::C ) { 90 throw SemanticError( "invalid overload of C function " ); 91 } 92 } 87 93 } 88 94 } … … 103 109 } 104 110 111 DeclarationWithType* IdTable::lookupId( const std::string &id) const { 112 DeclarationWithType* result = 0; 113 int depth = -1; 114 115 OuterTableType::const_iterator outer = table.find( id ); 116 if( outer == table.end() ) return 0; 117 const InnerTableType &declTable = outer->second; 118 for( InnerTableType::const_iterator it = declTable.begin(); it != declTable.end(); ++it ) { 119 const std::stack< DeclEntry >& entry = it->second; 120 if( !entry.empty() && entry.top().second > depth ) { 121 result = entry.top().first; 122 depth = entry.top().second; 123 } 124 } 125 return result; 126 } 127 105 128 void 106 129 IdTable::dump( std::ostream &os ) const 107 130 { 131 for( OuterTableType::const_iterator outer = table.begin(); outer != table.end(); ++outer ) { 132 for( InnerTableType::const_iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) { 133 #if 0 134 const std::stack< DeclEntry >& entry = inner->second; 135 if( !entry.empty() ) { // && entry.top().second == scopeLevel ) { 136 os << outer->first << " (" << inner->first << ") (" << entry.top().second << ")" << std::endl; 137 } else { 138 os << outer->first << " (" << inner->first << ") ( entry-empty)" << std::endl; 139 } 140 #endif 141 #if 0 142 std::stack<DeclEntry> stack = inner->second; 143 os << "dumping a stack" << std::endl; 144 while (!stack.empty()) { 145 DeclEntry d = stack.top(); 146 os << outer->first << " (" << inner->first << ") (" << d.second << ") " << std::endl; 147 stack.pop(); 148 } 149 #endif 150 } 151 } 152 #if 0 108 153 for( OuterTableType::const_iterator outer = table.begin(); outer != table.end(); ++outer ) { 109 154 for( InnerTableType::const_iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) { … … 114 159 } 115 160 } 161 #endif 116 162 } 117 163 -
translator/SymTab/IdTable.h
rad17ba6a rbdd516a 1 /*2 * This file is part of the Cforall project3 *4 * $Id: IdTable.h,v 1.4 2005/08/29 20:14:17 rcbilson Exp $5 *6 */7 8 1 #ifndef SYMTAB_IDTABLE_H 9 2 #define SYMTAB_IDTABLE_H … … 17 10 18 11 namespace SymTab { 12 class IdTable { 13 public: 14 IdTable(); 15 16 void enterScope(); 17 void leaveScope(); 18 void addDecl( DeclarationWithType *decl ); 19 void lookupId( const std::string &id, std::list< DeclarationWithType* >& decls ) const; 20 DeclarationWithType* lookupId( const std::string &id) const; 21 22 void dump( std::ostream &os ) const; // debugging 19 23 20 class IdTable 21 { 22 public: 23 IdTable(); 24 25 void enterScope(); 26 void leaveScope(); 27 void addDecl( DeclarationWithType *decl ); 28 void lookupId( const std::string &id, std::list< DeclarationWithType* >& decls ) const; 29 30 void dump( std::ostream &os ) const; // debugging 24 private: 25 typedef std::pair< DeclarationWithType*, int > DeclEntry; 26 typedef std::map< std::string, std::stack< DeclEntry > > InnerTableType; 27 typedef std::map< std::string, InnerTableType > OuterTableType; 31 28 32 private: 33 typedef std::pair< DeclarationWithType*, int > DeclEntry; 34 typedef std::map< std::string, std::stack< DeclEntry > > InnerTableType; 35 typedef std::map< std::string, InnerTableType > OuterTableType; 36 37 OuterTableType table; 38 int scopeLevel; 39 }; 40 29 OuterTableType table; 30 int scopeLevel; 31 }; 41 32 } // namespace SymTab 42 33 43 #endif / * #ifndef SYMTAB_IDTABLE_H */34 #endif // SYMTAB_IDTABLE_H -
translator/SymTab/Indexer.cc
rad17ba6a rbdd516a 162 162 } 163 163 164 DeclarationWithType* Indexer::lookupId( const std::string &id) const { 165 return idTable.lookupId(id); 166 } 167 164 168 NamedTypeDecl *Indexer::lookupType( const std::string &id ) const { 165 169 return typeTable.lookup( id ); … … 216 220 217 221 void Indexer::print( std::ostream &os, int indent ) const { 222 using std::cerr; 223 using std::endl; 224 225 cerr << "===idTable===" << endl; 226 idTable.dump( os ); 227 cerr << "===typeTable===" << endl; 228 typeTable.dump( os ); 229 cerr << "===structTable===" << endl; 230 structTable.dump( os ); 231 cerr << "===enumTable===" << endl; 232 enumTable.dump( os ); 233 cerr << "===unionTable===" << endl; 234 unionTable.dump( os ); 235 cerr << "===contextTable===" << endl; 236 contextTable.dump( os ); 237 #if 0 218 238 idTable.dump( os ); 219 239 typeTable.dump( os ); … … 222 242 unionTable.dump( os ); 223 243 contextTable.dump( os ); 244 #endif 224 245 } 225 246 } // namespace SymTab -
translator/SymTab/Indexer.h
rad17ba6a rbdd516a 39 39 40 40 void lookupId( const std::string &id, std::list< DeclarationWithType* >& ) const; 41 DeclarationWithType* lookupId( const std::string &id) const; 41 42 NamedTypeDecl *lookupType( const std::string &id ) const; 42 43 StructDecl *lookupStruct( const std::string &id ) const; … … 58 59 } // namespace SymTab 59 60 60 #endif / * #ifndef SYMTAB_INDEXER_H */61 #endif // SYMTAB_INDEXER_H -
translator/SymTab/Mangler.cc
rad17ba6a rbdd516a 226 226 mangleName << "L"; 227 227 } 228 if ( type->get_isAtomic() ) { 229 mangleName << "A"; 230 } 228 231 } 229 232 } // SymTab -
translator/SymTab/Validate.cc
rad17ba6a rbdd516a 278 278 ObjectDecl *obj = dynamic_cast< ObjectDecl * >( *i ); 279 279 assert( obj ); 280 obj->set_type( new EnumInstType( Type::Qualifiers( true, false, false, false ), enumDecl->get_name() ) );280 obj->set_type( new EnumInstType( Type::Qualifiers( true, false, false, false, false ), enumDecl->get_name() ) ); 281 281 } // for 282 282 Parent::visit( enumDecl ); -
translator/SynTree/Initializer.cc
rad17ba6a rbdd516a 39 39 } 40 40 41 MemberInit::MemberInit( Expression *_value, std::string _member ) : member ( _member ), value ( _value ) {}42 43 MemberInit::~MemberInit() {}44 45 MemberInit * MemberInit::clone() const {46 return new MemberInit( *this );47 }48 49 void MemberInit::print( std::ostream &os, int indent ) {50 os << "Member Initializer";51 value->print( os, indent+2 );52 }53 54 41 ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators ) 55 42 : initializers( _initializers ), designators( _designators ) { -
translator/SynTree/Initializer.h
rad17ba6a rbdd516a 61 61 }; 62 62 63 // MemberInit represents an initializer for a member of an aggregate object (e.g., struct q { int a; } x = { a : 4 } )64 class MemberInit : public Initializer {65 public:66 MemberInit( Expression *value, std::string member = std::string("") );67 virtual ~MemberInit();68 69 std::string get_member() { return member; }70 void set_member( std::string newValue ) { member = newValue; }71 Expression *get_value() { return value; }72 void set_value( Expression *newValue ) { value = newValue; }73 74 virtual MemberInit *clone() const;75 virtual void accept( Visitor &v ) { v.visit( this ); }76 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }77 virtual void print( std::ostream &os, int indent = 0 );78 private:79 std::string member;80 Expression *value;81 };82 83 // ElementInit represents an initializer of an element of an array (e.g., [10] int x = { [7] : 4 }84 class ElementInit : public Initializer {85 public:86 ElementInit( Expression *value );87 virtual ~ElementInit();88 89 int get_index() { return index; }90 void set_index( int newValue ) { index = newValue; }91 Expression *get_value() { return value; }92 void set_value( Expression *newValue ) { value = newValue; }93 94 virtual ElementInit *clone() const;95 virtual void accept( Visitor &v ) { v.visit( this ); }96 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }97 virtual void print( std::ostream &os, int indent = 0 );98 private:99 int index;100 Expression *value;101 };102 103 63 // ListInit represents an initializer that is composed recursively of a list of initializers; this is used to initialize 104 64 // an array or aggregate -
translator/SynTree/Mutator.cc
rad17ba6a rbdd516a 368 368 } 369 369 370 Initializer *Mutator::mutate( MemberInit *memberInit ) {371 memberInit->set_value( memberInit->get_value()->acceptMutator( *this ) );372 return memberInit;373 }374 375 Initializer *Mutator::mutate( ElementInit *elementInit ) {376 elementInit->set_value( elementInit->get_value()->acceptMutator( *this ) );377 return elementInit;378 }379 380 370 Initializer *Mutator::mutate( SingleInit *singleInit ) { 381 371 singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) ); -
translator/SynTree/Mutator.h
rad17ba6a rbdd516a 72 72 virtual Type* mutate( AttrType *attrType ); 73 73 74 virtual Initializer* mutate( MemberInit *memberInit );75 virtual Initializer* mutate( ElementInit *elementInit );76 74 virtual Initializer* mutate( SingleInit *singleInit ); 77 75 virtual Initializer* mutate( ListInit *listInit ); -
translator/SynTree/SynTree.h
rad17ba6a rbdd516a 89 89 90 90 class Initializer; 91 class MemberInit;92 class ElementInit;93 91 class SingleInit; 94 92 class ListInit; -
translator/SynTree/Type.cc
rad17ba6a rbdd516a 57 57 os << "lvalue "; 58 58 } // if 59 if ( tq.isAtomic ) { 60 os << "_Atomic "; 61 } // if 59 62 } -
translator/SynTree/Type.h
rad17ba6a rbdd516a 10 10 public: 11 11 struct Qualifiers { 12 Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ) {}13 Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue ): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue) {}12 Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ), isAtomic( false ) {} 13 Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue, bool isAtomic ): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ), isAtomic( isAtomic ) {} 14 14 15 15 Qualifiers &operator+=( const Qualifiers &other ); … … 27 27 bool isRestrict; 28 28 bool isLvalue; 29 bool isAtomic; 29 30 }; 30 31 … … 38 39 bool get_isRestrict() { return tq.isRestrict; } 39 40 bool get_isLvalue() { return tq.isLvalue; } 41 bool get_isAtomic() { return tq.isAtomic; } 40 42 void set_isConst( bool newValue ) { tq.isConst = newValue; } 41 43 void set_iisVolatile( bool newValue ) { tq.isVolatile = newValue; } 42 44 void set_isRestrict( bool newValue ) { tq.isRestrict = newValue; } 43 45 void set_isLvalue( bool newValue ) { tq.isLvalue = newValue; } 46 void set_isAtomic( bool newValue ) { tq.isAtomic = newValue; } 44 47 std::list<TypeDecl*>& get_forall() { return forall; } 45 48 … … 380 383 isRestrict |= other.isRestrict; 381 384 isLvalue |= other.isLvalue; 385 isAtomic |= other.isAtomic; 382 386 return *this; 383 387 } … … 387 391 if ( other.isVolatile ) isVolatile = 0; 388 392 if ( other.isRestrict ) isRestrict = 0; 393 if ( other.isAtomic ) isAtomic = 0; 389 394 return *this; 390 395 } … … 398 403 inline bool Type::Qualifiers::operator==( const Qualifiers &other ) { 399 404 return isConst == other.isConst 400 && isVolatile == other.isVolatile 401 && isRestrict == other.isRestrict; 402 /// && isLvalue == other.isLvalue; 405 && isVolatile == other.isVolatile 406 && isRestrict == other.isRestrict 407 // && isLvalue == other.isLvalue 408 && isAtomic == other.isAtomic; 403 409 } 404 410 … … 406 412 return isConst != other.isConst 407 413 || isVolatile != other.isVolatile 408 || isRestrict != other.isRestrict; 409 /// && isLvalue == other.isLvalue; 414 || isRestrict != other.isRestrict 415 // || isLvalue != other.isLvalue 416 || isAtomic != other.isAtomic; 410 417 } 411 418 … … 413 420 return isConst <= other.isConst 414 421 && isVolatile <= other.isVolatile 415 && isRestrict <= other.isRestrict; 416 /// && isLvalue >= other.isLvalue; 422 && isRestrict <= other.isRestrict 423 // && isLvalue >= other.isLvalue 424 && isAtomic == other.isAtomic; 417 425 } 418 426 … … 420 428 return isConst >= other.isConst 421 429 && isVolatile >= other.isVolatile 422 && isRestrict >= other.isRestrict; 423 /// && isLvalue <= other.isLvalue; 430 && isRestrict >= other.isRestrict 431 // && isLvalue <= other.isLvalue 432 && isAtomic == other.isAtomic; 424 433 } 425 434 -
translator/SynTree/Visitor.cc
rad17ba6a rbdd516a 309 309 } 310 310 311 void Visitor::visit(MemberInit *memberInit) {312 memberInit->get_value()->accept( *this );313 }314 315 void Visitor::visit(ElementInit *elementInit) {316 elementInit->get_value()->accept( *this );317 }318 319 311 void Visitor::visit(SingleInit *singleInit) { 320 312 singleInit->get_value()->accept( *this ); -
translator/SynTree/Visitor.h
rad17ba6a rbdd516a 72 72 virtual void visit( AttrType *attrType ); 73 73 74 virtual void visit( MemberInit *memberInit );75 virtual void visit( ElementInit *elementInit );76 74 virtual void visit( SingleInit *singleInit ); 77 75 virtual void visit( ListInit *listInit ); -
translator/Tests/Parser/Constant0-1.c
rad17ba6a rbdd516a 5 5 int 0; 6 6 const int 0; 7 static const int 0;7 //static const int 0; 8 8 int 1; 9 9 const int 1; 10 static const int 1;10 //static const int 1; 11 11 int 0, 1; 12 12 const int 0, 1; 13 static const int 0, 1;13 //static const int 0, 1; 14 14 struct { int i; } 0; 15 15 const struct { int i; } 1; … … 27 27 * int x, 0; 28 28 const * int x, 0; 29 static const * int x, 0;29 //static const * int x, 0; 30 30 * struct { int i; } 0; 31 31 const * struct { int i; } 0; 32 32 static const * struct { int i; } 0; 33 static * int x, 0;34 static const * int x, 0;33 //static * int x, 0; 34 //static const * int x, 0; 35 35 const * * int x, 0; 36 37 int main() { 38 //int 1, * 0; 39 //* int x, 0; 40 } -
translator/examples/includes.c
rad17ba6a rbdd516a 34 34 #include <curses.h> 35 35 #else 36 #include <time.h> // FAILS -- includes locale.h 36 37 #endif // 0 37 38 -
translator/examples/min.c
rad17ba6a rbdd516a 10 10 int main() { 11 11 char c; 12 c = min( ' a', 'z' );12 c = min( 'z', 'a' ); 13 13 printf( "minimum %d\n", c ); 14 14 int i; -
translator/examples/square.c
rad17ba6a rbdd516a 12 12 int main() { 13 13 printf( "result of square of 5 is %d\n", square( 5 ) ); 14 printf( "result of square of 5 is %f\n", square( 5.0 ) ); 14 15 } -
translator/examples/sum.c
rad17ba6a rbdd516a 7 7 T ?+?( T, T ); 8 8 T ?++( T * ); 9 [T]?+=?( T *, T );9 T ?+=?( T *, T ); 10 10 }; 11 11 12 12 forall( type T | sumable( T ) ) 13 13 T sum( int n, T a[] ) { 14 T total = 0; // instantiate T, select 0 14 T total; // instantiate T, select 0 15 total = 0; 15 16 for ( int i = 0; i < n; i += 1 ) 16 17 total = total + a[i]; // select + … … 18 19 } 19 20 21 // Required to satisfy sumable as char does not have addition. 22 const char 0; 23 char ?+?( char op1, char op2 ) { return op1 + op2; } 24 char ?++( char *op ) { return *op + 1; } 25 26 const double 0; // TEMPORARY, incorrect use of int 0 27 20 28 int main() { 21 29 const int size = 10, low = 0, High = 10; 22 int si , ai[10]; // size30 int si = 0, ai[10]; // size 23 31 int i; 24 32 for ( i = low; i < High; i += 1 ) { … … 28 36 printf( "sum from %d to %d is %d, check %d\n", 29 37 low, High, sum( size, ai ), si ); 30 double sd, ad[10]; // size 38 39 // char ci[10]; 40 // char c = sum( size, ci ); 41 // float fi[10]; 42 // float f = sum( size, fi ); 43 44 double sd = 0.0, ad[10]; // size 31 45 for ( i = low; i < High; i += 1 ) { 32 46 double d = i / (double)size; -
translator/main.cc
rad17ba6a rbdd516a 48 48 bool debugp = false, treep = false, astp = false, manglep = false, symtabp = false, validp = false; 49 49 bool preludep = true, protop = false, libp = false; 50 bool exprp = false ;50 bool exprp = false, codegenp = false; 51 51 int c; 52 52 FILE *input, *prelude, *builtins; … … 55 55 opterr = 0; 56 56 57 while ( (c = getopt( argc, argv, "dtsgmvxcenprlD :" )) != -1 ) {57 while ( (c = getopt( argc, argv, "dtsgmvxcenprlDz:" )) != -1 ) { 58 58 switch (c) { 59 59 case 'd': … … 89 89 exprp = true; 90 90 break; 91 case 'z': 92 codegenp = true; 93 break; 91 94 case 'n': 92 95 /* don't read preamble */ … … 234 237 return 0; 235 238 } // if 239 240 if ( codegenp ) { 241 // print the tree right before code generation... 242 // InitTweak::mutate( translationUnit ); 243 // InitTweak::tweak( translationUnit ); 244 //printAll( translationUnit, std::cout ); 245 246 // std::cerr << "finished tweaking" << std::endl; 247 SymTab::validate( translationUnit, false ); 248 ControlStruct::mutate( translationUnit ); 249 CodeGen::fixNames( translationUnit ); 250 ResolvExpr::resolve( translationUnit ); 251 GenPoly::copyParams( translationUnit ); 252 GenPoly::convertSpecializations( translationUnit ); 253 GenPoly::convertLvalue( translationUnit ); 254 GenPoly::box( translationUnit ); 255 printAll( translationUnit, std::cout ); 256 return 0; 257 } // if 236 258 237 259 //std::cerr << "before validate" << std::endl;
Note: See TracChangeset
for help on using the changeset viewer.