- Timestamp:
- Jun 24, 2019, 2:28:10 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 093a5d7
- Parents:
- 08c0780
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Type.hpp
r08c0780 r0f6a7752 164 164 static const char *typeNames[]; 165 165 166 BasicType( Kind k, CV::Qualifiers q = {} ) : Type(q), kind(k) {} 166 BasicType( Kind k, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} ) 167 : Type(q, std::move(as)), kind(k) {} 167 168 168 169 /// Check if this type represents an integer type -
src/ResolvExpr/ResolveTypeof.cc
r08c0780 r0f6a7752 18 18 #include <cassert> // for assert 19 19 20 #include "AST/CVQualifiers.hpp" 21 #include "AST/Node.hpp" 22 #include "AST/Pass.hpp" 23 #include "AST/Type.hpp" 24 #include "AST/TypeEnvironment.hpp" 20 25 #include "Common/PassVisitor.h" // for PassVisitor 26 #include "Common/utility.h" // for copy 21 27 #include "Resolver.h" // for resolveInVoidContext 22 28 #include "SynTree/Expression.h" // for Expression … … 42 48 } 43 49 44 class ResolveTypeof : public WithShortCircuiting {50 class ResolveTypeof_old : public WithShortCircuiting { 45 51 public: 46 ResolveTypeof ( const SymTab::Indexer &indexer ) : indexer( indexer ) {}52 ResolveTypeof_old( const SymTab::Indexer &indexer ) : indexer( indexer ) {} 47 53 void premutate( TypeofType *typeofType ); 48 54 Type * postmutate( TypeofType *typeofType ); … … 53 59 54 60 Type * resolveTypeof( Type *type, const SymTab::Indexer &indexer ) { 55 PassVisitor<ResolveTypeof > mutator( indexer );61 PassVisitor<ResolveTypeof_old> mutator( indexer ); 56 62 return type->acceptMutator( mutator ); 57 63 } 58 64 59 void ResolveTypeof ::premutate( TypeofType * ) {65 void ResolveTypeof_old::premutate( TypeofType * ) { 60 66 visit_children = false; 61 67 } 62 68 63 Type * ResolveTypeof ::postmutate( TypeofType *typeofType ) {69 Type * ResolveTypeof_old::postmutate( TypeofType *typeofType ) { 64 70 #if 0 65 71 std::cerr << "resolving typeof: "; … … 108 114 } 109 115 110 const ast::Type * resolveTypeof( const ast::Type * type , const ast::SymbolTable & symtab ) { 111 #warning unimplemented 112 (void)type; (void)symtab; 113 assert(false); 114 return nullptr; 115 } 116 namespace { 117 struct ResolveTypeof_new : public ast::WithShortCircuiting { 118 const ast::SymbolTable & localSymtab; 119 120 ResolveTypeof_new( const ast::SymbolTable & syms ) : localSymtab( syms ) {} 121 122 void premutate( const ast::TypeofType * ) { visit_children = false; } 123 124 const ast::Type * postmutate( const ast::TypeofType * typeofType ) { 125 // pass on null expression 126 if ( ! typeofType->expr ) return typeofType; 127 128 ast::ptr< ast::Type > newType; 129 if ( auto tyExpr = typeofType->expr.as< ast::TypeExpr >() ) { 130 // typeof wrapping type 131 newType = tyExpr->type; 132 } else { 133 // typeof wrapping expression 134 ast::TypeEnvironment dummy; 135 ast::ptr< ast::Expr > newExpr = 136 resolveInVoidContext( typeofType->expr, localSymtab, dummy ); 137 assert( newExpr->result && ! newExpr->result->isVoid() ); 138 newType = newExpr->result; 139 } 140 141 // clear qualifiers for base, combine with typeoftype quals regardless 142 if ( typeofType->kind == ast::TypeofType::Basetypeof ) { 143 // replace basetypeof(<enum>) by int 144 if ( newType.as< ast::EnumInstType >() ) { 145 newType = new ast::BasicType{ 146 ast::BasicType::SignedInt, newType->qualifiers, copy(newType->attributes) }; 147 } 148 reset_qualifiers( 149 newType, 150 ( newType->qualifiers & ~ast::CV::EquivQualifiers ) | typeofType->qualifiers ); 151 } else { 152 add_qualifiers( newType, typeofType->qualifiers ); 153 } 154 155 return newType; 156 } 157 }; 158 } // anonymous namespace 159 160 const ast::Type * resolveTypeof( const ast::Type * type , const ast::SymbolTable & symtab ) { 161 ast::Pass< ResolveTypeof_new > mutator{ symtab }; 162 return type->accept( mutator ); 163 } 164 116 165 } // namespace ResolvExpr 117 166 -
src/ResolvExpr/Resolver.cc
r08c0780 r0f6a7752 1226 1226 const ast::StaticAssertDecl * previsit( const ast::StaticAssertDecl * ); 1227 1227 1228 voidprevisit( const ast::ArrayType * );1229 voidprevisit( const ast::PointerType * );1228 const ast::ArrayType * previsit( const ast::ArrayType * ); 1229 const ast::PointerType * previsit( const ast::PointerType * ); 1230 1230 1231 1231 const ast::ExprStmt * previsit( const ast::ExprStmt * ); … … 1334 1334 1335 1335 template< typename PtrType > 1336 void handlePtrType( const PtrType * type, const ast::SymbolTable & symtab ) { 1337 #warning unimplemented; needs support for new Validate::SizeType global 1338 (void)type; (void)symtab; 1339 assert( false ); 1340 } 1341 1342 void Resolver_new::previsit( const ast::ArrayType * at ) { 1343 handlePtrType( at, symtab ); 1344 } 1345 1346 void Resolver_new::previsit( const ast::PointerType * pt ) { 1347 handlePtrType( pt, symtab ); 1336 const PtrType * handlePtrType( const PtrType * type, const ast::SymbolTable & symtab ) { 1337 if ( type->dimension ) { 1338 #warning should use new equivalent to Validate::SizeType rather than sizeType here 1339 ast::ptr< ast::Type > sizeType = 1340 new ast::BasicType{ ast::BasicType::LongLongUnsignedInt }; 1341 ast::mutate_field( 1342 type, &PtrType::dimension, 1343 findSingleExpression( type->dimension, sizeType, symtab ) ); 1344 } 1345 return type; 1346 } 1347 1348 const ast::ArrayType * Resolver_new::previsit( const ast::ArrayType * at ) { 1349 return handlePtrType( at, symtab ); 1350 } 1351 1352 const ast::PointerType * Resolver_new::previsit( const ast::PointerType * pt ) { 1353 return handlePtrType( pt, symtab ); 1348 1354 } 1349 1355
Note: See TracChangeset
for help on using the changeset viewer.