Changeset 4bf5298


Ignore:
Timestamp:
May 14, 2015, 1:54:02 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, string, with_gc
Children:
5c7fb6c
Parents:
c11e31c (diff), b1a6d6b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

update merged files from master

Files:
11 edited

Legend:

Unmodified
Added
Removed
  • driver/cfa.cc

    rc11e31c r4bf5298  
    294294        args[nargs] = "-Wno-deprecated";
    295295        nargs += 1;
     296        args[nargs] = "--std=c99";
     297        nargs += 1;
    296298        args[nargs] = ( *new string( string("-B") + Bprefix + "/" ) ).c_str();
    297299        nargs += 1;
  • translator/ControlStruct/Mutate.cc

    rc11e31c r4bf5298  
    2121namespace ControlStruct {
    2222    void mutate( std::list< Declaration * > translationUnit ) {
     23        // ForExprMutator formut;
     24        LabelFixer lfix;
    2325        ChooseMutator chmut;
    24         ForExprMutator formut;
    2526        CaseRangeMutator ranges;  // has to run after ChooseMutator
    26         LabelFixer lfix;
    2727        //ExceptMutator exc;
    28         LabelTypeChecker lbl;
     28        // LabelTypeChecker lbl;
    2929
    30         mutateAll( translationUnit, formut );
     30        // mutateAll( translationUnit, formut );
    3131        acceptAll( translationUnit, lfix );
    3232        mutateAll( translationUnit, chmut );
  • translator/GenPoly/Box.cc

    rc11e31c r4bf5298  
    77
    88#include <set>
     9#include <stack>
    910#include <string>
    1011#include <iterator>
     
    5051            virtual Type *mutate( FunctionType *pointerType );
    5152 
     53            virtual void doBeginScope();
    5254            virtual void doEndScope();
    5355          private:
     
    6668 
    6769            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;
    6972            DeclarationWithType *retval;
    7073            bool useRetval;
     
    126129
    127130    namespace {
     131        std::string makeAdapterName( const std::string &mangleName ) {
     132            return "_adapter" + mangleName;
     133        }
     134
    128135        bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars ) {
    129136            bool doTransform = false;
     
    219226                retval = oldRetval;
    220227                useRetval = oldUseRetval;
    221                 doEndScope();
     228                // doEndScope();
    222229            } // if
    223230            return functionDecl;
     
    316323            Type *concrete = env->lookup( typeName );
    317324            if ( concrete == 0 ) {
    318                 throw SemanticError( "Unbound type variable " + typeName + " in", appExpr );
     325                throw SemanticError( "Unbound type variable " + typeName + " in ", appExpr );
    319326            } // if
    320327            return addRetParam( appExpr, function, concrete, arg );
     
    326333                ret = addRetParam( appExpr, function, function->get_returnVals().front()->get_type(), arg );
    327334            } // if
     335            std::string mangleName = SymTab::Mangler::mangle( function );
     336            std::string adapterName = makeAdapterName( mangleName );
     337
    328338            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 ) );
    330340 
    331341            return ret;
     
    337347            TypeInstType *typeInst = dynamic_cast< TypeInstType *>( param );
    338348            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
    340354                    arg = new AddressExpr( arg );
    341355                } else {
     
    371385            for ( std::list< DeclarationWithType *>::const_iterator param = function->get_parameters().begin(); param != function->get_parameters().end(); ++param, ++arg ) {
    372386///     std::cout << "parameter is ";
    373 ///     (*param)->print( std::cout );
     387///     (*param)->print( std::fcout );
    374388///     std::cout << std::endl << "argument is ";
    375389///     (*arg)->print( std::cout );
     
    448462        }
    449463
     464
     465
    450466        FunctionDecl *Pass1::makeAdapter( FunctionType *adaptee, FunctionType *realType, const std::string &mangleName, const TyVarMap &tyVars ) {
    451467            FunctionType *adapterType = makeAdapterType( adaptee, tyVars );
     
    496512            CompoundStmt *adapterBody = new CompoundStmt( noLabels );
    497513            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 );
    499516        }
    500517
     
    515532                assert( env );
    516533                env->apply( realFunction );
     534
    517535                std::string mangleName = SymTab::Mangler::mangle( realFunction );
    518536                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 );
    522548                        adapter = adapters.insert( adapters.begin(), std::pair< std::string, FunctionDecl *>( mangleName, newAdapter ) );
    523549                        stmtsToAdd.push_back( new DeclStmt( noLabels, newAdapter ) );
     
    525551                    assert( adapter != adapters.end() );
    526552                    appExpr->get_args().push_front( new VariableExpr( adapter->second ) );
     553                    // appExpr->get_args().push_front( new NameExpr( makeAdapterName ( mangleName ) ) );
    527554                    adaptersDone.insert( adaptersDone.begin(), mangleName );
    528555                } // if
     
    845872        }
    846873
     874        void Pass1::doBeginScope() {
     875            adapters.push(AdapterMap());
     876        }
     877
    847878        void Pass1::doEndScope() {
    848             adapters.clear();
     879            adapters.pop();
    849880        }
    850881
     
    865896                std::string mangleName = SymTab::Mangler::mangle( *funType );
    866897                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 ) );
    868900                    adaptersDone.insert( adaptersDone.begin(), mangleName );
    869901                }
  • translator/GenPoly/GenPoly.cc

    rc11e31c r4bf5298  
    99#include "SynTree/Type.h"
    1010
     11#include <iostream>
     12using namespace std;
    1113
    1214namespace GenPoly {
    1315
     16// interface functions
     17bool isPolyVal( Type *type, const TyVarMap &tyVars ) {
     18  return isPolyVal( type, tyVars, false );
     19}
     20
     21bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 
     22  return needsAdapter( adaptee, tyVars, false );
     23}
     24
    1425bool
    15 isPolyVal( Type *type, const TyVarMap &tyVars )
     26isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars )
    1627{
    1728  if( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) {
     
    1930      return true;
    2031    }
     32    return considerAllTyVars;
    2133  }
    2234  return false;
     
    2638// parameters have polymorphic type
    2739bool
    28 needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars )
     40needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars, bool considerAllTyVars )
    2941{
    3042  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 ) ) {
    3244    needsAdapter = true;
    3345  }
    3446  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 ) ) {
    3648      needsAdapter = true;
    3749    }
  • translator/GenPoly/GenPoly.h

    rc11e31c r4bf5298  
    55 *
    66 */
     7
     8#ifndef GENPOLY_H
     9#define GENPOLY_H
    710
    811#include <map>
     
    1518typedef std::map< std::string, TypeDecl::Kind > TyVarMap;
    1619
    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
     23bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr );
     24bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars, bool considerAllTyVars );
    1825bool isPolyFun( FunctionType *fun, const TyVarMap &tyVars );
    1926bool isPolyVal( Type *type, const TyVarMap &tyVars );
     27bool isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars );
    2028void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
    2129
    2230} // namespace GenPoly
     31
     32#endif
  • translator/GenPoly/PolyMutator.cc

    rc11e31c r4bf5298  
    5151    compound->get_kids().push_back( newStmt );
    5252    compound->get_kids().splice( compound->get_kids().end(), stmtsToAddAfter );
    53     doEndScope();
     53    // doEndScope();
    5454    return compound;
    5555  } else {
     
    7474PolyMutator::mutate(CompoundStmt *compoundStmt)
    7575{
     76  doBeginScope();
    7677  mutateStatementList( compoundStmt->get_kids() );
    7778  doEndScope();
  • translator/GenPoly/PolyMutator.h

    rc11e31c r4bf5298  
    4141 
    4242  // template method
     43  virtual void doBeginScope() {}
    4344  virtual void doEndScope() {}
    4445
  • translator/ResolvExpr/Resolver.cc

    rc11e31c r4bf5298  
    192192
    193193    void Resolver::visit( ForStmt *forStmt ) {
     194        // SymTab::Indexer::visit( forStmt );
    194195        Expression *newExpr;
     196        // for statements introduce a level of scope
     197        enterScope();
     198        maybeAccept( forStmt->get_initialization(), *this );
    195199        if ( forStmt->get_condition() ) {
    196200            newExpr = findSingleExpression( forStmt->get_condition(), *this );
     
    204208            forStmt->set_increment( newExpr );
    205209        } // 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();
    208215    }
    209216
  • translator/SymTab/Validate.cc

    rc11e31c r4bf5298  
    155155    };
    156156
    157     void validate( std::list< Declaration * > &translationUnit, bool doDebug, const Indexer *indexer ) {
     157    void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {
    158158        Pass1 pass1;
    159         Pass2 pass2( doDebug, indexer );
    160         Pass3 pass3( indexer );
     159        Pass2 pass2( doDebug, 0 );
     160        Pass3 pass3( 0 );
    161161        EliminateTypedef::eliminateTypedef( translationUnit );
    162162        HoistStruct::hoistStruct( translationUnit );
     
    166166        acceptAll( translationUnit, pass3 );
    167167    }
    168 
     168   
    169169    void validateType( Type *type, const Indexer *indexer ) {
    170170        Pass1 pass1;
  • translator/SynTree/CompoundStmt.cc

    rc11e31c r4bf5298  
    1414using std::endl;
    1515
    16 CompoundStmt::CompoundStmt( std::list<Label> labels )
    17     : Statement( labels )
    18 {
     16CompoundStmt::CompoundStmt( std::list<Label> labels ) : Statement( labels ) {
    1917}
    2018
    21 CompoundStmt::CompoundStmt( const CompoundStmt &other )
    22     : Statement( other )
    23 {
     19CompoundStmt::CompoundStmt( const CompoundStmt &other ) : Statement( other ) {
    2420    cloneAll( other.kids, kids );
    2521}
    2622
    27 CompoundStmt::~CompoundStmt()
    28 {
     23CompoundStmt::~CompoundStmt() {
    2924    deleteAll( kids );
    3025}
    3126
    32 void
    33 CompoundStmt::print( std::ostream &os, int indent )
    34 {
    35     os << "\r" << string(indent, ' ') << "CompoundStmt Statement" << endl ;
    36     printAll( kids, os, indent + 4 );
     27void CompoundStmt::print( std::ostream &os, int indent ) {
     28    os << "\r" << string(indent, ' ') << "CompoundStmt" << endl ;
     29    printAll( kids, os, indent+2 );
    3730}
    3831
  • translator/main.cc

    rc11e31c r4bf5298  
    4949    bool debugp = false, treep = false, astp = false, manglep = false, symtabp = false, validp = false;
    5050    bool preludep = true, protop = false, libp = false;
    51     bool exprp = false, codegenp = false;
     51    bool exprp = false, codegenp = false, errorp = false;
    5252    int c;
    5353    FILE *input, *prelude, *builtins;
     
    5656    opterr = 0;
    5757
    58     while ( (c = getopt( argc, argv, "dtsgmvxcenprlDz:" )) != -1 ) {
     58    std::list< Declaration* > translationUnit;
     59   
     60    while ( (c = getopt( argc, argv, "dtsgmvxcenprlDyz:" )) != -1 ) {
    5961        switch (c) {
    6062          case 'd':
    61             /* bison debugging info */
     63            // bison debugging info
    6264            debugp = true;
    6365            break;
    6466          case 't':
    65             /* dump parse tree */
     67            // dump parse tree
    6668            treep = true;
    6769            break;
    6870          case 's':
    69             /* dump AST */
     71            // dump AST
    7072            astp = true;
    7173            break;
    7274          case 'g':
    73             /* print alternatives for expressions */
     75            // print alternatives for expressions
    7476            manglep = true;
    7577            break;
    7678          case 'm':
    77             /* print symbol table events */
     79            // print symbol table events
    7880            symtabp = true;
    7981            break;
    8082          case 'r':
    81             /* print resolver steps */
     83            // print resolver steps
    8284            resolveVerbose = true;
    8385            break;
    8486          case 'x':
    85             /* dump AST after decl validation pass */
     87            // dump AST after decl validation pass
    8688            validp = true;
    8789            break;
    8890          case 'e':
    89             /* dump AST after expression analysis */
     91            // dump AST after expression analysis
    9092            exprp = true;
    9193            break;
     
    9395            codegenp = true;
    9496            break;
     97          case 'y':
     98            errorp = true;
     99            break;
    95100          case 'n':
    96             /* don't read preamble */
     101            // don't read preamble
    97102            preludep = false;
    98103            break;
    99104          case 'p':
    100             /* generate prototypes for preamble functions */
     105            // generate prototypes for preamble functions
    101106            protop = true;
    102107            break;
    103108          case 'l':
    104             /* generate libcfa.c */
     109            // generate libcfa.c
    105110            libp = true;
    106111            break;
    107112          case 'v':
    108             /* verbose */
     113            // verbose
    109114            beVerbose = true;
    110115            break;
    111116          case 'D':
    112             /* ignore -Dxxx */
     117            // ignore -Dxxx
    113118            break;
    114119          case '?':
     
    205210        } // if
    206211
    207         std::list< Declaration* > translationUnit;
    208212        buildList( Parser::get_parser().get_parseTree(), translationUnit );
    209213
     
    233237
    234238        if ( exprp ) {
     239            InitTweak::tweak( translationUnit );
    235240            SymTab::validate( translationUnit, false );
    236             ResolvExpr::resolve( translationUnit );
    237             printAll( translationUnit, std::cout );
    238             return 0;
    239         } // if
    240 
    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 );
    249241            ControlStruct::mutate( translationUnit );
    250242            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;
    251259            ResolvExpr::resolve( translationUnit );
     260            cerr << "copyParams" << endl;
    252261            GenPoly::copyParams( translationUnit );
     262            cerr << "convertSpecializations" << endl;
    253263            GenPoly::convertSpecializations( translationUnit );
     264            cerr << "convertLvalue" << endl;
    254265            GenPoly::convertLvalue( translationUnit );
     266            cerr << "box" << endl;
    255267            GenPoly::box( translationUnit );
    256             printAll( translationUnit, std::cout );
     268            if ( errorp ) {
     269                printAll( translationUnit, std::cout );
     270            }
    257271            return 0;
    258272        } // if
     
    293307
    294308    } catch ( SemanticError &e ) {
     309        if ( errorp ) {
     310           printAll( translationUnit, std::cout );
     311        }
    295312        e.print( cout );
    296313        if ( output != &std::cout ) {
Note: See TracChangeset for help on using the changeset viewer.