Changes in / [946bcca:615a096]


Ignore:
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • doc/LaTeXmacros/common.tex

    r946bcca r615a096  
    4040\newcommand{\CC}{\rm C\kern-.1em\hbox{+\kern-.25em+}\xspace} % CC symbolic name
    4141\newcommand{\CCeleven}{\rm C\kern-.1em\hbox{+\kern-.25em+}11\xspace} % C++11 symbolic name
    42 \newcommand{\CCfourteen}{\rm C\kern-.1em\hbox{+\kern-.25em+}14\xspace} % C++14 symbolic name
    4342\newcommand{\CCseventeen}{\rm C\kern-.1em\hbox{+\kern-.25em+}17\xspace} % C++17 symbolic name
    4443\newcommand{\Celeven}{C11\xspace}               % C11 symbolic name
  • src/InitTweak/FixInit.cc

    r946bcca r615a096  
    232232                        void handleFirstParam( Expression * firstParam );
    233233                        template< typename... Params >
    234                         void emit( CodeLocation, const Params &... params );
     234                        void emit( const Params &... params );
    235235
    236236                        FunctionDecl * function = 0;
    237                         std::set< DeclarationWithType * > unhandled;
    238                         std::map< DeclarationWithType *, CodeLocation > usedUninit;
     237                        std::set< DeclarationWithType * > unhandled, usedUninit;
    239238                        ObjectDecl * thisParam = 0;
    240239                        bool isCtor = false; // true if current function is a constructor
     
    337336                        GenStructMemberCalls warner;
    338337                        acceptAll( translationUnit, warner );
     338
     339                        // visitor doesn't throw so that it can collect all errors
     340                        if ( ! warner.errors.isEmpty() ) {
     341                                throw warner.errors;
     342                        }
    339343                }
    340344
     
    936940                        ValueGuard< FunctionDecl * > oldFunction( funcDecl );
    937941                        ValueGuard< std::set< DeclarationWithType * > > oldUnhandled( unhandled );
    938                         ValueGuard< std::map< DeclarationWithType *, CodeLocation > > oldUsedUninit( usedUninit );
     942                        ValueGuard< std::set< DeclarationWithType * > > oldUsedUninit( usedUninit );
    939943                        ValueGuard< ObjectDecl * > oldThisParam( thisParam );
    940944                        ValueGuard< bool > oldIsCtor( isCtor );
    941945                        ValueGuard< StructDecl * > oldStructDecl( structDecl );
    942                         errors = SemanticError();  // clear previous errors
    943946
    944947                        // need to start with fresh sets
     
    969972                        // remove the unhandled objects from usedUninit, because a call is inserted
    970973                        // to handle them - only objects that are later constructed are used uninitialized.
    971                         std::map< DeclarationWithType *, CodeLocation > diff;
    972                         // need the comparator since usedUninit and unhandled have different types
    973                         struct comp_t {
    974                                 typedef decltype(usedUninit)::value_type usedUninit_t;
    975                                 typedef decltype(unhandled)::value_type unhandled_t;
    976                                 bool operator()(usedUninit_t x, unhandled_t y) { return x.first < y; }
    977                                 bool operator()(unhandled_t x, usedUninit_t y) { return x < y.first; }
    978                         } comp;
    979                         std::set_difference( usedUninit.begin(), usedUninit.end(), unhandled.begin(), unhandled.end(), std::inserter( diff, diff.begin() ), comp );
    980                         for ( auto p : diff ) {
    981                                 DeclarationWithType * member = p.first;
    982                                 CodeLocation loc = p.second;
    983                                 // xxx - make error message better by also tracking the location that the object is constructed at?
    984                                 emit( loc, "in ", CodeGen::genPrettyType( function->get_functionType(), function->get_name() ), ", field ", member->get_name(), " used before being constructed" );
     974                        std::set< DeclarationWithType * > diff;
     975                        std::set_difference( usedUninit.begin(), usedUninit.end(), unhandled.begin(), unhandled.end(), std::inserter( diff, diff.begin() ) );
     976                        for ( DeclarationWithType * member : diff ) {
     977                                emit( "in ", CodeGen::genPrettyType( function->get_functionType(), function->get_name() ), ", field ", member->get_name(), " used before being constructed" );
    985978                        }
    986979
     
    10271020                                                        }
    10281021                                                } catch ( SemanticError & error ) {
    1029                                                         emit( funcDecl->location, "in ", CodeGen::genPrettyType( function->get_functionType(), function->get_name() ), ", field ", field->get_name(), " not explicitly ", isCtor ? "constructed" : "destructed",  " and no ", isCtor ? "default constructor" : "destructor", " found" );
     1022                                                        emit( "in ", CodeGen::genPrettyType( function->get_functionType(), function->get_name() ), ", field ", field->get_name(), " not explicitly ", isCtor ? "constructed" : "destructed",  " and no ", isCtor ? "default constructor" : "destructor", " found" );
    10301023                                                }
    10311024                                        }
    10321025                                }
    10331026                                leaveScope();
    1034                         }
    1035                         if (! errors.isEmpty()) {
    1036                                 throw errors;
    10371027                        }
    10381028                }
     
    10891079                                                        if ( unhandled.count( memberExpr->get_member() ) ) {
    10901080                                                                // emit a warning because a member was used before it was constructed
    1091                                                                 usedUninit.insert( { memberExpr->get_member(), memberExpr->location } );
     1081                                                                usedUninit.insert( memberExpr->get_member() );
    10921082                                                        }
    10931083                                                }
     
    10991089
    11001090                template< typename Visitor, typename... Params >
    1101                 void error( Visitor & v, CodeLocation loc, const Params &... params ) {
    1102                         SemanticError err( toString( params... ) );
    1103                         err.set_location( loc );
    1104                         v.errors.append( err );
     1091                void error( Visitor & v, const Params &... params ) {
     1092                        v.errors.append( toString( params... ) );
    11051093                }
    11061094
    11071095                template< typename... Params >
    1108                 void GenStructMemberCalls::emit( CodeLocation loc, const Params &... params ) {
     1096                void GenStructMemberCalls::emit( const Params &... params ) {
    11091097                        // toggle warnings vs. errors here.
    11101098                        // warn( params... );
    1111                         error( *this, loc, params... );
     1099                        error( *this, params... );
    11121100                }
    11131101
  • src/Parser/ExpressionNode.cc

    r946bcca r615a096  
    254254Expression *build_pfieldSel( ExpressionNode *expr_node, Expression *member ) {
    255255        UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    256         deref->location = expr_node->location;
    257256        deref->get_args().push_back( maybeMoveBuild< Expression >(expr_node) );
    258257        UntypedMemberExpr *ret = new UntypedMemberExpr( member, deref );
  • src/Parser/ParseNode.h

    r946bcca r615a096  
    134134                        Expression * p = orig->build();
    135135                        p->set_extension( orig->get_extension() );
    136                         p->location = orig->location;
    137136                        return p;
    138137                } else {
  • src/ResolvExpr/AlternativeFinder.cc

    r946bcca r615a096  
    200200                }
    201201
    202                 // Central location to handle gcc extension keyword, etc. for all expression types.
     202                // Central location to handle gcc extension keyword for all expression types.
    203203                for ( Alternative &iter: alternatives ) {
    204204                        iter.expr->set_extension( expr->get_extension() );
    205                         iter.expr->location = expr->location;
    206205                } // for
    207206        }
  • src/SynTree/Declaration.cc

    r946bcca r615a096  
    3232
    3333Declaration::Declaration( const Declaration &other )
    34         : BaseSyntaxNode( other ), name( other.name ), storageClasses( other.storageClasses ), linkage( other.linkage ), uniqueId( other.uniqueId ) {
     34        : name( other.name ), storageClasses( other.storageClasses ), linkage( other.linkage ), uniqueId( other.uniqueId ) {
    3535}
    3636
  • src/SynTree/Expression.cc

    r946bcca r615a096  
    3333Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {}
    3434
    35 Expression::Expression( const Expression &other ) : BaseSyntaxNode( other ), result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) {
     35Expression::Expression( const Expression &other ) : result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) {
    3636}
    3737
  • src/SynTree/Initializer.cc

    r946bcca r615a096  
    2020
    2121Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {}
    22 Initializer::Initializer( const Initializer & other ) : BaseSyntaxNode( other ), maybeConstructed( other.maybeConstructed ) {
     22Initializer::Initializer( const Initializer & other ) : maybeConstructed( other.maybeConstructed ) {
    2323}
    2424
  • src/SynTree/Initializer.h

    r946bcca r615a096  
    112112// ConstructorInit represents an initializer that is either a constructor expression or
    113113// a C-style initializer.
    114 // It should not be necessary to create ConstructorInit nodes manually. Instead, set maybeConstructed
    115 // to true on SingleInit or ListInit constructors if object should be constructed.
    116114class ConstructorInit : public Initializer {
    117115  public:
  • src/SynTree/Type.cc

    r946bcca r615a096  
    5050Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {}
    5151
    52 Type::Type( const Type &other ) : BaseSyntaxNode( other ), tq( other.tq ) {
     52Type::Type( const Type &other ) : tq( other.tq ) {
    5353        cloneAll( other.forall, forall );
    5454        cloneAll( other.attributes, attributes );
     
    8484                printAll( attributes, os, indent+4 );
    8585        } // if
    86 
     86       
    8787        tq.print( os );
    8888}
  • src/Tuples/TupleExpansion.cc

    r946bcca r615a096  
    126126                /// given a expression representing the member and an expression representing the aggregate,
    127127                /// reconstructs a flattened UntypedMemberExpr with the right precedence
    128                 Expression * reconstructMemberExpr( Expression * member, Expression * aggr, CodeLocation & loc ) {
     128                Expression * reconstructMemberExpr( Expression * member, Expression * aggr ) {
    129129                        if ( UntypedMemberExpr * memberExpr = dynamic_cast< UntypedMemberExpr * >( member ) ) {
    130130                                // construct a new UntypedMemberExpr with the correct structure , and recursively
    131131                                // expand that member expression.
    132132                                MemberTupleExpander expander;
    133                                 UntypedMemberExpr * inner = new UntypedMemberExpr( memberExpr->get_aggregate(), aggr->clone() );
    134                                 UntypedMemberExpr * newMemberExpr = new UntypedMemberExpr( memberExpr->get_member(), inner );
    135                                 inner->location = newMemberExpr->location = loc;
     133                                UntypedMemberExpr * newMemberExpr = new UntypedMemberExpr( memberExpr->get_member(), new UntypedMemberExpr( memberExpr->get_aggregate(), aggr->clone() ) );
     134
    136135                                memberExpr->set_member(nullptr);
    137136                                memberExpr->set_aggregate(nullptr);
     
    140139                        } else {
    141140                                // not a member expression, so there is nothing to do but attach and return
    142                                 UntypedMemberExpr * newMemberExpr = new UntypedMemberExpr( member, aggr->clone() );
    143                                 newMemberExpr->location = loc;
    144                                 return newMemberExpr;
     141                                return new UntypedMemberExpr( member, aggr->clone() );
    145142                        }
    146143                }
     
    155152                        aggr = new UniqueExpr( aggr );
    156153                        for ( Expression *& expr : tupleExpr->get_exprs() ) {
    157                                 expr = reconstructMemberExpr( expr, aggr, memberExpr->location );
    158                                 expr->location = memberExpr->location;
     154                                expr = reconstructMemberExpr( expr, aggr );
    159155                        }
    160156                        delete aggr;
    161                         tupleExpr->location = memberExpr->location;
    162157                        return tupleExpr;
    163158                } else {
    164159                        // there may be a tuple expr buried in the aggregate
    165160                        // xxx - this is a memory leak
    166                         UntypedMemberExpr * newMemberExpr = new UntypedMemberExpr( memberExpr->get_member()->clone(), memberExpr->get_aggregate()->acceptMutator( *this ) );
    167                         newMemberExpr->location = memberExpr->location;
    168                         return newMemberExpr;
     161                        return new UntypedMemberExpr( memberExpr->get_member()->clone(), memberExpr->get_aggregate()->acceptMutator( *this ) );
    169162                }
    170163        }
  • src/tests/.expect/memberCtors-ERR1.txt

    r946bcca r615a096  
    1 memberCtors.c:62 error: in void ?{}(struct B *b), field a2 used before being constructed
     1error: in void ?{}(struct B *b), field a2 used before being constructed
    22make: *** [memberCtors-ERR1] Error 1
Note: See TracChangeset for help on using the changeset viewer.