Changes in / [2065609:26238c1]


Ignore:
Location:
src
Files:
2 added
1 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r2065609 r26238c1  
    756756                                Type * newType = arg->get_result()->clone();
    757757                                if ( env ) env->apply( newType );
    758                                 std::auto_ptr<Type> manager( newType );
     758                                std::unique_ptr<Type> manager( newType );
    759759                                if ( isPolyType( newType ) ) {
    760760                                        // if the argument's type is polymorphic, we don't need to box again!
     
    774774                                        newObj->get_type()->get_qualifiers() = Type::Qualifiers(); // TODO: is this right???
    775775                                        stmtsToAdd.push_back( new DeclStmt( noLabels, newObj ) );
    776                                         UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
     776                                        UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); // TODO: why doesn't this just use initialization syntax?
    777777                                        assign->get_args().push_back( new VariableExpr( newObj ) );
    778778                                        assign->get_args().push_back( arg );
  • src/InitTweak/InitTweak.cc

    r2065609 r26238c1  
    418418                        assertf( ! tuple->get_exprs().empty(), "TupleAssignExpr somehow has empty tuple expr." );
    419419                        return getCallArg( tuple->get_exprs().front(), pos );
     420                } else if ( ImplicitCopyCtorExpr * copyCtor = dynamic_cast< ImplicitCopyCtorExpr * >( callExpr ) ) {
     421                        return getCallArg( copyCtor->callExpr, pos );
    420422                } else {
    421423                        assertf( false, "Unexpected expression type passed to getCallArg: %s", toString( callExpr ).c_str() );
     
    450452                        } else if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( func ) ) {
    451453                                return handleDerefName( appExpr );
     454                        } else if ( ConstructorExpr * ctorExpr = dynamic_cast< ConstructorExpr * >( func ) ) {
     455                                return funcName( getCallArg( ctorExpr->get_callExpr(), 0 ) );
    452456                        } else {
    453                                 assertf( false, "Unexpected expression type being called as a function in call expression" );
     457                                assertf( false, "Unexpected expression type being called as a function in call expression: %s", toString( func ).c_str() );
    454458                        }
    455459                }
  • src/Parser/parser.yy

    r2065609 r26238c1  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 23 21:08:08 2017
    13 // Update Count     : 2704
     12// Last Modified On : Sat Aug 26 17:50:19 2017
     13// Update Count     : 2712
    1414//
    1515
     
    120120%token RESTRICT                                                                                 // C99
    121121%token ATOMIC                                                                                   // C11
    122 %token FORALL MUTEX VIRTUAL                                             // CFA
     122%token FORALL MUTEX VIRTUAL                                                             // CFA
    123123%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
    124124%token BOOL COMPLEX IMAGINARY                                                   // C99
     
    188188%type<flag> asm_volatile_opt
    189189%type<en> handler_predicate_opt
    190 %type<en> when_clause_opt timeout
    191190
    192191// statements
    193 %type<sn> labeled_statement                             compound_statement                      expression_statement            selection_statement
    194 %type<sn> iteration_statement                   jump_statement
    195 %type<sn> with_statement                                exception_statement                     asm_statement
    196 %type<sn> waitfor_statement
    197 %type<sn> fall_through_opt                              fall_through
    198 %type<sn> statement                                             statement_list
    199 %type<sn> block_item_list                               block_item
    200 %type<sn> with_clause_opt
     192%type<sn> statement                                             labeled_statement                       compound_statement
     193%type<sn> statement_decl                                statement_decl_list                     statement_list_nodecl
     194%type<sn> selection_statement
     195%type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
    201196%type<en> case_value
    202197%type<sn> case_clause                                   case_value_list                         case_label                                      case_label_list
    203 %type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
    204 %type<sn> handler_clause                                finally_clause
     198%type<sn> fall_through                                  fall_through_opt
     199%type<sn> iteration_statement                   jump_statement
     200%type<sn> expression_statement                  asm_statement
     201%type<sn> with_statement                                with_clause_opt
     202%type<sn> exception_statement                   handler_clause                          finally_clause
    205203%type<catch_kind> handler_key
     204%type<en> when_clause                                   when_clause_opt                         waitfor                                         timeout
     205%type<sn> waitfor_statement
    206206%type<wfs> waitfor_clause
    207 %type<en> waitfor
    208207
    209208// declarations
     
    777776          push push
    778777          local_label_declaration_opt                                           // GCC, local labels
    779           block_item_list                                                                       // C99, intermix declarations and statements
     778          statement_decl_list                                                           // C99, intermix declarations and statements
    780779          pop '}'
    781780                { $$ = new StatementNode( build_compound( $5 ) ); }
    782781        ;
    783782
    784 block_item_list:                                                                                // C99
    785         block_item
    786         | block_item_list push block_item
     783statement_decl_list:                                                                    // C99
     784        statement_decl
     785        | statement_decl_list push statement_decl
    787786                { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
    788787        ;
    789788
    790 block_item:
     789statement_decl:
    791790        declaration                                                                                     // CFA, new & old style declarations
    792791                { $$ = new StatementNode( $1 ); }
     
    806805        ;
    807806
    808 statement_list:
     807statement_list_nodecl:
    809808        statement
    810         | statement_list statement
     809        | statement_list_nodecl statement
    811810                { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
    812811        ;
     
    818817
    819818selection_statement:
    820         IF '(' push if_control_expression ')' statement                         %prec THEN
     819        IF '(' push if_control_expression ')' statement         %prec THEN
    821820                // explicitly deal with the shift/reduce conflict on if/else
    822821                { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); }
     
    893892
    894893switch_clause_list:                                                                             // CFA
    895         case_label_list statement_list
     894        case_label_list statement_list_nodecl
    896895                { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }
    897         | switch_clause_list case_label_list statement_list
     896        | switch_clause_list case_label_list statement_list_nodecl
    898897                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( $3 ) ) ) ) ); }
    899898        ;
     
    908907        case_label_list fall_through
    909908                { $$ = $1->append_last_case( $2 ); }
    910         | case_label_list statement_list fall_through_opt
     909        | case_label_list statement_list_nodecl fall_through_opt
    911910                { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last( $3 ) ) ) ); }
    912911        | choose_clause_list case_label_list fall_through
    913912                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( $3 ))); }
    914         | choose_clause_list case_label_list statement_list fall_through_opt
     913        | choose_clause_list case_label_list statement_list_nodecl fall_through_opt
    915914                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last( $4 ) ) ) ) ) ); }
    916915        ;
     
    981980        ;
    982981
     982when_clause:
     983        WHEN '(' comma_expression ')'
     984                { $$ = $3; }
     985        ;
     986
    983987when_clause_opt:
    984988        // empty
    985989                { $$ = nullptr; }
    986         | WHEN '(' comma_expression ')'
    987                 { $$ = $3; }
     990        | when_clause
    988991        ;
    989992
     
    10081011
    10091012waitfor_clause:
    1010         when_clause_opt waitfor statement %prec THEN
     1013        when_clause_opt waitfor statement                                       %prec THEN
    10111014                { $$ = build_waitfor( $2, $3, $1 ); }
    10121015        | when_clause_opt waitfor statement WOR waitfor_clause
    10131016                { $$ = build_waitfor( $2, $3, $1, $5 ); }
    1014         | when_clause_opt timeout statement %prec THEN
     1017        | when_clause_opt timeout statement                                     %prec THEN
    10151018                { $$ = build_waitfor_timeout( $2, $3, $1 ); }
    10161019        | when_clause_opt ELSE statement
    10171020                { $$ = build_waitfor_timeout( nullptr, $3, $1 ); }
    1018         | when_clause_opt timeout statement WOR when_clause_opt ELSE statement
     1021                // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
     1022        | when_clause_opt timeout statement WOR when_clause ELSE statement
    10191023                { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); }
    10201024        ;
    10211025
    10221026waitfor_statement:
    1023         when_clause_opt waitfor statement %prec THEN
     1027        when_clause_opt waitfor statement                                       %prec THEN
    10241028                { $$ = new StatementNode( build_waitfor( $2, $3, $1 ) ); }
    10251029        | when_clause_opt waitfor statement WOR waitfor_clause
  • src/ResolvExpr/AlternativeFinder.cc

    r2065609 r26238c1  
    698698
    699699        void AlternativeFinder::visit( UntypedExpr *untypedExpr ) {
    700                 bool doneInit = false;
    701                 AlternativeFinder funcOpFinder( indexer, env );
    702 
    703                 AlternativeFinder funcFinder( indexer, env );
    704 
    705700                {
    706701                        std::string fname = InitTweak::getFunctionName( untypedExpr );
     
    715710                }
    716711
     712                AlternativeFinder funcFinder( indexer, env );
    717713                funcFinder.findWithAdjustment( untypedExpr->get_function() );
     714                // if there are no function alternatives, then proceeding is a waste of time.
     715                if ( funcFinder.alternatives.empty() ) return;
     716
    718717                std::list< AlternativeFinder > argAlternatives;
    719718                findSubExprs( untypedExpr->begin_args(), untypedExpr->end_args(), back_inserter( argAlternatives ) );
     
    725724                // if not tuple assignment, assignment is taken care of as a normal function call
    726725                Tuples::handleTupleAssignment( *this, untypedExpr, possibilities );
     726
     727                // find function operators
     728                AlternativeFinder funcOpFinder( indexer, env );
     729                NameExpr *opExpr = new NameExpr( "?()" );
     730                try {
     731                        funcOpFinder.findWithAdjustment( opExpr );
     732                } catch( SemanticError &e ) {
     733                        // it's ok if there aren't any defined function ops
     734                }
     735                PRINT(
     736                        std::cerr << "known function ops:" << std::endl;
     737                        printAlts( funcOpFinder.alternatives, std::cerr, 8 );
     738                )
    727739
    728740                AltList candidates;
     
    754766                                                } // if
    755767                                        } // if
    756                                 } else {
    757                                         // seek a function operator that's compatible
    758                                         if ( ! doneInit ) {
    759                                                 doneInit = true;
    760                                                 NameExpr *opExpr = new NameExpr( "?()" );
    761                                                 try {
    762                                                         funcOpFinder.findWithAdjustment( opExpr );
    763                                                 } catch( SemanticError &e ) {
    764                                                         // it's ok if there aren't any defined function ops
    765                                                 }
    766                                                 PRINT(
    767                                                         std::cerr << "known function ops:" << std::endl;
    768                                                         printAlts( funcOpFinder.alternatives, std::cerr, 8 );
    769                                                 )
    770                                         }
    771 
    772                                         for ( AltList::iterator funcOp = funcOpFinder.alternatives.begin(); funcOp != funcOpFinder.alternatives.end(); ++funcOp ) {
    773                                                 // check if the type is pointer to function
    774                                                 if ( PointerType *pointer = dynamic_cast< PointerType* >( funcOp->expr->get_result()->stripReferences() ) ) {
    775                                                         if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
    776                                                                 referenceToRvalueConversion( funcOp->expr );
    777                                                                 for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) {
    778                                                                         AltList currentAlt;
    779                                                                         currentAlt.push_back( *func );
    780                                                                         currentAlt.insert( currentAlt.end(), actualAlt->begin(), actualAlt->end() );
    781                                                                         makeFunctionAlternatives( *funcOp, function, currentAlt, std::back_inserter( candidates ) );
    782                                                                 } // for
    783                                                         } // if
     768                                }
     769
     770                                // try each function operator ?() with the current function alternative and each of the argument combinations
     771                                for ( AltList::iterator funcOp = funcOpFinder.alternatives.begin(); funcOp != funcOpFinder.alternatives.end(); ++funcOp ) {
     772                                        // check if the type is pointer to function
     773                                        if ( PointerType *pointer = dynamic_cast< PointerType* >( funcOp->expr->get_result()->stripReferences() ) ) {
     774                                                if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
     775                                                        referenceToRvalueConversion( funcOp->expr );
     776                                                        for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) {
     777                                                                AltList currentAlt;
     778                                                                currentAlt.push_back( *func );
     779                                                                currentAlt.insert( currentAlt.end(), actualAlt->begin(), actualAlt->end() );
     780                                                                makeFunctionAlternatives( *funcOp, function, currentAlt, std::back_inserter( candidates ) );
     781                                                        } // for
    784782                                                } // if
    785                                         } // for
    786                                 } // if
     783                                        } // if
     784                                } // for
    787785                        } catch ( SemanticError &e ) {
    788786                                errors.append( e );
  • src/ResolvExpr/CastCost.cc

    r2065609 r26238c1  
    5858                        return Cost::safe;
    5959                } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( dest ) ) {
    60                         return convertToReferenceCost( src, refType, indexer, env );
     60                        return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const TypeEnvironment & env, const SymTab::Indexer & indexer) {
     61                                return ptrsCastable( t1, t2, env, indexer );
     62                        });
    6163                } else {
    6264                        CastCost converter( dest, indexer, env );
  • src/ResolvExpr/ConversionCost.cc

    r2065609 r26238c1  
    4040#define PRINT(x)
    4141#endif
    42 
    4342        Cost conversionCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
    4443                if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) {
     
    7877                } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( dest ) ) {
    7978                        PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; )
    80                         return convertToReferenceCost( src, refType, indexer, env );
     79                        return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const TypeEnvironment & env, const SymTab::Indexer &){
     80                                return ptrsAssignable( t1, t2, env );
     81                        });
    8182                } else {
    8283                        ConversionCost converter( dest, indexer, env );
     
    9091        }
    9192
    92         Cost convertToReferenceCost( Type * src, Type * dest, int diff, const SymTab::Indexer & indexer, const TypeEnvironment & env ) {
     93        Cost convertToReferenceCost( Type * src, Type * dest, int diff, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ) {
    9394                PRINT( std::cerr << "convert to reference cost..." << std::endl; )
    9495                if ( diff > 0 ) {
    9596                        // TODO: document this
    96                         Cost cost = convertToReferenceCost( safe_dynamic_cast< ReferenceType * >( src )->get_base(), dest, diff-1, indexer, env );
     97                        Cost cost = convertToReferenceCost( safe_dynamic_cast< ReferenceType * >( src )->get_base(), dest, diff-1, indexer, env, func );
    9798                        cost.incReference();
    9899                        return cost;
    99100                } else if ( diff < -1 ) {
    100101                        // TODO: document this
    101                         Cost cost = convertToReferenceCost( src, safe_dynamic_cast< ReferenceType * >( dest )->get_base(), diff+1, indexer, env );
     102                        Cost cost = convertToReferenceCost( src, safe_dynamic_cast< ReferenceType * >( dest )->get_base(), diff+1, indexer, env, func );
    102103                        cost.incReference();
    103104                        return cost;
     
    110111                                        return Cost::safe;
    111112                                } else {  // xxx - this discards reference qualifiers from consideration -- reducing qualifiers is a safe conversion; is this right?
    112                                         int assignResult = ptrsAssignable( srcAsRef->get_base(), destAsRef->get_base(), env );
     113                                        int assignResult = func( srcAsRef->get_base(), destAsRef->get_base(), env, indexer );
    113114                                        PRINT( std::cerr << "comparing references: " << assignResult << " " << srcAsRef << " " << destAsRef << std::endl; )
    114115                                        if ( assignResult < 0 ) {
     
    157158        }
    158159
    159         Cost convertToReferenceCost( Type * src, ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env ) {
     160        Cost convertToReferenceCost( Type * src, ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ) {
    160161                int sdepth = src->referenceDepth(), ddepth = dest->referenceDepth();
    161                 return convertToReferenceCost( src, dest, sdepth-ddepth, indexer, env );
     162                return convertToReferenceCost( src, dest, sdepth-ddepth, indexer, env, func );
    162163        }
    163164
  • src/ResolvExpr/ConversionCost.h

    r2065609 r26238c1  
    1616#pragma once
    1717
     18#include <functional>         // for function
     19
    1820#include "Cost.h"             // for Cost
    1921#include "SynTree/Visitor.h"  // for Visitor
     
    2123
    2224namespace SymTab {
    23 class Indexer;
     25        class Indexer;
    2426}  // namespace SymTab
    2527
    2628namespace ResolvExpr {
    27 class TypeEnvironment;
     29        class TypeEnvironment;
    2830
    2931        class ConversionCost : public Visitor {
     
    5557        };
    5658
    57         Cost convertToReferenceCost( Type * src, ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env );
     59        typedef std::function<int(Type *, Type *, const TypeEnvironment &, const SymTab::Indexer &)> PtrsFunction;
     60        Cost convertToReferenceCost( Type * src, ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func );
    5861} // namespace ResolvExpr
    5962
  • src/SymTab/Indexer.cc

    r2065609 r26238c1  
    345345                leaveScope();
    346346
    347                 debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl );
     347                debugPrint( "Adding trait " << aggregateDecl->get_name() << std::endl );
    348348                addTrait( aggregateDecl );
    349349        }
  • src/SymTab/Validate.cc

    r2065609 r26238c1  
    467467                        return;
    468468                }
     469
     470                // handle other traits
    469471                TraitDecl *traitDecl = indexer->lookupTrait( traitInst->get_name() );
    470472                if ( ! traitDecl ) {
  • src/SynTree/Expression.cc

    r2065609 r26238c1  
    645645                }
    646646        }
     647        // ensure that StmtExpr has a result type
     648        if ( ! result ) {
     649                set_result( new VoidType( Type::Qualifiers() ) );
     650        }
    647651}
    648652StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {
  • src/tests/multiDimension.c

    r2065609 r26238c1  
    5959}
    6060
     61// ensure constructed const arrays continue to compile
     62const int global[1] = { -2 };
     63
    6164int main() {
    6265  X abc[4][4] = {
  • src/tests/switch.c

    r2065609 r26238c1  
    1010// Created On       : Tue Jul 12 06:50:22 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug  4 11:44:29 2016
    13 // Update Count     : 31
     12// Last Modified On : Sat Aug 26 10:14:21 2017
     13// Update Count     : 33
    1414//
    1515
    1616int f( int i ) { return i; }
    1717
    18 int main() {
     18int main( void ) {
    1919        int i = 0;
    2020        switch ( i ) case 3 : i = 1;
     
    100100                j = 5;
    101101        } // choose
    102 }
     102} // main
    103103
    104104// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.