Changeset b1a6d6b
- Timestamp:
- May 14, 2015, 12:19:46 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 4bf5298
- Parents:
- d4778a6
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
driver/cfa.cc
rd4778a6 rb1a6d6b 294 294 args[nargs] = "-Wno-deprecated"; 295 295 nargs += 1; 296 args[nargs] = "--std=c99"; 297 nargs += 1; 296 298 args[nargs] = ( *new string( string("-B") + Bprefix + "/" ) ).c_str(); 297 299 nargs += 1; -
translator/ControlStruct/Mutate.cc
rd4778a6 rb1a6d6b 21 21 namespace ControlStruct { 22 22 void mutate( std::list< Declaration * > translationUnit ) { 23 // ForExprMutator formut; 24 LabelFixer lfix; 23 25 ChooseMutator chmut; 24 ForExprMutator formut;25 26 CaseRangeMutator ranges; // has to run after ChooseMutator 26 LabelFixer lfix;27 27 //ExceptMutator exc; 28 LabelTypeChecker lbl;28 // LabelTypeChecker lbl; 29 29 30 mutateAll( translationUnit, formut );30 // mutateAll( translationUnit, formut ); 31 31 acceptAll( translationUnit, lfix ); 32 32 mutateAll( translationUnit, chmut ); -
translator/GenPoly/Box.cc
rd4778a6 rb1a6d6b 7 7 8 8 #include <set> 9 #include <stack> 9 10 #include <string> 10 11 #include <iterator> … … 50 51 virtual Type *mutate( FunctionType *pointerType ); 51 52 53 virtual void doBeginScope(); 52 54 virtual void doEndScope(); 53 55 private: … … 66 68 67 69 std::map< std::string, DeclarationWithType *> assignOps; 68 std::map< std::string, FunctionDecl *> adapters; 70 typedef std::map< std::string, FunctionDecl *> AdapterMap; 71 std::stack< AdapterMap > adapters; 69 72 DeclarationWithType *retval; 70 73 bool useRetval; … … 126 129 127 130 namespace { 131 std::string makeAdapterName( const std::string &mangleName ) { 132 return "_adapter" + mangleName; 133 } 134 128 135 bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars ) { 129 136 bool doTransform = false; … … 219 226 retval = oldRetval; 220 227 useRetval = oldUseRetval; 221 doEndScope();228 // doEndScope(); 222 229 } // if 223 230 return functionDecl; … … 316 323 Type *concrete = env->lookup( typeName ); 317 324 if ( concrete == 0 ) { 318 throw SemanticError( "Unbound type variable " + typeName + " in ", appExpr );325 throw SemanticError( "Unbound type variable " + typeName + " in ", appExpr ); 319 326 } // if 320 327 return addRetParam( appExpr, function, concrete, arg ); … … 326 333 ret = addRetParam( appExpr, function, function->get_returnVals().front()->get_type(), arg ); 327 334 } // if 335 std::string mangleName = SymTab::Mangler::mangle( function ); 336 std::string adapterName = makeAdapterName( mangleName ); 337 328 338 appExpr->get_args().push_front( appExpr->get_function() ); 329 appExpr->set_function( new NameExpr( "_adapter" + SymTab::Mangler::mangle( function )) );339 appExpr->set_function( new NameExpr( adapterName ) ); 330 340 331 341 return ret; … … 337 347 TypeInstType *typeInst = dynamic_cast< TypeInstType *>( param ); 338 348 if ( typeInst && exprTyVars.find( typeInst->get_name() ) != exprTyVars.end() ) { 339 if ( arg->get_results().front()->get_isLvalue() ) { 349 if ( dynamic_cast< TypeInstType *>( arg->get_results().front() ) ) { 350 // if the argument's type is a type parameter, we don't need to box again! 351 return; 352 } else if ( arg->get_results().front()->get_isLvalue() ) { 353 // VariableExpr and MemberExpr are lvalues 340 354 arg = new AddressExpr( arg ); 341 355 } else { … … 371 385 for ( std::list< DeclarationWithType *>::const_iterator param = function->get_parameters().begin(); param != function->get_parameters().end(); ++param, ++arg ) { 372 386 /// std::cout << "parameter is "; 373 /// (*param)->print( std:: cout );387 /// (*param)->print( std::fcout ); 374 388 /// std::cout << std::endl << "argument is "; 375 389 /// (*arg)->print( std::cout ); … … 448 462 } 449 463 464 465 450 466 FunctionDecl *Pass1::makeAdapter( FunctionType *adaptee, FunctionType *realType, const std::string &mangleName, const TyVarMap &tyVars ) { 451 467 FunctionType *adapterType = makeAdapterType( adaptee, tyVars ); … … 496 512 CompoundStmt *adapterBody = new CompoundStmt( noLabels ); 497 513 adapterBody->get_kids().push_back( bodyStmt ); 498 return new FunctionDecl( "_adapter" + mangleName, Declaration::NoStorageClass, LinkageSpec::C, adapterType, adapterBody, false ); 514 std::string adapterName = makeAdapterName( mangleName ); 515 return new FunctionDecl( adapterName, Declaration::NoStorageClass, LinkageSpec::C, adapterType, adapterBody, false ); 499 516 } 500 517 … … 515 532 assert( env ); 516 533 env->apply( realFunction ); 534 517 535 std::string mangleName = SymTab::Mangler::mangle( realFunction ); 518 536 if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) { 519 std::map< std::string, FunctionDecl *>::iterator adapter = adapters.find( mangleName ); 520 if ( adapter == adapters.end() ) { 521 FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars ); 537 AdapterMap & adapters = Pass1::adapters.top(); 538 AdapterMap::iterator adapter = adapters.find( mangleName ); 539 540 if ( needsAdapter( realFunction, exprTyVars, true ) ) { 541 // the function still contains type variables, which means we are in a polymorphic 542 // context and the adapter function is a parameter - call the parameter and don't 543 // create a new adapter. 544 appExpr->get_args().push_front( new NameExpr( makeAdapterName ( mangleName ) ) ); 545 continue; 546 } else if ( adapter == adapters.end() ) { 547 FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars ); 522 548 adapter = adapters.insert( adapters.begin(), std::pair< std::string, FunctionDecl *>( mangleName, newAdapter ) ); 523 549 stmtsToAdd.push_back( new DeclStmt( noLabels, newAdapter ) ); … … 525 551 assert( adapter != adapters.end() ); 526 552 appExpr->get_args().push_front( new VariableExpr( adapter->second ) ); 553 // appExpr->get_args().push_front( new NameExpr( makeAdapterName ( mangleName ) ) ); 527 554 adaptersDone.insert( adaptersDone.begin(), mangleName ); 528 555 } // if … … 845 872 } 846 873 874 void Pass1::doBeginScope() { 875 adapters.push(AdapterMap()); 876 } 877 847 878 void Pass1::doEndScope() { 848 adapters. clear();879 adapters.pop(); 849 880 } 850 881 … … 865 896 std::string mangleName = SymTab::Mangler::mangle( *funType ); 866 897 if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) { 867 paramList.push_front( new ObjectDecl( "_adapter" + mangleName, Declaration::NoStorageClass, LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), 0 ) ); 898 std::string adapterName = makeAdapterName( mangleName ); 899 paramList.push_front( new ObjectDecl( adapterName, Declaration::NoStorageClass, LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), 0 ) ); 868 900 adaptersDone.insert( adaptersDone.begin(), mangleName ); 869 901 } -
translator/GenPoly/GenPoly.cc
rd4778a6 rb1a6d6b 9 9 #include "SynTree/Type.h" 10 10 11 #include <iostream> 12 using namespace std; 11 13 12 14 namespace GenPoly { 13 15 16 // interface functions 17 bool isPolyVal( Type *type, const TyVarMap &tyVars ) { 18 return isPolyVal( type, tyVars, false ); 19 } 20 21 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 22 return needsAdapter( adaptee, tyVars, false ); 23 } 24 14 25 bool 15 isPolyVal( Type *type, const TyVarMap &tyVars )26 isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars ) 16 27 { 17 28 if( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) { … … 19 30 return true; 20 31 } 32 return considerAllTyVars; 21 33 } 22 34 return false; … … 26 38 // parameters have polymorphic type 27 39 bool 28 needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars )40 needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars, bool considerAllTyVars ) 29 41 { 30 42 bool needsAdapter = false; 31 if( !adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {43 if( !adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars, considerAllTyVars ) ) { 32 44 needsAdapter = true; 33 45 } 34 46 for( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); !needsAdapter && innerArg != adaptee->get_parameters().end(); ++innerArg ) { 35 if( isPolyVal( (*innerArg)->get_type(), tyVars ) ) {47 if( isPolyVal( (*innerArg)->get_type(), tyVars, considerAllTyVars ) ) { 36 48 needsAdapter = true; 37 49 } -
translator/GenPoly/GenPoly.h
rd4778a6 rb1a6d6b 5 5 * 6 6 */ 7 8 #ifndef GENPOLY_H 9 #define GENPOLY_H 7 10 8 11 #include <map> … … 15 18 typedef std::map< std::string, TypeDecl::Kind > TyVarMap; 16 19 17 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ); 20 // considerAllTyVars allows ignoring the contents of the TyVarMap parameter, for the situations where 21 // it is important only that a TypeInstType node exists. 22 23 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr ); 24 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars, bool considerAllTyVars ); 18 25 bool isPolyFun( FunctionType *fun, const TyVarMap &tyVars ); 19 26 bool isPolyVal( Type *type, const TyVarMap &tyVars ); 27 bool isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars ); 20 28 void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ); 21 29 22 30 } // namespace GenPoly 31 32 #endif -
translator/GenPoly/PolyMutator.cc
rd4778a6 rb1a6d6b 51 51 compound->get_kids().push_back( newStmt ); 52 52 compound->get_kids().splice( compound->get_kids().end(), stmtsToAddAfter ); 53 doEndScope();53 // doEndScope(); 54 54 return compound; 55 55 } else { … … 74 74 PolyMutator::mutate(CompoundStmt *compoundStmt) 75 75 { 76 doBeginScope(); 76 77 mutateStatementList( compoundStmt->get_kids() ); 77 78 doEndScope(); -
translator/GenPoly/PolyMutator.h
rd4778a6 rb1a6d6b 41 41 42 42 // template method 43 virtual void doBeginScope() {} 43 44 virtual void doEndScope() {} 44 45 -
translator/ResolvExpr/Resolver.cc
rd4778a6 rb1a6d6b 192 192 193 193 void Resolver::visit( ForStmt *forStmt ) { 194 // SymTab::Indexer::visit( forStmt ); 194 195 Expression *newExpr; 196 // for statements introduce a level of scope 197 enterScope(); 198 maybeAccept( forStmt->get_initialization(), *this ); 195 199 if ( forStmt->get_condition() ) { 196 200 newExpr = findSingleExpression( forStmt->get_condition(), *this ); … … 204 208 forStmt->set_increment( newExpr ); 205 209 } // if 206 207 Visitor::visit( forStmt ); 210 211 maybeAccept( forStmt->get_condition(), *this ); 212 maybeAccept( forStmt->get_increment(), *this ); 213 maybeAccept( forStmt->get_body(), *this ); 214 leaveScope(); 208 215 } 209 216 -
translator/SymTab/Validate.cc
rd4778a6 rb1a6d6b 155 155 }; 156 156 157 void validate( std::list< Declaration * > &translationUnit, bool doDebug , const Indexer *indexer) {157 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) { 158 158 Pass1 pass1; 159 Pass2 pass2( doDebug, indexer);160 Pass3 pass3( indexer);159 Pass2 pass2( doDebug, 0 ); 160 Pass3 pass3( 0 ); 161 161 EliminateTypedef::eliminateTypedef( translationUnit ); 162 162 HoistStruct::hoistStruct( translationUnit ); … … 166 166 acceptAll( translationUnit, pass3 ); 167 167 } 168 168 169 169 void validateType( Type *type, const Indexer *indexer ) { 170 170 Pass1 pass1; -
translator/SynTree/CompoundStmt.cc
rd4778a6 rb1a6d6b 11 11 #include <functional> 12 12 13 #include <iostream> 14 using namespace std; 13 15 14 16 CompoundStmt::CompoundStmt( std::list<Label> labels ) … … 31 33 CompoundStmt::print( std::ostream &os, int indent ) 32 34 { 33 printAll( kids, os, indent ); 35 os << "\r" << string(indent, ' ') << "CompoundStmt" << endl ; 36 printAll( kids, os, indent+2 ); 34 37 } 35 38 -
translator/main.cc
rd4778a6 rb1a6d6b 49 49 bool debugp = false, treep = false, astp = false, manglep = false, symtabp = false, validp = false; 50 50 bool preludep = true, protop = false, libp = false; 51 bool exprp = false, codegenp = false ;51 bool exprp = false, codegenp = false, errorp = false; 52 52 int c; 53 53 FILE *input, *prelude, *builtins; … … 56 56 opterr = 0; 57 57 58 while ( (c = getopt( argc, argv, "dtsgmvxcenprlDz:" )) != -1 ) { 58 std::list< Declaration* > translationUnit; 59 60 while ( (c = getopt( argc, argv, "dtsgmvxcenprlDyz:" )) != -1 ) { 59 61 switch (c) { 60 62 case 'd': 61 / * bison debugging info */63 // bison debugging info 62 64 debugp = true; 63 65 break; 64 66 case 't': 65 / * dump parse tree */67 // dump parse tree 66 68 treep = true; 67 69 break; 68 70 case 's': 69 / * dump AST */71 // dump AST 70 72 astp = true; 71 73 break; 72 74 case 'g': 73 / * print alternatives for expressions */75 // print alternatives for expressions 74 76 manglep = true; 75 77 break; 76 78 case 'm': 77 / * print symbol table events */79 // print symbol table events 78 80 symtabp = true; 79 81 break; 80 82 case 'r': 81 / * print resolver steps */83 // print resolver steps 82 84 resolveVerbose = true; 83 85 break; 84 86 case 'x': 85 / * dump AST after decl validation pass */87 // dump AST after decl validation pass 86 88 validp = true; 87 89 break; 88 90 case 'e': 89 / * dump AST after expression analysis */91 // dump AST after expression analysis 90 92 exprp = true; 91 93 break; … … 93 95 codegenp = true; 94 96 break; 97 case 'y': 98 errorp = true; 99 break; 95 100 case 'n': 96 / * don't read preamble */101 // don't read preamble 97 102 preludep = false; 98 103 break; 99 104 case 'p': 100 / * generate prototypes for preamble functions */105 // generate prototypes for preamble functions 101 106 protop = true; 102 107 break; 103 108 case 'l': 104 / * generate libcfa.c */109 // generate libcfa.c 105 110 libp = true; 106 111 break; 107 112 case 'v': 108 / * verbose */113 // verbose 109 114 beVerbose = true; 110 115 break; 111 116 case 'D': 112 / * ignore -Dxxx */117 // ignore -Dxxx 113 118 break; 114 119 case '?': … … 205 210 } // if 206 211 207 std::list< Declaration* > translationUnit;208 212 buildList( Parser::get_parser().get_parseTree(), translationUnit ); 209 213 … … 233 237 234 238 if ( exprp ) { 239 InitTweak::tweak( translationUnit ); 235 240 SymTab::validate( translationUnit, false ); 236 ResolvExpr::resolve( translationUnit );237 printAll( translationUnit, std::cout );238 return 0;239 } // if240 241 if ( codegenp ) {242 // print the tree right before code generation...243 // InitTweak::mutate( translationUnit );244 // InitTweak::tweak( translationUnit );245 //printAll( translationUnit, std::cout );246 247 // std::cerr << "finished tweaking" << std::endl;248 SymTab::validate( translationUnit, false );249 241 ControlStruct::mutate( translationUnit ); 250 242 CodeGen::fixNames( translationUnit ); 243 ResolvExpr::resolve( translationUnit ); 244 printAll( translationUnit, std::cout ); 245 return 0; 246 } // if 247 248 if ( codegenp ) { 249 // print the tree right before code generation 250 cerr << "tweak" << endl; 251 InitTweak::tweak( translationUnit ); 252 cerr << "validate" << endl; 253 SymTab::validate( translationUnit, false ); 254 cerr << "mutate" << endl; 255 ControlStruct::mutate( translationUnit ); 256 cerr << "fixNames" << endl; 257 CodeGen::fixNames( translationUnit ); 258 cerr << "resolve" << endl; 251 259 ResolvExpr::resolve( translationUnit ); 260 cerr << "copyParams" << endl; 252 261 GenPoly::copyParams( translationUnit ); 262 cerr << "convertSpecializations" << endl; 253 263 GenPoly::convertSpecializations( translationUnit ); 264 cerr << "convertLvalue" << endl; 254 265 GenPoly::convertLvalue( translationUnit ); 266 cerr << "box" << endl; 255 267 GenPoly::box( translationUnit ); 256 printAll( translationUnit, std::cout ); 268 if ( errorp ) { 269 printAll( translationUnit, std::cout ); 270 } 257 271 return 0; 258 272 } // if … … 293 307 294 308 } catch ( SemanticError &e ) { 309 if ( errorp ) { 310 printAll( translationUnit, std::cout ); 311 } 295 312 e.print( cout ); 296 313 if ( output != &std::cout ) {
Note: See TracChangeset
for help on using the changeset viewer.