Changes in / [a56767c:61f9356]


Ignore:
Location:
src
Files:
2 added
18 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    ra56767c r61f9356  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Sep 17 15:25:58 2015
    13 // Update Count     : 233
     12// Last Modified On : Thu Sep 17 15:24:08 2015
     13// Update Count     : 231
    1414//
    1515
     
    258258             
    259259                                  case OT_CALL:
    260                                   case OT_CTOR:
    261                                   case OT_DTOR:
    262                                         // there are no intrinsic definitions of the function call operator or constructors or destructors
     260                                        // there are no intrinsic definitions of the function call operator
    263261                                        assert( false );
    264262                                        break;
     
    324322             
    325323                                  case OT_CALL:
    326                                         case OT_CTOR:
    327                                         case OT_DTOR:
    328324                                        assert( false );
    329325                                        break;
  • src/CodeGen/OperatorTable.cc

    ra56767c r61f9356  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Oct 06 15:26:34 2015
    13 // Update Count     : 9
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Jun 23 17:41:14 2015
     13// Update Count     : 5
    1414//
    1515
     
    2121                const OperatorInfo tableValues[] = {
    2222                        {       "?[?]",         "",             "_operator_index",                              OT_INDEX                        },
    23                         {       "?{}",          "",             "_constructor",                                 OT_CTOR                         },
    24                         {       "^?{}",         "",             "_destructor",                                  OT_DTOR                         }, // ~?{}, -?{}, !?{}, $?{}, ??{}, ^?{}, ?destroy, ?delete
    2523                        {       "?()",          "",             "_operator_call",                               OT_CALL                         },
    2624                        {       "?++",          "++",   "_operator_postincr",                   OT_POSTFIXASSIGN        },
  • src/CodeGen/OperatorTable.h

    ra56767c r61f9356  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jun 24 16:17:57 2015
    13 // Update Count     : 5
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Jun 23 16:09:27 2015
     13// Update Count     : 3
    1414//
    1515
     
    2222        enum OperatorType {
    2323                OT_INDEX,
    24                 OT_CTOR,
    25                 OT_DTOR,
    2624                OT_CALL,
    2725                OT_PREFIX,
  • src/GenPoly/Box.cc

    ra56767c r61f9356  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jan 07 13:40:05 2016
    13 // Update Count     : 219
     12// Last Modified On : Fri Dec 18 14:53:08 2015
     13// Update Count     : 217
    1414//
    1515
     
    11391139
    11401140                                        std::list<Expression*> designators;
    1141                                         objectDecl->set_init( new SingleInit( alloc, designators, false ) ); // not constructed
     1141                                        objectDecl->set_init( new SingleInit( alloc, designators ) );
    11421142                                }
    11431143                        }
  • src/InitTweak/InitModel.cc

    ra56767c r61f9356  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // InitModel.cc --
     7// InitModel.cc -- 
    88//
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jan 07 13:38:46 2016
    13 // Update Count     : 5
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue May 19 16:37:08 2015
     13// Update Count     : 1
    1414//
    1515
     
    198198                assert(init == 0 && single != 0);
    199199                std::list< Expression * > empty;
    200                 init = new SingleInit( single->get_expr(), empty, false ); // cannot be constructed
     200                init = new SingleInit( single->get_expr(), empty );
    201201                return;
    202202        }
     
    214214                        } // if
    215215
    216                 std::list< Expression * > desig;
    217                 init = new ListInit( contents, desig, false ); // cannot be constructed
     216                init = new ListInit( contents );
    218217                return;
    219218        }
  • src/InitTweak/RemoveInit.cc

    ra56767c r61f9356  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // RemoveInit.cc --
     7// RemoveInit.cc -- 
    88//
    99// Author           : Rob Schluntz
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Jan 11 14:41:26 2016
    13 // Update Count     : 118
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Dec 15 15:37:26 2015
     13// Update Count     : 15
    1414//
    1515
    16 #include <stack>
    17 #include <list>
    1816#include "RemoveInit.h"
    1917#include "SynTree/Declaration.h"
     
    2321#include "SynTree/Initializer.h"
    2422#include "SynTree/Mutator.h"
    25 #include "GenPoly/PolyMutator.h"
    2623
    2724namespace InitTweak {
     
    2926                const std::list<Label> noLabels;
    3027        }
    31 
    32         class RemoveInit : public GenPoly::PolyMutator {
     28       
     29        class RemoveInit : public Mutator {
    3330          public:
    3431                RemoveInit();
    35                 virtual ObjectDecl * mutate( ObjectDecl *objDecl );
     32                virtual ObjectDecl * mutate(ObjectDecl *objDecl);
    3633                virtual DeclarationWithType * mutate( FunctionDecl *functionDecl );
    3734
    3835                virtual Statement * mutate( ReturnStmt * returnStmt );
     36               
     37                virtual CompoundStmt * mutate(CompoundStmt * compoundStmt);
     38               
     39          protected:
     40                std::list< Statement* > stmtsToAddBefore;
     41                std::list< Statement* > stmtsToAddAfter;
     42                void mutateStatementList( std::list< Statement* > &statements );
    3943
    40           protected:
    4144                std::list<DeclarationWithType*> returnVals;
    4245                UniqueName tempNamer;
     
    4447        };
    4548
    46         class CtorDtor : public GenPoly::PolyMutator {
    47           public:
    48                 // CtorDtor();
    49 
    50                 virtual ObjectDecl * mutate( ObjectDecl * );
    51 
    52                 virtual CompoundStmt * mutate( CompoundStmt * compoundStmt );
    53 
    54           protected:
    55                 typedef std::map< std::string, DeclarationWithType * > MMMMAP;
    56                 std::stack< MMMMAP > constructedObjects;
    57 
    58                 // to be added before block ends - use push_front so order is correct
    59                 std::list< Statement * > destructorStmts;
    60         };
    61 
    6249        void tweak( std::list< Declaration * > translationUnit ) {
    6350                RemoveInit remover;
    64                 CtorDtor ctordtor;
    6551                mutateAll( translationUnit, remover );
    66                 mutateAll( translationUnit, ctordtor );
    6752        }
    6853
    6954        RemoveInit::RemoveInit() : tempNamer( "_retVal" ) {}
     55       
     56        void RemoveInit::mutateStatementList( std::list< Statement* > &statements ) {
     57                for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
     58                        if ( ! stmtsToAddAfter.empty() ) {
     59                                statements.splice( i, stmtsToAddAfter );
     60                        } // if
     61                        *i = (*i)->acceptMutator( *this );
     62                        if ( ! stmtsToAddBefore.empty() ) {
     63                                statements.splice( i, stmtsToAddBefore );
     64                        } // if
     65                } // for
     66                if ( ! stmtsToAddAfter.empty() ) {
     67                        statements.splice( statements.end(), stmtsToAddAfter );
     68                } // if
     69        }
     70
     71        CompoundStmt *RemoveInit::mutate(CompoundStmt *compoundStmt) {
     72                mutateStatementList( compoundStmt->get_kids() );
     73                return compoundStmt;
     74        }
    7075
    7176        // in the case where an object has an initializer and a polymorphic type, insert an assignment immediately after the
     
    9095                if ( returnStmt->get_expr() && returnVals.size() == 1 && funcName != "?=?" && ! returnVals.front()->get_type()->get_isLvalue()  ) {
    9196                        ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, returnVals.front()->get_type()->clone(), 0 );
    92                         stmtsToAdd.push_back( new DeclStmt( noLabels, newObj ) );
    93 
     97                        stmtsToAddBefore.push_back( new DeclStmt( noLabels, newObj ) );
     98                       
    9499                        UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
    95100                        assign->get_args().push_back( new AddressExpr (new NameExpr( newObj->get_name() ) ) );
    96101                        assign->get_args().push_back( returnStmt->get_expr() );
    97                         stmtsToAdd.push_back(new ExprStmt(noLabels, assign));
     102                        stmtsToAddBefore.push_back(new ExprStmt(noLabels, assign));
    98103
    99104                        returnStmt->set_expr( new VariableExpr( newObj ) );
     
    105110                std::list<DeclarationWithType*> oldReturnVals = returnVals;
    106111                std::string oldFuncName = funcName;
    107 
     112               
    108113                FunctionType * type = functionDecl->get_functionType();
    109114                returnVals = type->get_returnVals();
     
    114119                return decl;
    115120        }
    116 
    117         bool tryConstruct( ObjectDecl * objDecl ) {
    118                 // xxx - handle designations
    119                 return objDecl->get_init() == NULL ||
    120                         ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() );
    121         }
    122 
    123         ExprStmt * makeCtorDtorStmt( std::string name, ObjectDecl * objDecl, std::list< Expression * > args ) {
    124                 UntypedExpr * expr = new UntypedExpr( new NameExpr( name ) );
    125                 expr->get_args().push_back( new VariableExpr( objDecl ) );
    126                 expr->get_args().splice( expr->get_args().end(), args );
    127                 return new ExprStmt( noLabels, expr );
    128         }
    129 
    130         // InitExpander ctor/dtor being marked as weak symbols
    131         // this is causing a bug - Rodolfo's InitExpander is being constructed and destructed
    132         // with different fields, which causes a segfault
    133 
    134         class InitExpander : public Visitor {
    135           public:
    136           InitExpander() {}
    137           // ~InitExpander() {}
    138                 virtual void visit( SingleInit * singleInit );
    139                 virtual void visit( ListInit * listInit );
    140                 std::list< Expression * > argList;
    141         };
    142 
    143         void InitExpander::visit( SingleInit * singleInit ) {
    144                 argList.push_back( singleInit->get_value()->clone() );
    145         }
    146 
    147         void InitExpander::visit( ListInit * listInit ) {
    148                 // xxx - for now, assume no nested list inits
    149                 std::list<Initializer*>::iterator it = listInit->begin_initializers();
    150                 for ( ; it != listInit->end_initializers(); ++it ) {
    151                         (*it)->accept( *this );
    152                 }
    153         }
    154 
    155         std::list< Expression * > makeInitList( Initializer * init ) {
    156                 if ( init ) {
    157                         InitExpander expander;
    158                         // init->accept( expander );
    159                         // std::list< Expression * > l = expander.argList;
    160                         std::list< Expression * > l;
    161                         return l;
    162                 } else {
    163                         std::list< Expression * > l;
    164                         return l;
    165                 }
    166         }
    167 
    168         ObjectDecl * CtorDtor::mutate( ObjectDecl * objDecl ) {
    169                 // hands off if designated or if @=
    170                 if ( tryConstruct( objDecl ) ) {
    171                         ExprStmt * ctor = makeCtorDtorStmt( "?{}", objDecl, makeInitList( objDecl->get_init() ) );
    172                         ExprStmt * dtor = makeCtorDtorStmt( "^?{}", objDecl, std::list< Expression * >() );
    173 
    174                         // set_ctor...
    175                         // need to remember init expression, in case no ctors exist
    176                         // if ctor does exist, want to use ctor stmt instead of init
    177                         objDecl->set_ctor( ctor );
    178                         destructorStmts.push_front( dtor );
    179                 }
    180                 return objDecl;
    181         }
    182 
    183         CompoundStmt * CtorDtor::mutate( CompoundStmt * compoundStmt ) {
    184                 CompoundStmt * ret = PolyMutator::mutate( compoundStmt );
    185                 std::list< Statement * > &statements = ret->get_kids();
    186                 if ( ! destructorStmts.empty() ) {
    187                         statements.splice( statements.end(), destructorStmts );
    188                 } // if
    189                 return ret;
    190         }
    191 
    192 
    193 
    194121} // namespace InitTweak
    195122
  • src/MakeLibCfa.cc

    ra56767c r61f9356  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // MakeLibCfa.cc --
     7// MakeLibCfa.cc -- 
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Sat May 16 10:33:33 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jan 07 13:34:39 2016
    13 // Update Count     : 20
    14 //
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Jun 26 16:52:59 2015
     13// Update Count     : 14
     14// 
    1515
    1616#include "MakeLibCfa.h"
     
    2929                void visit( FunctionDecl* funcDecl );
    3030                void visit( ObjectDecl* objDecl );
    31 
     31 
    3232                std::list< Declaration* > &get_newDecls() { return newDecls; }
    3333          private:
     
    4343        void MakeLibCfa::visit( FunctionDecl* origFuncDecl ) {
    4444                if ( origFuncDecl->get_linkage() != LinkageSpec::Intrinsic ) return;
    45 
     45 
    4646                FunctionDecl *funcDecl = origFuncDecl->clone();
    4747                CodeGen::OperatorInfo opInfo;
     
    7777                                break;
    7878                        }
    79                   case CodeGen::OT_CTOR:
    80                   case CodeGen::OT_DTOR:
    8179                  case CodeGen::OT_CONSTANT:
    8280                  case CodeGen::OT_LABELADDRESS:
     
    9997        void MakeLibCfa::visit( ObjectDecl* origObjDecl ) {
    10098                if ( origObjDecl->get_linkage() != LinkageSpec::Intrinsic ) return;
    101 
     99 
    102100                ObjectDecl *objDecl = origObjDecl->clone();
    103101                assert( ! objDecl->get_init() );
    104102                std::list< Expression* > noDesignators;
    105                 objDecl->set_init( new SingleInit( new NameExpr( objDecl->get_name() ), noDesignators, false ) ); // cannot be constructed
     103                objDecl->set_init( new SingleInit( new NameExpr( objDecl->get_name() ), noDesignators ) );
    106104                newDecls.push_back( objDecl );
    107105        }
  • src/Parser/DeclarationNode.cc

    ra56767c r61f9356  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // DeclarationNode.cc --
     7// DeclarationNode.cc -- 
    88//
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 12:34:05 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jan 07 13:18:02 2016
    13 // Update Count     : 130
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Jul 14 14:46:32 2015
     13// Update Count     : 126
    1414//
    1515
     
    9696                os << endl << string( indent + 2, ' ' ) << "with initializer ";
    9797                initializer->printOneLine( os );
    98                 os << " maybe constructed? " << initializer->get_maybeConstructed();
    99 
    10098        } // if
    10199
     
    359357        } // if
    360358}
    361 
     359         
    362360DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
    363361        if ( q ) {
     
    510508                assert( false );
    511509        } // switch
    512 
     510       
    513511        return this;
    514512}
     
    621619                assert( a->type->kind == TypeData::Array );
    622620                TypeData *lastArray = findLast( a->type );
    623                 if ( type ) {
     621                if ( type ) { 
    624622                        switch ( type->kind ) {
    625623                          case TypeData::Aggregate:
     
    665663        } // if
    666664}
    667 
     665       
    668666DeclarationNode *DeclarationNode::addIdList( DeclarationNode *ids ) {
    669667        type = addIdListToType( type, ids );
     
    870868Type *DeclarationNode::buildType() const {
    871869        assert( type );
    872 
     870 
    873871        switch ( type->kind ) {
    874872          case TypeData::Enum:
  • src/Parser/InitializerNode.cc

    ra56767c r61f9356  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // InitializerNode.cc --
    8 //
     7// InitializerNode.cc -- 
     8// 
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:20:24 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jan 07 13:32:57 2016
    13 // Update Count     : 13
    14 //
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Oct  8 17:18:55 2015
     13// Update Count     : 4
     14// 
    1515
    1616#include <cassert>
     
    2323
    2424InitializerNode::InitializerNode( ExpressionNode *_expr, bool aggrp, ExpressionNode *des )
    25         : expr( _expr ), aggregate( aggrp ), designator( des ), kids( 0 ), maybeConstructed( true ) {
     25        : expr( _expr ), aggregate( aggrp ), designator( des ), kids( 0 ) {
    2626        if ( aggrp )
    2727                kids = dynamic_cast< InitializerNode *>( get_link() );
     
    3232
    3333InitializerNode::InitializerNode( InitializerNode *init, bool aggrp, ExpressionNode *des )
    34         : expr( 0 ), aggregate( aggrp ), designator( des ), kids( 0 ), maybeConstructed( true ) {
     34        : expr( 0 ), aggregate( aggrp ), designator( des ), kids( 0 ) {
    3535        if ( init != 0 )
    3636                set_link(init);
     
    9191                } // if
    9292
    93                 return new ListInit( initlist, designlist, maybeConstructed );
     93                return new ListInit( initlist, designlist );
    9494        } else {
    9595                std::list< Expression *> designators;
     
    9999
    100100                if ( get_expression() != 0)
    101                         return new SingleInit( get_expression()->build(), designators, maybeConstructed );
     101                        return new SingleInit( get_expression()->build(), designators );
    102102        } // if
    103103
  • src/Parser/ParseNode.h

    ra56767c r61f9356  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // ParseNode.h --
     7// ParseNode.h -- 
    88//
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jan 07 13:17:46 2016
    13 // Update Count     : 177
     12// Last Modified On : Wed Aug 12 13:27:11 2015
     13// Update Count     : 172
    1414//
    1515
     
    175175  public:
    176176        enum Type { TupleC, Comma, TupleFieldSel,
    177                                 Cond, NCond,
    178                                 SizeOf, AlignOf, Attr, CompLit, Plus, Minus, Mul, Div, Mod, Or, And,
    179                                 BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq,
    180                                 Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn,
     177                                Cond, NCond, 
     178                                SizeOf, AlignOf, Attr, CompLit, Plus, Minus, Mul, Div, Mod, Or, And, 
     179                                BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq, 
     180                                Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, 
    181181                                ERAssn, OrAssn, Index, FieldSel, PFieldSel, Range,
    182                                 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress,
    183                                 Ctor, Dtor,
     182                                UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress
    184183        };
    185184
     
    307306        ValofExprNode( const ValofExprNode &other );
    308307        ~ValofExprNode();
    309 
     308 
    310309        virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); }
    311310
     
    330329        enum TypeClass { Type, Dtype, Ftype };
    331330
    332         static const char *storageName[];
     331        static const char *storageName[]; 
    333332        static const char *qualifierName[];
    334333        static const char *basicTypeName[];
     
    420419class StatementNode : public ParseNode {
    421420  public:
    422         enum Type { Exp,   If,        Switch,  Case,    Default,  Choose,   Fallthru,
     421        enum Type { Exp,   If,        Switch,  Case,    Default,  Choose,   Fallthru, 
    423422                                While, Do,        For,
    424423                                Goto,  Continue,  Break,   Return,  Throw,
     
    518517        ExpressionNode *get_designators() const { return designator; }
    519518
    520         InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; }
    521         bool get_maybeConstructed() const { return maybeConstructed; }
    522 
    523519        InitializerNode *next_init() const { return kids; }
    524520
     
    532528        ExpressionNode *designator; // may be list
    533529        InitializerNode *kids;
    534         bool maybeConstructed;
    535530};
    536531
  • src/Parser/parser.cc

    ra56767c r61f9356  
    72917291/* Line 1806 of yacc.c  */
    72927292#line 1684 "parser.yy"
    7293     { (yyval.in) = (yyvsp[(2) - (2)].in)->set_maybeConstructed( false ); }
     7293    { (yyval.in) = (yyvsp[(2) - (2)].in); }
    72947294    break;
    72957295
  • src/Parser/parser.yy

    ra56767c r61f9356  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // cfa.y --
    8 //
     7// cfa.y -- 
     8// 
    99// Author           : Peter A. Buhr
    1010// Created On       : Sat Sep  1 20:22:55 2001
     
    1212// Last Modified On : Thu Oct  8 17:17:54 2015
    1313// Update Count     : 1473
    14 //
     14// 
    1515
    1616// This grammar is based on the ANSI99/11 C grammar, specifically parts of EXPRESSION and STATEMENTS, and on the C
     
    16821682                { $$ = $2; }
    16831683        | ATassign initializer
    1684                 { $$ = $2->set_maybeConstructed( false ); }
     1684                { $$ = $2; }
    16851685        ;
    16861686
  • src/SymTab/Validate.cc

    ra56767c r61f9356  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jan 07 11:27:49 2016
    13 // Update Count     : 269
     12// Last Modified On : Fri Dec 18 15:34:05 2015
     13// Update Count     : 218
    1414//
    1515
     
    202202        };
    203203
    204         class VerifyCtorDtor : public Visitor {
    205         public:
    206                 /// ensure that constructors and destructors have at least one
    207                 /// parameter, the first of which must be a pointer, and no
    208                 /// return values.
    209                 static void verify( std::list< Declaration * > &translationUnit );
    210 
    211                 // VerifyCtorDtor() {}
    212 
    213                 virtual void visit( FunctionDecl *funcDecl );
    214         private:
    215         };
    216 
    217204        void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {
    218205                Pass1 pass1;
     
    226213                AutogenerateRoutines::autogenerateRoutines( translationUnit );
    227214                acceptAll( translationUnit, pass3 );
    228                 VerifyCtorDtor::verify( translationUnit );
    229215        }
    230216
     
    10431029        }
    10441030
    1045         void VerifyCtorDtor::verify( std::list< Declaration * > & translationUnit ) {
    1046                 VerifyCtorDtor verifier;
    1047                 acceptAll( translationUnit, verifier );
    1048         }
    1049 
    1050         void VerifyCtorDtor::visit( FunctionDecl * funcDecl ) {
    1051                 FunctionType * funcType = funcDecl->get_functionType();
    1052                 std::list< DeclarationWithType * > &returnVals = funcType->get_returnVals();
    1053                 std::list< DeclarationWithType * > &params = funcType->get_parameters();
    1054 
    1055                 if ( funcDecl->get_name() == "?{}" || funcDecl->get_name() == "^?{}" ) {
    1056                         if ( params.size() == 0 ) {
    1057                                 throw SemanticError( "Constructors and destructors require at least one parameter ", funcDecl );
    1058                         }
    1059                         if ( ! dynamic_cast< PointerType * >( params.front()->get_type() ) ) {
    1060                                 throw SemanticError( "First parameter of a constructor or destructor must be a pointer ", funcDecl );
    1061                         }
    1062                         if ( returnVals.size() != 0 ) {
    1063                                 throw SemanticError( "Constructors and destructors cannot have explicit return values ", funcDecl );
    1064                         }
    1065                 }
    1066 
    1067                 Visitor::visit( funcDecl );
    1068                 // original idea: modify signature of ctor/dtors and insert appropriate return statements
    1069                 // to cause desired behaviour
    1070                 // new idea: add comma exprs to every ctor call to produce first parameter.
    1071                 // this requires some memoization of the first parameter, because it can be a
    1072                 // complicated expression with side effects (see: malloc). idea: add temporary variable
    1073                 // that is assigned address of constructed object in ctor argument position and
    1074                 // return the temporary. It should also be done after all implicit ctors are
    1075                 // added, so not in this pass!
    1076         }
    10771031} // namespace SymTab
    10781032
  • src/SynTree/Declaration.h

    ra56767c r61f9356  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Declaration.h --
     7// Declaration.h -- 
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jan 07 14:48:44 2016
    13 // Update Count     : 34
     12// Last Modified On : Wed Dec 09 14:08:22 2015
     13// Update Count     : 32
    1414//
    1515
     
    9191        Expression *get_bitfieldWidth() const { return bitfieldWidth; }
    9292        void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; }
    93         ExprStmt * get_ctor() const { return ctor; }
    94         void set_ctor( ExprStmt * newValue ) { ctor = newValue; }
    9593
    9694        virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); }
     
    103101        Initializer *init;
    104102        Expression *bitfieldWidth;
    105         ExprStmt * ctor;
    106103};
    107104
  • src/SynTree/Initializer.cc

    ra56767c r61f9356  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Initializer.cc --
     7// Initializer.cc -- 
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jan 07 15:00:18 2016
    13 // Update Count     : 23
     12// Last Modified On : Wed Aug 12 14:05:25 2015
     13// Update Count     : 14
    1414//
    1515
     
    1818#include "utility.h"
    1919
    20 Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {}
     20Initializer::Initializer() {}
    2121
    2222Initializer::~Initializer() {}
     
    3131void Initializer::print( std::ostream &os, int indent ) {}
    3232
    33 SingleInit::SingleInit( Expression *v, std::list< Expression *> &_designators, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ), designators( _designators ) {
     33SingleInit::SingleInit( Expression *v, std::list< Expression *> &_designators ) : value ( v ), designators( _designators ) {
    3434}
    3535
    36 SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( other.value ) {
     36SingleInit::SingleInit( const SingleInit &other ) : value ( other.value ) {
    3737        cloneAll(other.designators, designators );
    3838}
     
    5454}
    5555
    56 ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators, bool maybeConstructed )
    57         : Initializer( maybeConstructed), initializers( _initializers ), designators( _designators ) {
     56ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators )
     57        : initializers( _initializers ), designators( _designators ) {
    5858}
    5959
     
    6565
    6666void ListInit::print( std::ostream &os, int indent ) {
    67         os << std::endl << std::string(indent, ' ') << "Compound initializer:  ";
     67        os << std::endl << std::string(indent, ' ') << "Compound initializer:  "; 
    6868        if ( ! designators.empty() ) {
    6969                os << std::string(indent + 2, ' ' ) << "designated by: [";
    7070                for ( std::list < Expression * >::iterator i = designators.begin();
    7171                          i != designators.end(); i++ ) {
    72                         ( *i )->print(os, indent + 4 );
     72                        ( *i )->print(os, indent + 4 ); 
    7373                } // for
    74 
     74       
    7575                os << std::string(indent + 2, ' ' ) << "]";
    7676        } // if
    7777
    78         for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ )
     78        for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ ) 
    7979                (*i)->print( os, indent + 2 );
    8080}
  • src/SynTree/Initializer.h

    ra56767c r61f9356  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Initializer.h --
     7// Initializer.h -- 
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jan 07 13:33:20 2016
    13 // Update Count     : 5
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 09:03:48 2015
     13// Update Count     : 1
    1414//
    1515
     
    2727  public:
    2828        //      Initializer( std::string _name = std::string(""), int _pos = 0 );
    29         Initializer( bool maybeConstructed );
     29        Initializer( );
    3030        virtual ~Initializer();
    3131
     
    4343        }
    4444
    45         bool get_maybeConstructed() { return maybeConstructed; }
    46 
    4745        virtual Initializer *clone() const = 0;
    4846        virtual void accept( Visitor &v ) = 0;
     
    5250        //      std::string name;
    5351        //      int pos;
    54         bool maybeConstructed;
    5552};
    5653
     
    5855class SingleInit : public Initializer {
    5956  public:
    60         SingleInit( Expression *value, std::list< Expression *> &designators, bool maybeConstructed );
     57        SingleInit( Expression *value, std::list< Expression *> &designators );
    6158        SingleInit( const SingleInit &other );
    6259        virtual ~SingleInit();
    63 
     60       
    6461        Expression *get_value() { return value; }
    6562        void set_value( Expression *newValue ) { value = newValue; }
     
    8279class ListInit : public Initializer {
    8380  public:
    84         ListInit( std::list<Initializer*> &,
    85                           std::list<Expression *> &designators, bool maybeConstructed );
     81        ListInit( std::list<Initializer*> &, 
     82                          std::list<Expression *> &designators = *(new std::list<Expression *>()) );
    8683        virtual ~ListInit();
    8784
  • src/SynTree/ObjectDecl.cc

    ra56767c r61f9356  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // ObjectDecl.cc --
     7// ObjectDecl.cc -- 
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri Jan 08 15:29:10 2016
    13 // Update Count     : 27
     12// Last Modified On : Tue Sep 29 14:13:01 2015
     13// Update Count     : 18
    1414//
    1515
     
    1919#include "Expression.h"
    2020#include "utility.h"
    21 #include "Statement.h"
    2221
    2322ObjectDecl::ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init, bool isInline, bool isNoreturn )
     
    2524        set_isInline( isInline );
    2625        set_isNoreturn( isNoreturn );
    27         set_ctor( NULL );
    2826}
    2927
    3028ObjectDecl::ObjectDecl( const ObjectDecl &other )
    31         : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ), ctor( maybeClone( other.ctor ) ) {
     29        : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) {
    3230}
    3331
     
    3634        delete init;
    3735        delete bitfieldWidth;
    38         delete ctor;
    3936}
    4037
     
    6158                os << " with initializer ";
    6259                init->print( os, indent );
    63                 os << std::string(indent, ' ') << "maybeConstructed? " << init->get_maybeConstructed();
    6460        } // if
    6561
     
    6864                bitfieldWidth->print( os );
    6965        } // if
    70 
    71         if ( ctor ) {
    72                 os << " initially constructed with ";
    73                 ctor->print( os, indent );
    74         } // if
    7566}
    7667
     
    7869#if 0
    7970        if ( get_mangleName() != "") {
    80                 os << get_mangleName() << ": ";
    81         } else
     71                os << get_mangleName() << ": "; 
     72        } else 
    8273#endif
    8374        if ( get_name() != "" ) {
  • src/initialization.txt

    ra56767c r61f9356  
    3434sure that resolved initializers for all declarations are being
    3535generated.
    36 
    37 
    38 ------
    39 
    40 More recent email: (I am quoted; Richard is the responder)
    41 > As far as I'm aware, the only way that I could currently get the correct
    42 > results from the unification engine is by feeding it an expression that
    43 > looks like "?=?( ((struct Y)x.y).a, 10 )", then picking out the pieces that
    44 > I need (namely the correct choice for a). Does this seem like a reasonable
    45 > approach to solve this problem?
    46 
    47 No, unfortunately. Initialization isn't being rewritten as assignment,
    48 so you shouldn't allow the particular selection of assignment
    49 operators that happen to be in scope (and which may include
    50 user-defined operators) to guide the type resolution.
    51 
    52 I don't think there is any way to rewrite an initializer as a single
    53 expression and have the resolver just do the right thing. I see the
    54 algorithm as:
    55 
    56 For each alternative interpretation of the designator:
    57   Construct an expression that casts the initializer to the type of
    58     the designator
    59   Construct an AlternativeFinder and use it to find the lowest cost
    60     interpretation of the expression
    61   Add this interpretation to a list of possibilities
    62 Go through the list of possibilities and pick the lowest cost
    63 
    64 As with many things in the resolver, it's conceptually simple but the
    65 implementation may be a bit of a pain. It fits in with functions like
    66 findSingleExpression, findIntegralExpression in Resolver.cc, although
    67 it will be significantly more complicated than any of the existing
    68 ones.
    69 
    70 
    71 
Note: See TracChangeset for help on using the changeset viewer.