Changeset 1a5ad8c for src/SymTab/Autogen.h
- Timestamp:
- Oct 19, 2017, 11:15:36 AM (7 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:
- f30b2610
- Parents:
- 12536d3
- git-author:
- Rob Schluntz <rschlunt@…> (10/18/17 11:45:01)
- git-committer:
- Rob Schluntz <rschlunt@…> (10/19/17 11:15:36)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Autogen.h
r12536d3 r1a5ad8c 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 … … 60 61 /// optionally returns a statement which must be inserted prior to the containing loop, if there is one 61 62 template< typename OutputIterator > 62 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 63 74 // want to be able to generate assignment, ctor, and dtor generically, 64 75 // so fname is either ?=?, ?{}, or ^?{} 65 UntypedExpr * fExpr = new UntypedExpr( new NameExpr( fname ) );76 UntypedExpr * fExpr = new UntypedExpr( new NameExpr( fname ) ); 66 77 67 78 if ( addCast ) { … … 78 89 dstParam = new CastExpr( dstParam, new ReferenceType( Type::Qualifiers(), castType ) ); 79 90 } 80 fExpr-> get_args().push_back( dstParam );91 fExpr->args.push_back( dstParam ); 81 92 82 93 Statement * listInit = srcParam.buildListInit( fExpr ); 83 94 84 std::list< Expression * > args = *++srcParam; 85 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 ); 86 106 87 107 *out++ = new ExprStmt( noLabels, fExpr ); … … 105 125 // generate: for ( int i = 0; i < N; ++i ) 106 126 begin = new ConstantExpr( Constant::from_int( 0 ) ); 107 end = array-> get_dimension()->clone();127 end = array->dimension->clone(); 108 128 cmp = new NameExpr( "?<?" ); 109 129 update = new NameExpr( "++?" ); … … 111 131 // generate: for ( int i = N-1; i >= 0; --i ) 112 132 begin = new UntypedExpr( new NameExpr( "?-?" ) ); 113 ((UntypedExpr*)begin)-> get_args().push_back( array->get_dimension()->clone() );114 ((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 ) ) ); 115 135 end = new ConstantExpr( Constant::from_int( 0 ) ); 116 136 cmp = new NameExpr( "?>=?" ); … … 121 141 122 142 UntypedExpr *cond = new UntypedExpr( cmp ); 123 cond-> get_args().push_back( new VariableExpr( index ) );124 cond-> get_args().push_back( end );143 cond->args.push_back( new VariableExpr( index ) ); 144 cond->args.push_back( end ); 125 145 126 146 UntypedExpr *inc = new UntypedExpr( update ); 127 inc-> get_args().push_back( new VariableExpr( index ) );147 inc->args.push_back( new VariableExpr( index ) ); 128 148 129 149 UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?[?]" ) ); 130 dstIndex-> get_args().push_back( dstParam );131 dstIndex-> get_args().push_back( new VariableExpr( index ) );150 dstIndex->args.push_back( dstParam ); 151 dstIndex->args.push_back( new VariableExpr( index ) ); 132 152 dstParam = dstIndex; 133 153 134 154 // srcParam must keep track of the array indices to build the 135 155 // source parameter and/or array list initializer 136 srcParam.addArrayIndex( new VariableExpr( index ), array-> get_dimension()->clone() );156 srcParam.addArrayIndex( new VariableExpr( index ), array->dimension->clone() ); 137 157 138 158 // for stmt's body, eventually containing call 139 159 CompoundStmt * body = new CompoundStmt( noLabels ); 140 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 ); 141 161 142 162 // block containing for stmt and index variable 143 163 std::list<Statement *> initList; 144 164 CompoundStmt * block = new CompoundStmt( noLabels ); 145 block-> get_kids().push_back( new DeclStmt( noLabels, index ) );165 block->push_back( new DeclStmt( noLabels, index ) ); 146 166 if ( listInit ) block->get_kids().push_back( listInit ); 147 block-> get_kids().push_back( new ForStmt( noLabels, initList, cond, inc, body ) );167 block->push_back( new ForStmt( noLabels, initList, cond, inc, body ) ); 148 168 149 169 *out++ = block; … … 151 171 152 172 template< typename OutputIterator > 153 Statement * genCall( InitTweak::InitExpander & 173 Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) { 154 174 if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) { 155 175 genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward ); … … 165 185 /// ImplicitCtorDtorStmt node. 166 186 template< typename OutputIterator > 167 void genImplicitCall( InitTweak::InitExpander & 187 void genImplicitCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, DeclarationWithType * decl, bool forward = true ) { 168 188 ObjectDecl *obj = dynamic_cast<ObjectDecl *>( decl ); 169 189 assert( obj ); … … 173 193 bool addCast = (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && ! obj->get_bitfieldWidth() ) ); 174 194 std::list< Statement * > stmts; 175 genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj-> get_type(), addCast, forward );195 genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->type, addCast, forward ); 176 196 177 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.