Ignore:
Timestamp:
Nov 13, 2023, 1:40:12 PM (8 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
6ea85b22
Parents:
25f2798
Message:

Removed forward declarations missed in the BaseSyntaxNode? removal. Removed code and modified names to support two versions of the ast.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/GenType.cc

    r25f2798 r0bd3faf  
    2121#include "AST/Print.hpp"          // for print
    2222#include "AST/Vector.hpp"         // for vector
    23 #include "CodeGeneratorNew.hpp"   // for CodeGenerator_new
     23#include "CodeGeneratorNew.hpp"   // for CodeGenerator
    2424#include "Common/UniqueName.h"    // for UniqueName
    2525
     
    2828namespace {
    2929
    30 #warning Remove the _new when old version is removed.
    31 struct GenType_new :
     30struct GenType final :
    3231                public ast::WithShortCircuiting,
    33                 public ast::WithVisitorRef<GenType_new> {
     32                public ast::WithVisitorRef<GenType> {
    3433        std::string result;
    35         GenType_new( const std::string &typeString, const Options &options );
     34        GenType( const std::string &typeString, const Options &options );
    3635
    3736        void previsit( ast::Node const * );
     
    6766};
    6867
    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 * ) {
     68GenType::GenType( const std::string &typeString, const Options &options ) : result( typeString ), options( options ) {}
     69
     70void GenType::previsit( ast::Node const * ) {
    7271        // Turn off automatic recursion for all nodes, to allow each visitor to
    7372        // precisely control the order in which its children are visited.
     
    7574}
    7675
    77 void GenType_new::postvisit( ast::Node const * node ) {
     76void GenType::postvisit( ast::Node const * node ) {
    7877        std::stringstream ss;
    7978        ast::print( ss, node );
     
    8180}
    8281
    83 void GenType_new::postvisit( ast::VoidType const * type ) {
     82void GenType::postvisit( ast::VoidType const * type ) {
    8483        result = "void " + result;
    8584        handleQualifiers( type );
    8685}
    8786
    88 void GenType_new::postvisit( ast::BasicType const * type ) {
     87void GenType::postvisit( ast::BasicType const * type ) {
    8988        ast::BasicType::Kind kind = type->kind;
    9089        assert( 0 <= kind && kind < ast::BasicType::NUMBER_OF_BASIC_TYPES );
     
    9392}
    9493
    95 void GenType_new::genArray( const ast::CV::Qualifiers & qualifiers, ast::Type const * base, ast::Expr const *dimension, bool isVarLen, bool isStatic ) {
     94void GenType::genArray( const ast::CV::Qualifiers & qualifiers, ast::Type const * base, ast::Expr const *dimension, bool isVarLen, bool isStatic ) {
    9695        std::ostringstream os;
    9796        if ( result != "" ) {
     
    119118        }
    120119        if ( dimension != 0 ) {
    121                 ast::Pass<CodeGenerator_new>::read( dimension, os, options );
     120                ast::Pass<CodeGenerator>::read( dimension, os, options );
    122121        } else if ( isVarLen ) {
    123122                // no dimension expression on a VLA means it came in with the * token
     
    131130}
    132131
    133 void GenType_new::postvisit( ast::PointerType const * type ) {
     132void GenType::postvisit( ast::PointerType const * type ) {
    134133        if ( type->isStatic || type->isVarLen || type->dimension ) {
    135134                genArray( type->qualifiers, type->base, type->dimension, type->isVarLen, type->isStatic );
     
    145144}
    146145
    147 void GenType_new::postvisit( ast::ArrayType const * type ) {
     146void GenType::postvisit( ast::ArrayType const * type ) {
    148147        genArray( type->qualifiers, type->base, type->dimension, type->isVarLen, type->isStatic );
    149148}
    150149
    151 void GenType_new::postvisit( ast::ReferenceType const * type ) {
     150void GenType::postvisit( ast::ReferenceType const * type ) {
    152151        assertf( !options.genC, "Reference types should not reach code generation." );
    153152        handleQualifiers( type );
     
    156155}
    157156
    158 void GenType_new::postvisit( ast::FunctionType const * type ) {
     157void GenType::postvisit( ast::FunctionType const * type ) {
    159158        std::ostringstream os;
    160159
     
    196195                //assertf( !options.genC, "FunctionDecl type parameters should not reach code generation." );
    197196                std::ostringstream os;
    198                 ast::Pass<CodeGenerator_new> cg( os, options );
     197                ast::Pass<CodeGenerator> cg( os, options );
    199198                os << "forall(";
    200199                cg.core.genCommaList( type->forall );
     
    204203}
    205204
    206 std::string GenType_new::handleGeneric( ast::BaseInstType const * type ) {
     205std::string GenType::handleGeneric( ast::BaseInstType const * type ) {
    207206        if ( !type->params.empty() ) {
    208207                std::ostringstream os;
    209                 ast::Pass<CodeGenerator_new> cg( os, options );
     208                ast::Pass<CodeGenerator> cg( os, options );
    210209                os << "(";
    211210                cg.core.genCommaList( type->params );
     
    216215}
    217216
    218 void GenType_new::postvisit( ast::StructInstType const * type )  {
     217void GenType::postvisit( ast::StructInstType const * type )  {
    219218        result = type->name + handleGeneric( type ) + " " + result;
    220219        if ( options.genC ) result = "struct " + result;
     
    222221}
    223222
    224 void GenType_new::postvisit( ast::UnionInstType const * type ) {
     223void GenType::postvisit( ast::UnionInstType const * type ) {
    225224        result = type->name + handleGeneric( type ) + " " + result;
    226225        if ( options.genC ) result = "union " + result;
     
    228227}
    229228
    230 void GenType_new::postvisit( ast::EnumInstType const * type ) {
     229void GenType::postvisit( ast::EnumInstType const * type ) {
    231230        if ( type->base && type->base->base ) {
    232231                result = genType( type->base->base, result, options );
     
    240239}
    241240
    242 void GenType_new::postvisit( ast::TypeInstType const * type ) {
     241void GenType::postvisit( ast::TypeInstType const * type ) {
    243242        assertf( !options.genC, "TypeInstType should not reach code generation." );
    244243        result = type->name + " " + result;
     
    246245}
    247246
    248 void GenType_new::postvisit( ast::TupleType const * type ) {
     247void GenType::postvisit( ast::TupleType const * type ) {
    249248        assertf( !options.genC, "TupleType should not reach code generation." );
    250249        unsigned int i = 0;
     
    259258}
    260259
    261 void GenType_new::postvisit( ast::VarArgsType const * type ) {
     260void GenType::postvisit( ast::VarArgsType const * type ) {
    262261        result = "__builtin_va_list " + result;
    263262        handleQualifiers( type );
    264263}
    265264
    266 void GenType_new::postvisit( ast::ZeroType const * type ) {
     265void GenType::postvisit( ast::ZeroType const * type ) {
    267266        // Ideally these wouldn't hit codegen at all, but should be safe to make them ints.
    268267        result = (options.pretty ? "zero_t " : "long int ") + result;
     
    270269}
    271270
    272 void GenType_new::postvisit( ast::OneType const * type ) {
     271void GenType::postvisit( ast::OneType const * type ) {
    273272        // Ideally these wouldn't hit codegen at all, but should be safe to make them ints.
    274273        result = (options.pretty ? "one_t " : "long int ") + result;
     
    276275}
    277276
    278 void GenType_new::postvisit( ast::GlobalScopeType const * type ) {
     277void GenType::postvisit( ast::GlobalScopeType const * type ) {
    279278        assertf( !options.genC, "GlobalScopeType should not reach code generation." );
    280279        handleQualifiers( type );
    281280}
    282281
    283 void GenType_new::postvisit( ast::TraitInstType const * type ) {
     282void GenType::postvisit( ast::TraitInstType const * type ) {
    284283        assertf( !options.genC, "TraitInstType should not reach code generation." );
    285284        result = type->name + " " + result;
     
    287286}
    288287
    289 void GenType_new::postvisit( ast::TypeofType const * type ) {
     288void GenType::postvisit( ast::TypeofType const * type ) {
    290289        std::ostringstream os;
    291290        os << "typeof(";
    292         ast::Pass<CodeGenerator_new>::read( type, os, options );
     291        ast::Pass<CodeGenerator>::read( type, os, options );
    293292        os << ") " << result;
    294293        result = os.str();
     
    296295}
    297296
    298 void GenType_new::postvisit( ast::VTableType const * type ) {
     297void GenType::postvisit( ast::VTableType const * type ) {
    299298        assertf( !options.genC, "Virtual table types should not reach code generation." );
    300299        std::ostringstream os;
     
    304303}
    305304
    306 void GenType_new::postvisit( ast::QualifiedType const * type ) {
     305void GenType::postvisit( ast::QualifiedType const * type ) {
    307306        assertf( !options.genC, "QualifiedType should not reach code generation." );
    308307        std::ostringstream os;
     
    312311}
    313312
    314 void GenType_new::handleQualifiers( ast::Type const * type ) {
     313void GenType::handleQualifiers( ast::Type const * type ) {
    315314        if ( type->is_const() ) {
    316315                result = "const " + result;
     
    327326}
    328327
    329 std::string GenType_new::genParamList( const ast::vector<ast::Type> & range ) {
     328std::string GenType::genParamList( const ast::vector<ast::Type> & range ) {
    330329        auto cur = range.begin();
    331330        auto end = range.end();
     
    346345        std::ostringstream os;
    347346        if ( !type->attributes.empty() ) {
    348                 ast::Pass<CodeGenerator_new> cg( os, options );
     347                ast::Pass<CodeGenerator> cg( os, options );
    349348                cg.core.genAttributes( type->attributes );
    350349        }
    351350
    352         return os.str() + ast::Pass<GenType_new>::read( type, base, options );
     351        return os.str() + ast::Pass<GenType>::read( type, base, options );
    353352}
    354353
    355354std::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 );
    357356}
    358357
Note: See TracChangeset for help on using the changeset viewer.