Changeset 21255675 for src/ResolvExpr/ResolveTypeof.cc
- Timestamp:
- Nov 11, 2020, 2:41:34 PM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 23954b6
- Parents:
- 6a8882c (diff), 4a36b344 (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/ResolvExpr/ResolveTypeof.cc
r6a8882c r21255675 29 29 #include "SynTree/Mutator.h" // for Mutator 30 30 #include "SynTree/Type.h" // for TypeofType, Type 31 #include "SymTab/Mangler.h" 32 #include "InitTweak/InitTweak.h" // for isConstExpr 31 33 32 34 namespace SymTab { … … 163 165 } 164 166 167 struct FixArrayDimension { 168 // should not require a mutable symbol table - prevent pass template instantiation 169 const ast::SymbolTable & _symtab; 170 FixArrayDimension(const ast::SymbolTable & symtab): _symtab(symtab) {} 171 172 const ast::ArrayType * previsit (const ast::ArrayType * arrayType) { 173 if (!arrayType->dimension) return arrayType; 174 auto mutType = mutate(arrayType); 175 ast::ptr<ast::Type> sizetype = ast::sizeType ? ast::sizeType : new ast::BasicType(ast::BasicType::LongUnsignedInt); 176 mutType->dimension = findSingleExpression(arrayType->dimension, sizetype, _symtab); 177 178 if (InitTweak::isConstExpr(mutType->dimension)) { 179 mutType->isVarLen = ast::LengthFlag::FixedLen; 180 } 181 else { 182 mutType->isVarLen = ast::LengthFlag::VariableLen; 183 } 184 return mutType; 185 } 186 }; 187 188 const ast::Type * fixArrayType( const ast::Type * type, const ast::SymbolTable & symtab) { 189 ast::Pass<FixArrayDimension> visitor {symtab}; 190 return type->accept(visitor); 191 } 192 193 const ast::ObjectDecl * fixObjectType( const ast::ObjectDecl * decl , const ast::SymbolTable & symtab ) { 194 if (!decl->isTypeFixed) { 195 auto mutDecl = mutate(decl); 196 auto resolvedType = resolveTypeof(decl->type, symtab); 197 resolvedType = fixArrayType(resolvedType, symtab); 198 mutDecl->type = resolvedType; 199 200 // check variable length if object is an array. 201 // xxx - should this be part of fixObjectType? 202 203 /* 204 if (auto arrayType = dynamic_cast<const ast::ArrayType *>(resolvedType)) { 205 auto dimExpr = findSingleExpression(arrayType->dimension, ast::sizeType, symtab); 206 if (auto varexpr = arrayType->dimension.as<ast::VariableExpr>()) {// hoisted previously 207 if (InitTweak::isConstExpr(varexpr->var.strict_as<ast::ObjectDecl>()->init)) { 208 auto mutType = mutate(arrayType); 209 mutType->isVarLen = ast::LengthFlag::VariableLen; 210 mutDecl->type = mutType; 211 } 212 } 213 } 214 */ 215 216 217 if (!mutDecl->name.empty()) 218 mutDecl->mangleName = Mangle::mangle(mutDecl); // do not mangle unnamed variables 219 220 mutDecl->isTypeFixed = true; 221 return mutDecl; 222 } 223 return decl; 224 } 225 165 226 } // namespace ResolvExpr 166 227
Note: See TracChangeset
for help on using the changeset viewer.