Changeset 4d2434a for src/SymTab
- Timestamp:
- Aug 2, 2016, 6:37:08 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 8a443f4
- Parents:
- 39f84a4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Autogen.h
r39f84a4 r4d2434a 37 37 /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls. 38 38 template< typename OutputIterator > 39 void genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool forward = true );39 void genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false, bool forward = true ); 40 40 41 41 /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Should only be called with non-array types. 42 42 template< typename OutputIterator > 43 void genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out ) {43 void genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false ) { 44 44 // want to be able to generate assignment, ctor, and dtor generically, 45 45 // so fname is either ?=?, ?{}, or ^?{} … … 47 47 48 48 // do something special for unnamed members 49 fExpr->get_args().push_back( new AddressExpr( dstParam ) ); 49 dstParam = new AddressExpr( dstParam ); 50 if ( addCast ) { 51 // cast to T* with qualifiers removed, so that qualified objects can be constructed 52 // and destructed with the same functions as non-qualified objects. 53 // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument 54 // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever 55 // remove lvalue as a qualifier, this can change to 56 // type->get_qualifiers() = Type::Qualifiers(); 57 assert( type ); 58 Type * castType = type->clone(); 59 castType->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, true); 60 castType->set_isLvalue( true ); // xxx - might not need this 61 dstParam = new CastExpr( dstParam, new PointerType( Type::Qualifiers(), castType ) ); 62 } 63 fExpr->get_args().push_back( dstParam ); 50 64 51 65 Statement * listInit = srcParam.buildListInit( fExpr ); … … 56 70 std::list< Expression * > args = *++srcParam; 57 71 fExpr->get_args().splice( fExpr->get_args().end(), args ); 58 /* if ( srcParam ) { 59 // xxx - 60 // make srcParam more complicated 61 // if srcParam contains 62 fExpr->get_args().push_back( srcParam ); 63 } 64 */ 72 65 73 *out++ = new ExprStmt( noLabels, fExpr ); 74 75 srcParam.clearArrayIndices(); 66 76 } 67 77 … … 69 79 /// If forward is true, loop goes from 0 to N-1, else N-1 to 0 70 80 template< typename OutputIterator > 71 void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, bool forward = true ) {81 void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, bool addCast = false, bool forward = true ) { 72 82 static UniqueName indexName( "_index" ); 73 83 … … 124 134 // for stmt's body, eventually containing call 125 135 CompoundStmt * body = new CompoundStmt( noLabels ); 126 genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), forward );136 genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), addCast, forward ); 127 137 128 138 // block containing for stmt and index variable … … 136 146 137 147 template< typename OutputIterator > 138 void genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool forward ) {148 void genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) { 139 149 if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) { 140 genArrayCall( srcParam, dstParam, fname, out, at, forward );150 genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward ); 141 151 } else { 142 genScalarCall( srcParam, dstParam, fname, out );152 genScalarCall( srcParam, dstParam, fname, out, type, addCast ); 143 153 } 144 154 } … … 155 165 if ( isUnnamedBitfield( obj ) ) return; 156 166 167 bool addCast = (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && obj->get_bitfieldWidth() == NULL ) ); 157 168 std::list< Statement * > stmts; 158 genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->get_type(), forward );169 genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->get_type(), addCast, forward ); 159 170 160 171 // 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 … … 162 173 if ( stmts.size() == 1 ) { 163 174 Statement * callStmt = stmts.front(); 164 if ( (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && obj->get_bitfieldWidth() == NULL ) )) {175 if ( addCast ) { 165 176 // implicitly generated ctor/dtor calls should be wrapped 166 177 // so that later passes are aware they were generated.
Note: See TracChangeset
for help on using the changeset viewer.