Changeset 0bd3faf for src/CodeGen/GenType.cc
- Timestamp:
- Nov 13, 2023, 1:40:12 PM (8 months ago)
- Branches:
- master
- Children:
- 6ea85b22
- Parents:
- 25f2798
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/GenType.cc
r25f2798 r0bd3faf 21 21 #include "AST/Print.hpp" // for print 22 22 #include "AST/Vector.hpp" // for vector 23 #include "CodeGeneratorNew.hpp" // for CodeGenerator _new23 #include "CodeGeneratorNew.hpp" // for CodeGenerator 24 24 #include "Common/UniqueName.h" // for UniqueName 25 25 … … 28 28 namespace { 29 29 30 #warning Remove the _new when old version is removed. 31 struct GenType_new : 30 struct GenType final : 32 31 public ast::WithShortCircuiting, 33 public ast::WithVisitorRef<GenType _new> {32 public ast::WithVisitorRef<GenType> { 34 33 std::string result; 35 GenType _new( const std::string &typeString, const Options &options );34 GenType( const std::string &typeString, const Options &options ); 36 35 37 36 void previsit( ast::Node const * ); … … 67 66 }; 68 67 69 GenType _new::GenType_new( const std::string &typeString, const Options &options ) : result( typeString ), options( options ) {}70 71 void GenType _new::previsit( ast::Node const * ) {68 GenType::GenType( const std::string &typeString, const Options &options ) : result( typeString ), options( options ) {} 69 70 void GenType::previsit( ast::Node const * ) { 72 71 // Turn off automatic recursion for all nodes, to allow each visitor to 73 72 // precisely control the order in which its children are visited. … … 75 74 } 76 75 77 void GenType _new::postvisit( ast::Node const * node ) {76 void GenType::postvisit( ast::Node const * node ) { 78 77 std::stringstream ss; 79 78 ast::print( ss, node ); … … 81 80 } 82 81 83 void GenType _new::postvisit( ast::VoidType const * type ) {82 void GenType::postvisit( ast::VoidType const * type ) { 84 83 result = "void " + result; 85 84 handleQualifiers( type ); 86 85 } 87 86 88 void GenType _new::postvisit( ast::BasicType const * type ) {87 void GenType::postvisit( ast::BasicType const * type ) { 89 88 ast::BasicType::Kind kind = type->kind; 90 89 assert( 0 <= kind && kind < ast::BasicType::NUMBER_OF_BASIC_TYPES ); … … 93 92 } 94 93 95 void GenType _new::genArray( const ast::CV::Qualifiers & qualifiers, ast::Type const * base, ast::Expr const *dimension, bool isVarLen, bool isStatic ) {94 void GenType::genArray( const ast::CV::Qualifiers & qualifiers, ast::Type const * base, ast::Expr const *dimension, bool isVarLen, bool isStatic ) { 96 95 std::ostringstream os; 97 96 if ( result != "" ) { … … 119 118 } 120 119 if ( dimension != 0 ) { 121 ast::Pass<CodeGenerator _new>::read( dimension, os, options );120 ast::Pass<CodeGenerator>::read( dimension, os, options ); 122 121 } else if ( isVarLen ) { 123 122 // no dimension expression on a VLA means it came in with the * token … … 131 130 } 132 131 133 void GenType _new::postvisit( ast::PointerType const * type ) {132 void GenType::postvisit( ast::PointerType const * type ) { 134 133 if ( type->isStatic || type->isVarLen || type->dimension ) { 135 134 genArray( type->qualifiers, type->base, type->dimension, type->isVarLen, type->isStatic ); … … 145 144 } 146 145 147 void GenType _new::postvisit( ast::ArrayType const * type ) {146 void GenType::postvisit( ast::ArrayType const * type ) { 148 147 genArray( type->qualifiers, type->base, type->dimension, type->isVarLen, type->isStatic ); 149 148 } 150 149 151 void GenType _new::postvisit( ast::ReferenceType const * type ) {150 void GenType::postvisit( ast::ReferenceType const * type ) { 152 151 assertf( !options.genC, "Reference types should not reach code generation." ); 153 152 handleQualifiers( type ); … … 156 155 } 157 156 158 void GenType _new::postvisit( ast::FunctionType const * type ) {157 void GenType::postvisit( ast::FunctionType const * type ) { 159 158 std::ostringstream os; 160 159 … … 196 195 //assertf( !options.genC, "FunctionDecl type parameters should not reach code generation." ); 197 196 std::ostringstream os; 198 ast::Pass<CodeGenerator _new> cg( os, options );197 ast::Pass<CodeGenerator> cg( os, options ); 199 198 os << "forall("; 200 199 cg.core.genCommaList( type->forall ); … … 204 203 } 205 204 206 std::string GenType _new::handleGeneric( ast::BaseInstType const * type ) {205 std::string GenType::handleGeneric( ast::BaseInstType const * type ) { 207 206 if ( !type->params.empty() ) { 208 207 std::ostringstream os; 209 ast::Pass<CodeGenerator _new> cg( os, options );208 ast::Pass<CodeGenerator> cg( os, options ); 210 209 os << "("; 211 210 cg.core.genCommaList( type->params ); … … 216 215 } 217 216 218 void GenType _new::postvisit( ast::StructInstType const * type ) {217 void GenType::postvisit( ast::StructInstType const * type ) { 219 218 result = type->name + handleGeneric( type ) + " " + result; 220 219 if ( options.genC ) result = "struct " + result; … … 222 221 } 223 222 224 void GenType _new::postvisit( ast::UnionInstType const * type ) {223 void GenType::postvisit( ast::UnionInstType const * type ) { 225 224 result = type->name + handleGeneric( type ) + " " + result; 226 225 if ( options.genC ) result = "union " + result; … … 228 227 } 229 228 230 void GenType _new::postvisit( ast::EnumInstType const * type ) {229 void GenType::postvisit( ast::EnumInstType const * type ) { 231 230 if ( type->base && type->base->base ) { 232 231 result = genType( type->base->base, result, options ); … … 240 239 } 241 240 242 void GenType _new::postvisit( ast::TypeInstType const * type ) {241 void GenType::postvisit( ast::TypeInstType const * type ) { 243 242 assertf( !options.genC, "TypeInstType should not reach code generation." ); 244 243 result = type->name + " " + result; … … 246 245 } 247 246 248 void GenType _new::postvisit( ast::TupleType const * type ) {247 void GenType::postvisit( ast::TupleType const * type ) { 249 248 assertf( !options.genC, "TupleType should not reach code generation." ); 250 249 unsigned int i = 0; … … 259 258 } 260 259 261 void GenType _new::postvisit( ast::VarArgsType const * type ) {260 void GenType::postvisit( ast::VarArgsType const * type ) { 262 261 result = "__builtin_va_list " + result; 263 262 handleQualifiers( type ); 264 263 } 265 264 266 void GenType _new::postvisit( ast::ZeroType const * type ) {265 void GenType::postvisit( ast::ZeroType const * type ) { 267 266 // Ideally these wouldn't hit codegen at all, but should be safe to make them ints. 268 267 result = (options.pretty ? "zero_t " : "long int ") + result; … … 270 269 } 271 270 272 void GenType _new::postvisit( ast::OneType const * type ) {271 void GenType::postvisit( ast::OneType const * type ) { 273 272 // Ideally these wouldn't hit codegen at all, but should be safe to make them ints. 274 273 result = (options.pretty ? "one_t " : "long int ") + result; … … 276 275 } 277 276 278 void GenType _new::postvisit( ast::GlobalScopeType const * type ) {277 void GenType::postvisit( ast::GlobalScopeType const * type ) { 279 278 assertf( !options.genC, "GlobalScopeType should not reach code generation." ); 280 279 handleQualifiers( type ); 281 280 } 282 281 283 void GenType _new::postvisit( ast::TraitInstType const * type ) {282 void GenType::postvisit( ast::TraitInstType const * type ) { 284 283 assertf( !options.genC, "TraitInstType should not reach code generation." ); 285 284 result = type->name + " " + result; … … 287 286 } 288 287 289 void GenType _new::postvisit( ast::TypeofType const * type ) {288 void GenType::postvisit( ast::TypeofType const * type ) { 290 289 std::ostringstream os; 291 290 os << "typeof("; 292 ast::Pass<CodeGenerator _new>::read( type, os, options );291 ast::Pass<CodeGenerator>::read( type, os, options ); 293 292 os << ") " << result; 294 293 result = os.str(); … … 296 295 } 297 296 298 void GenType _new::postvisit( ast::VTableType const * type ) {297 void GenType::postvisit( ast::VTableType const * type ) { 299 298 assertf( !options.genC, "Virtual table types should not reach code generation." ); 300 299 std::ostringstream os; … … 304 303 } 305 304 306 void GenType _new::postvisit( ast::QualifiedType const * type ) {305 void GenType::postvisit( ast::QualifiedType const * type ) { 307 306 assertf( !options.genC, "QualifiedType should not reach code generation." ); 308 307 std::ostringstream os; … … 312 311 } 313 312 314 void GenType _new::handleQualifiers( ast::Type const * type ) {313 void GenType::handleQualifiers( ast::Type const * type ) { 315 314 if ( type->is_const() ) { 316 315 result = "const " + result; … … 327 326 } 328 327 329 std::string GenType _new::genParamList( const ast::vector<ast::Type> & range ) {328 std::string GenType::genParamList( const ast::vector<ast::Type> & range ) { 330 329 auto cur = range.begin(); 331 330 auto end = range.end(); … … 346 345 std::ostringstream os; 347 346 if ( !type->attributes.empty() ) { 348 ast::Pass<CodeGenerator _new> cg( os, options );347 ast::Pass<CodeGenerator> cg( os, options ); 349 348 cg.core.genAttributes( type->attributes ); 350 349 } 351 350 352 return os.str() + ast::Pass<GenType _new>::read( type, base, options );351 return os.str() + ast::Pass<GenType>::read( type, base, options ); 353 352 } 354 353 355 354 std::string genTypeNoAttr( ast::Type const * type, const std::string & base, const Options & options ) { 356 return ast::Pass<GenType _new>::read( type, base, options );355 return ast::Pass<GenType>::read( type, base, options ); 357 356 } 358 357
Note: See TracChangeset
for help on using the changeset viewer.