Changeset 58fe85a for src/ResolvExpr/ResolveTypeof.cc
- Timestamp:
- Jan 7, 2021, 3:27:00 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 2b4daf2, 64aeca0
- Parents:
- 3c64c668 (diff), eef8dfb (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
r3c64c668 r58fe85a 15 15 16 16 #include "ResolveTypeof.h" 17 #include "RenameVars.h" 17 18 18 19 #include <cassert> // for assert … … 29 30 #include "SynTree/Mutator.h" // for Mutator 30 31 #include "SynTree/Type.h" // for TypeofType, Type 32 #include "SymTab/Mangler.h" 33 #include "InitTweak/InitTweak.h" // for isConstExpr 31 34 32 35 namespace SymTab { … … 99 102 // replace basetypeof(<enum>) by int 100 103 if ( dynamic_cast<EnumInstType*>(newType) ) { 101 Type* newerType = 102 new BasicType{ newType->get_qualifiers(), BasicType::SignedInt, 104 Type* newerType = 105 new BasicType{ newType->get_qualifiers(), BasicType::SignedInt, 103 106 newType->attributes }; 104 107 delete newType; 105 108 newType = newerType; 106 109 } 107 newType->get_qualifiers().val 110 newType->get_qualifiers().val 108 111 = ( newType->get_qualifiers().val & ~Type::Qualifiers::Mask ) | oldQuals; 109 112 } else { 110 113 newType->get_qualifiers().val |= oldQuals; 111 114 } 112 115 113 116 return newType; 114 117 } … … 120 123 ResolveTypeof_new( const ast::SymbolTable & syms ) : localSymtab( syms ) {} 121 124 122 void pre mutate( const ast::TypeofType * ) { visit_children = false; }123 124 const ast::Type * post mutate( const ast::TypeofType * typeofType ) {125 void previsit( const ast::TypeofType * ) { visit_children = false; } 126 127 const ast::Type * postvisit( const ast::TypeofType * typeofType ) { 125 128 // pass on null expression 126 129 if ( ! typeofType->expr ) return typeofType; … … 133 136 // typeof wrapping expression 134 137 ast::TypeEnvironment dummy; 135 ast::ptr< ast::Expr > newExpr = 138 ast::ptr< ast::Expr > newExpr = 136 139 resolveInVoidContext( typeofType->expr, localSymtab, dummy ); 137 140 assert( newExpr->result && ! newExpr->result->isVoid() ); … … 143 146 // replace basetypeof(<enum>) by int 144 147 if ( newType.as< ast::EnumInstType >() ) { 145 newType = new ast::BasicType{ 148 newType = new ast::BasicType{ 146 149 ast::BasicType::SignedInt, newType->qualifiers, copy(newType->attributes) }; 147 150 } 148 reset_qualifiers( 149 newType, 151 reset_qualifiers( 152 newType, 150 153 ( newType->qualifiers & ~ast::CV::EquivQualifiers ) | typeofType->qualifiers ); 151 154 } else { … … 153 156 } 154 157 155 return newType ;158 return newType.release(); 156 159 } 157 160 }; … … 161 164 ast::Pass< ResolveTypeof_new > mutator{ symtab }; 162 165 return type->accept( mutator ); 166 } 167 168 struct FixArrayDimension { 169 // should not require a mutable symbol table - prevent pass template instantiation 170 const ast::SymbolTable & _symtab; 171 FixArrayDimension(const ast::SymbolTable & symtab): _symtab(symtab) {} 172 173 const ast::ArrayType * previsit (const ast::ArrayType * arrayType) { 174 if (!arrayType->dimension) return arrayType; 175 auto mutType = mutate(arrayType); 176 ast::ptr<ast::Type> sizetype = ast::sizeType ? ast::sizeType : new ast::BasicType(ast::BasicType::LongUnsignedInt); 177 mutType->dimension = findSingleExpression(arrayType->dimension, sizetype, _symtab); 178 179 if (InitTweak::isConstExpr(mutType->dimension)) { 180 mutType->isVarLen = ast::LengthFlag::FixedLen; 181 } 182 else { 183 mutType->isVarLen = ast::LengthFlag::VariableLen; 184 } 185 return mutType; 186 } 187 }; 188 189 const ast::Type * fixArrayType( const ast::Type * type, const ast::SymbolTable & symtab) { 190 ast::Pass<FixArrayDimension> visitor {symtab}; 191 return type->accept(visitor); 192 } 193 194 const ast::ObjectDecl * fixObjectType( const ast::ObjectDecl * decl , const ast::SymbolTable & symtab ) { 195 if (!decl->isTypeFixed) { 196 auto mutDecl = mutate(decl); 197 auto resolvedType = resolveTypeof(decl->type, symtab); 198 resolvedType = fixArrayType(resolvedType, symtab); 199 mutDecl->type = resolvedType; 200 201 // check variable length if object is an array. 202 // xxx - should this be part of fixObjectType? 203 204 /* 205 if (auto arrayType = dynamic_cast<const ast::ArrayType *>(resolvedType)) { 206 auto dimExpr = findSingleExpression(arrayType->dimension, ast::sizeType, symtab); 207 if (auto varexpr = arrayType->dimension.as<ast::VariableExpr>()) {// hoisted previously 208 if (InitTweak::isConstExpr(varexpr->var.strict_as<ast::ObjectDecl>()->init)) { 209 auto mutType = mutate(arrayType); 210 mutType->isVarLen = ast::LengthFlag::VariableLen; 211 mutDecl->type = mutType; 212 } 213 } 214 } 215 */ 216 217 218 if (!mutDecl->name.empty()) 219 mutDecl->mangleName = Mangle::mangle(mutDecl); // do not mangle unnamed variables 220 221 mutDecl->type = renameTyVars(mutDecl->type, RenameMode::GEN_EXPR_ID); 222 mutDecl->isTypeFixed = true; 223 return mutDecl; 224 } 225 return decl; 163 226 } 164 227
Note:
See TracChangeset
for help on using the changeset viewer.