Changeset 3f7e12cb for src/SymTab/Autogen.h
- Timestamp:
- Nov 8, 2017, 5:43:33 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 954908d
- Parents:
- 78315272 (diff), e35f30a (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Autogen.h
r78315272 r3f7e12cb 19 19 #include <string> // for string 20 20 21 #include "CodeGen/OperatorTable.h" 21 22 #include "Common/UniqueName.h" // for UniqueName 22 23 #include "InitTweak/InitTweak.h" // for InitExpander … … 44 45 extern FunctionDecl * dereferenceOperator; 45 46 46 // temporary47 // generate the type of an assignment function for paramType 47 48 FunctionType * genAssignType( Type * paramType ); 49 50 // generate the type of a default constructor or destructor for paramType 51 FunctionType * genDefaultType( Type * paramType ); 52 53 // generate the type of a copy constructor for paramType 54 FunctionType * genCopyType( Type * paramType ); 48 55 49 56 /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls. … … 54 61 /// optionally returns a statement which must be inserted prior to the containing loop, if there is one 55 62 template< typename OutputIterator > 56 Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false ) { 63 Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression * dstParam, std::string fname, OutputIterator out, Type * type, bool addCast = false ) { 64 bool isReferenceCtorDtor = false; 65 if ( dynamic_cast< ReferenceType * >( type ) && CodeGen::isCtorDtor( fname ) ) { 66 // reference constructors are essentially application of the rebind operator. 67 // apply & to both arguments, do not need a cast 68 fname = "?=?"; 69 dstParam = new AddressExpr( dstParam ); 70 addCast = false; 71 isReferenceCtorDtor = true; 72 } 73 57 74 // want to be able to generate assignment, ctor, and dtor generically, 58 75 // so fname is either ?=?, ?{}, or ^?{} 59 UntypedExpr * fExpr = new UntypedExpr( new NameExpr( fname ) );76 UntypedExpr * fExpr = new UntypedExpr( new NameExpr( fname ) ); 60 77 61 78 if ( addCast ) { … … 72 89 dstParam = new CastExpr( dstParam, new ReferenceType( Type::Qualifiers(), castType ) ); 73 90 } 74 fExpr-> get_args().push_back( dstParam );91 fExpr->args.push_back( dstParam ); 75 92 76 93 Statement * listInit = srcParam.buildListInit( fExpr ); 77 94 78 std::list< Expression * > args = *++srcParam; 79 fExpr->get_args().splice( fExpr->get_args().end(), args ); 95 // fetch next set of arguments 96 ++srcParam; 97 98 // return if adding reference fails - will happen on default constructor and destructor 99 if ( isReferenceCtorDtor && ! srcParam.addReference() ) { 100 delete fExpr; 101 return listInit; 102 } 103 104 std::list< Expression * > args = *srcParam; 105 fExpr->args.splice( fExpr->args.end(), args ); 80 106 81 107 *out++ = new ExprStmt( noLabels, fExpr ); … … 99 125 // generate: for ( int i = 0; i < N; ++i ) 100 126 begin = new ConstantExpr( Constant::from_int( 0 ) ); 101 end = array-> get_dimension()->clone();127 end = array->dimension->clone(); 102 128 cmp = new NameExpr( "?<?" ); 103 129 update = new NameExpr( "++?" ); … … 105 131 // generate: for ( int i = N-1; i >= 0; --i ) 106 132 begin = new UntypedExpr( new NameExpr( "?-?" ) ); 107 ((UntypedExpr*)begin)-> get_args().push_back( array->get_dimension()->clone() );108 ((UntypedExpr*)begin)-> get_args().push_back( new ConstantExpr( Constant::from_int( 1 ) ) );133 ((UntypedExpr*)begin)->args.push_back( array->dimension->clone() ); 134 ((UntypedExpr*)begin)->args.push_back( new ConstantExpr( Constant::from_int( 1 ) ) ); 109 135 end = new ConstantExpr( Constant::from_int( 0 ) ); 110 136 cmp = new NameExpr( "?>=?" ); … … 115 141 116 142 UntypedExpr *cond = new UntypedExpr( cmp ); 117 cond-> get_args().push_back( new VariableExpr( index ) );118 cond-> get_args().push_back( end );143 cond->args.push_back( new VariableExpr( index ) ); 144 cond->args.push_back( end ); 119 145 120 146 UntypedExpr *inc = new UntypedExpr( update ); 121 inc-> get_args().push_back( new VariableExpr( index ) );147 inc->args.push_back( new VariableExpr( index ) ); 122 148 123 149 UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?[?]" ) ); 124 dstIndex-> get_args().push_back( dstParam );125 dstIndex-> get_args().push_back( new VariableExpr( index ) );150 dstIndex->args.push_back( dstParam ); 151 dstIndex->args.push_back( new VariableExpr( index ) ); 126 152 dstParam = dstIndex; 127 153 128 154 // srcParam must keep track of the array indices to build the 129 155 // source parameter and/or array list initializer 130 srcParam.addArrayIndex( new VariableExpr( index ), array-> get_dimension()->clone() );156 srcParam.addArrayIndex( new VariableExpr( index ), array->dimension->clone() ); 131 157 132 158 // for stmt's body, eventually containing call 133 159 CompoundStmt * body = new CompoundStmt( noLabels ); 134 Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body-> get_kids() ), array->get_base(), addCast, forward );160 Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->kids ), array->base, addCast, forward ); 135 161 136 162 // block containing for stmt and index variable 137 163 std::list<Statement *> initList; 138 164 CompoundStmt * block = new CompoundStmt( noLabels ); 139 block-> get_kids().push_back( new DeclStmt( noLabels, index ) );165 block->push_back( new DeclStmt( noLabels, index ) ); 140 166 if ( listInit ) block->get_kids().push_back( listInit ); 141 block-> get_kids().push_back( new ForStmt( noLabels, initList, cond, inc, body ) );167 block->push_back( new ForStmt( noLabels, initList, cond, inc, body ) ); 142 168 143 169 *out++ = block; … … 145 171 146 172 template< typename OutputIterator > 147 Statement * genCall( InitTweak::InitExpander & 173 Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) { 148 174 if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) { 149 175 genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward ); … … 159 185 /// ImplicitCtorDtorStmt node. 160 186 template< typename OutputIterator > 161 void genImplicitCall( InitTweak::InitExpander & 187 void genImplicitCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, DeclarationWithType * decl, bool forward = true ) { 162 188 ObjectDecl *obj = dynamic_cast<ObjectDecl *>( decl ); 163 189 assert( obj ); … … 167 193 bool addCast = (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && ! obj->get_bitfieldWidth() ) ); 168 194 std::list< Statement * > stmts; 169 genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj-> get_type(), addCast, forward );195 genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->type, addCast, forward ); 170 196 171 197 // currently genCall should produce at most one element, but if that changes then the next line needs to be updated to grab the statement which contains the call
Note:
See TracChangeset
for help on using the changeset viewer.