Changeset f9cebb5 for src/InitTweak/InitTweak.cc
- Timestamp:
- Aug 4, 2016, 4:10:06 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:
- 4819cac
- Parents:
- 73bf8cf2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitTweak.cc
r73bf8cf2 rf9cebb5 5 5 #include "SynTree/Initializer.h" 6 6 #include "SynTree/Expression.h" 7 #include "SynTree/Attribute.h" 7 8 #include "GenPoly/GenPoly.h" 8 9 … … 125 126 126 127 namespace { 128 /// given index i, dimension d, initializer init, and callExpr f, generates 129 /// if (i < d) f(..., init) 130 /// ++i; 131 /// so that only elements within the range of the array are constructed 127 132 template< typename OutIterator > 128 void dothething( UntypedExpr * callExpr, Expression * index, Expression * dimension, Initializer * init, OutIterator out ) {133 void buildCallExpr( UntypedExpr * callExpr, Expression * index, Expression * dimension, Initializer * init, OutIterator out ) { 129 134 UntypedExpr * cond = new UntypedExpr( new NameExpr( "?<?") ); 130 135 cond->get_args().push_back( index->clone() ); … … 148 153 Expression * dimension = *idx++; 149 154 155 // xxx - may want to eventually issue a warning here if we can detect 156 // that the number of elements exceeds to dimension of the array 150 157 if ( idx == idxEnd ) { 151 158 if ( ListInit * listInit = dynamic_cast< ListInit * >( init ) ) { 152 159 for ( Initializer * init : *listInit ) { 153 dothething( callExpr->clone(), index, dimension, init, out );160 buildCallExpr( callExpr->clone(), index, dimension, init, out ); 154 161 } 155 162 } else { 156 dothething( callExpr->clone(), index, dimension, init, out );163 buildCallExpr( callExpr->clone(), index, dimension, init, out ); 157 164 } 158 165 } else { … … 166 173 throw SemanticError( "unbalanced list initializers" ); 167 174 } 175 176 static UniqueName targetLabel( "L__autogen__" ); 177 Label switchLabel( targetLabel.newName(), 0, std::list< Attribute * >{ new Attribute("unused") } ); 168 178 for ( Initializer * init : *listInit ) { 169 179 Expression * condition; … … 178 188 std::list< Statement * > stmts; 179 189 build( callExpr, idx, idxEnd, init, back_inserter( stmts ) ); 190 stmts.push_back( new BranchStmt( noLabels, switchLabel, BranchStmt::Break ) ); 180 191 CaseStmt * caseStmt = new CaseStmt( noLabels, condition, stmts ); 181 192 branches.push_back( caseStmt ); 182 193 } 183 194 *out++ = new SwitchStmt( noLabels, index->clone(), branches ); 195 *out++ = new NullStmt( std::list<Label>{ switchLabel } ); 184 196 } 185 197 } … … 194 206 Statement * InitImpl::buildListInit( UntypedExpr * dst, std::list< Expression * > & indices ) { 195 207 if ( ! init ) return NULL; 196 std::list< Statement * > results;197 build( dst, indices.begin(), indices.end(), init, back_inserter( results) );198 assert( results.size() <= 1 );199 if ( results.empty() ) {208 CompoundStmt * block = new CompoundStmt( noLabels ); 209 build( dst, indices.begin(), indices.end(), init, back_inserter( block->get_kids() ) ); 210 if ( block->get_kids().empty() ) { 211 delete block; 200 212 return NULL; 201 213 } else { 202 214 init = NULL; // init was consumed in creating the list init 203 return results.front(); 204 } 205 return ! results.empty() ? results.front() : NULL; 215 return block; 216 } 206 217 } 207 218 … … 280 291 } 281 292 282 bool isIn strinsicSingleArgCallStmt( Statement * stmt ) {293 bool isIntrinsicSingleArgCallStmt( Statement * stmt ) { 283 294 std::list< Expression * > callExprs; 284 295 collectCtorDtorCalls( stmt, callExprs );
Note: See TracChangeset
for help on using the changeset viewer.