Changeset 42a36d9


Ignore:
Timestamp:
May 1, 2019, 3:32:10 PM (5 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
5157ba7
Parents:
3908e5d
Message:

Created CodeGen::Options which hold some flags for code generation.

Location:
src/CodeGen
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r3908e5d r42a36d9  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May  5 09:08:32 2018
    13 // Update Count     : 494
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed May  1 10:06:00 2019
     13// Update Count     : 495
    1414//
    1515#include "CodeGenerator.h"
     
    8383        void CodeGenerator::updateLocation( CodeLocation const & to ) {
    8484                // skip if linemarks shouldn't appear or if codelocation is unset
    85                 if ( !lineMarks || to.isUnset() ) return;
     85                if ( !options.lineMarks || to.isUnset() ) return;
    8686
    8787                if ( currentLocation.followedBy( to, 0 ) ) {
     
    116116        }
    117117
    118         CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks, bool printExprTypes ) : indent( CodeGenerator::tabsize ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ), printExprTypes( printExprTypes ), endl( *this ) {}
     118        CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks, bool printExprTypes ) : indent( CodeGenerator::tabsize ), output( os ), printLabels( *this ), options( pretty, genC, lineMarks, printExprTypes ), endl( *this ) {}
     119        CodeGenerator::CodeGenerator( std::ostream & os, const Options &options ) : indent( CodeGenerator::tabsize ), output( os ), printLabels( *this ), options(options), endl( *this ) {}
    119120
    120121        string CodeGenerator::mangleName( DeclarationWithType * decl ) {
    121122                // GCC builtins should always be printed unmangled
    122                 if ( pretty || decl->linkage.is_gcc_builtin ) return decl->name;
     123                if ( options.pretty || decl->linkage.is_gcc_builtin ) return decl->name;
    123124                if ( decl->mangleName != "" ) {
    124125                        // need to incorporate scope level in order to differentiate names for destructors
     
    164165                previsit( (BaseSyntaxNode *)node );
    165166                GuardAction( [this, node](){
    166                         if ( printExprTypes && node->result ) {
    167                                 output << " /* " << genType( node->result, "", pretty, genC ) << " */ ";
     167                        if ( options.printExprTypes && node->result ) {
     168                                output << " /* " << genType( node->result, "", options ) << " */ ";
    168169                        }
    169170                } );
     
    173174        void CodeGenerator::postvisit( FunctionDecl * functionDecl ) {
    174175                // deleted decls should never be used, so don't print them
    175                 if ( functionDecl->isDeleted && genC ) return;
     176                if ( functionDecl->isDeleted && options.genC ) return;
    176177                extension( functionDecl );
    177178                genAttributes( functionDecl->get_attributes() );
     
    180181                functionDecl->get_funcSpec().print( output );
    181182
    182                 output << genType( functionDecl->get_functionType(), mangleName( functionDecl ), pretty, genC );
     183                output << genType( functionDecl->get_functionType(), mangleName( functionDecl ), options.pretty, options.genC );
    183184
    184185                asmName( functionDecl );
     
    194195        void CodeGenerator::postvisit( ObjectDecl * objectDecl ) {
    195196                // deleted decls should never be used, so don't print them
    196                 if ( objectDecl->isDeleted && genC ) return;
    197                 if (objectDecl->get_name().empty() && genC ) {
     197                if ( objectDecl->isDeleted && options.genC ) return;
     198                if (objectDecl->get_name().empty() && options.genC ) {
    198199                        // only generate an anonymous name when generating C code, otherwise it clutters the output too much
    199200                        static UniqueName name = { "__anonymous_object" };
     
    205206
    206207                handleStorageClass( objectDecl );
    207                 output << genType( objectDecl->get_type(), mangleName( objectDecl ), pretty, genC );
     208                output << genType( objectDecl->get_type(), mangleName( objectDecl ), options.pretty, options.genC );
    208209
    209210                asmName( objectDecl );
     
    224225
    225226        void CodeGenerator::handleAggregate( AggregateDecl * aggDecl, const std::string & kind ) {
    226                 if( ! aggDecl->parameters.empty() && ! genC ) {
     227                if( ! aggDecl->parameters.empty() && ! options.genC ) {
    227228                        // assertf( ! genC, "Aggregate type parameters should not reach code generation." );
    228229                        output << "forall(";
     
    294295
    295296        void CodeGenerator::postvisit( TraitDecl * traitDecl ) {
    296                 assertf( ! genC, "TraitDecls should not reach code generation." );
     297                assertf( ! options.genC, "TraitDecls should not reach code generation." );
    297298                extension( traitDecl );
    298299                handleAggregate( traitDecl, "trait " );
     
    300301
    301302        void CodeGenerator::postvisit( TypedefDecl * typeDecl ) {
    302                 assertf( ! genC, "Typedefs are removed and substituted in earlier passes." );
     303                assertf( ! options.genC, "Typedefs are removed and substituted in earlier passes." );
    303304                output << "typedef ";
    304                 output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl;
     305                output << genType( typeDecl->get_base(), typeDecl->get_name(), options ) << endl;
    305306        }
    306307
    307308        void CodeGenerator::postvisit( TypeDecl * typeDecl ) {
    308                 assertf( ! genC, "TypeDecls should not reach code generation." );
     309                assertf( ! options.genC, "TypeDecls should not reach code generation." );
    309310                output << typeDecl->genTypeString() << " " << typeDecl->name;
    310311                if ( typeDecl->sized ) {
     
    371372
    372373        void CodeGenerator::postvisit( ConstructorInit * init ){
    373                 assertf( ! genC, "ConstructorInit nodes should not reach code generation." );
     374                assertf( ! options.genC, "ConstructorInit nodes should not reach code generation." );
    374375                // pseudo-output for constructor/destructor pairs
    375376                output << "<ctorinit>{" << endl << ++indent << "ctor: ";
     
    507508                                        } else {
    508509                                                // no constructors with 0 or more than 2 parameters
    509                                                 assertf( ! genC, "UntypedExpr constructor/destructor with 0 or more than 2 parameters." );
     510                                                assertf( ! options.genC, "UntypedExpr constructor/destructor with 0 or more than 2 parameters." );
    510511                                                output << "(";
    511512                                                (*arg++)->accept( *visitor );
     
    604605                        // an lvalue cast, this has been taken out.
    605606                        output << "(";
    606                         output << genType( castExpr->get_result(), "", pretty, genC );
     607                        output << genType( castExpr->get_result(), "", options );
    607608                        output << ")";
    608609                } // if
     
    612613
    613614        void CodeGenerator::postvisit( KeywordCastExpr * castExpr ) {
    614                 assertf( ! genC, "KeywordCast should not reach code generation." );
     615                assertf( ! options.genC, "KeywordCast should not reach code generation." );
    615616                extension( castExpr );
    616617                output << "((" << castExpr->targetString() << " &)";
     
    620621
    621622        void CodeGenerator::postvisit( VirtualCastExpr * castExpr ) {
    622                 assertf( ! genC, "VirtualCastExpr should not reach code generation." );
     623                assertf( ! options.genC, "VirtualCastExpr should not reach code generation." );
    623624                extension( castExpr );
    624625                output << "(virtual ";
     
    628629
    629630        void CodeGenerator::postvisit( UntypedMemberExpr * memberExpr ) {
    630                 assertf( ! genC, "UntypedMemberExpr should not reach code generation." );
     631                assertf( ! options.genC, "UntypedMemberExpr should not reach code generation." );
    631632                extension( memberExpr );
    632633                memberExpr->get_aggregate()->accept( *visitor );
     
    661662                output << "sizeof(";
    662663                if ( sizeofExpr->get_isType() ) {
    663                         output << genType( sizeofExpr->get_type(), "", pretty, genC );
     664                        output << genType( sizeofExpr->get_type(), "", options );
    664665                } else {
    665666                        sizeofExpr->get_expr()->accept( *visitor );
     
    673674                output << "__alignof__(";
    674675                if ( alignofExpr->get_isType() ) {
    675                         output << genType( alignofExpr->get_type(), "", pretty, genC );
     676                        output << genType( alignofExpr->get_type(), "", options );
    676677                } else {
    677678                        alignofExpr->get_expr()->accept( *visitor );
     
    681682
    682683        void CodeGenerator::postvisit( UntypedOffsetofExpr * offsetofExpr ) {
    683                 assertf( ! genC, "UntypedOffsetofExpr should not reach code generation." );
     684                assertf( ! options.genC, "UntypedOffsetofExpr should not reach code generation." );
    684685                output << "offsetof(";
    685                 output << genType( offsetofExpr->get_type(), "", pretty, genC );
     686                output << genType( offsetofExpr->get_type(), "", options );
    686687                output << ", " << offsetofExpr->get_member();
    687688                output << ")";
     
    691692                // use GCC builtin
    692693                output << "__builtin_offsetof(";
    693                 output << genType( offsetofExpr->get_type(), "", pretty, genC );
     694                output << genType( offsetofExpr->get_type(), "", options );
    694695                output << ", " << mangleName( offsetofExpr->get_member() );
    695696                output << ")";
     
    697698
    698699        void CodeGenerator::postvisit( OffsetPackExpr * offsetPackExpr ) {
    699                 assertf( ! genC, "OffsetPackExpr should not reach code generation." );
    700                 output << "__CFA_offsetpack(" << genType( offsetPackExpr->get_type(), "", pretty, genC ) << ")";
     700                assertf( ! options.genC, "OffsetPackExpr should not reach code generation." );
     701                output << "__CFA_offsetpack(" << genType( offsetPackExpr->get_type(), "", options ) << ")";
    701702        }
    702703
     
    728729                extension( commaExpr );
    729730                output << "(";
    730                 if ( genC ) {
     731                if ( options.genC ) {
    731732                        // arg1 of a CommaExpr is never used, so it can be safely cast to void to reduce gcc warnings.
    732733                        commaExpr->set_arg1( new CastExpr( commaExpr->get_arg1() ) );
     
    739740
    740741        void CodeGenerator::postvisit( TupleAssignExpr * tupleExpr ) {
    741                 assertf( ! genC, "TupleAssignExpr should not reach code generation." );
     742                assertf( ! options.genC, "TupleAssignExpr should not reach code generation." );
    742743                tupleExpr->stmtExpr->accept( *visitor );
    743744        }
    744745
    745746        void CodeGenerator::postvisit( UntypedTupleExpr * tupleExpr ) {
    746                 assertf( ! genC, "UntypedTupleExpr should not reach code generation." );
     747                assertf( ! options.genC, "UntypedTupleExpr should not reach code generation." );
    747748                extension( tupleExpr );
    748749                output << "[";
     
    752753
    753754        void CodeGenerator::postvisit( TupleExpr * tupleExpr ) {
    754                 assertf( ! genC, "TupleExpr should not reach code generation." );
     755                assertf( ! options.genC, "TupleExpr should not reach code generation." );
    755756                extension( tupleExpr );
    756757                output << "[";
     
    760761
    761762        void CodeGenerator::postvisit( TupleIndexExpr * tupleExpr ) {
    762                 assertf( ! genC, "TupleIndexExpr should not reach code generation." );
     763                assertf( ! options.genC, "TupleIndexExpr should not reach code generation." );
    763764                extension( tupleExpr );
    764765                tupleExpr->get_tuple()->accept( *visitor );
     
    767768
    768769        void CodeGenerator::postvisit( TypeExpr * typeExpr ) {
    769                 // if ( genC ) std::cerr << "typeexpr still exists: " << typeExpr << std::endl;
    770                 // assertf( ! genC, "TypeExpr should not reach code generation." );
    771                 if ( ! genC ) {
    772                         output<< genType( typeExpr->get_type(), "", pretty, genC );
     770                // if ( options.genC ) std::cerr << "typeexpr still exists: " << typeExpr << std::endl;
     771                // assertf( ! options.genC, "TypeExpr should not reach code generation." );
     772                if ( ! options.genC ) {
     773                        output << genType( typeExpr->get_type(), "", options );
    773774                }
    774775        }
     
    788789        void CodeGenerator::postvisit( CompoundLiteralExpr *compLitExpr ) {
    789790                assert( compLitExpr->get_result() && dynamic_cast< ListInit * > ( compLitExpr->get_initializer() ) );
    790                 output << "(" << genType( compLitExpr->get_result(), "", pretty, genC ) << ")";
     791                output << "(" << genType( compLitExpr->get_result(), "", options ) << ")";
    791792                compLitExpr->get_initializer()->accept( *visitor );
    792793        }
    793794
    794795        void CodeGenerator::postvisit( UniqueExpr * unqExpr ) {
    795                 assertf( ! genC, "Unique expressions should not reach code generation." );
     796                assertf( ! options.genC, "Unique expressions should not reach code generation." );
    796797                output << "unq<" << unqExpr->get_id() << ">{ ";
    797798                unqExpr->get_expr()->accept( *visitor );
     
    829830
    830831        void CodeGenerator::postvisit( ConstructorExpr * expr ) {
    831                 assertf( ! genC, "Unique expressions should not reach code generation." );
     832                assertf( ! options.genC, "Unique expressions should not reach code generation." );
    832833                expr->callExpr->accept( *visitor );
    833834        }
    834835
    835836        void CodeGenerator::postvisit( DeletedExpr * expr ) {
    836                 assertf( ! genC, "Deleted expressions should not reach code generation." );
     837                assertf( ! options.genC, "Deleted expressions should not reach code generation." );
    837838                expr->expr->accept( *visitor );
    838839        }
    839840
    840841        void CodeGenerator::postvisit( DefaultArgExpr * arg ) {
    841                 assertf( ! genC, "Default argument expressions should not reach code generation." );
     842                assertf( ! options.genC, "Default argument expressions should not reach code generation." );
    842843                arg->expr->accept( *visitor );
    843844        }
    844845
    845846        void CodeGenerator::postvisit( GenericExpr * expr ) {
    846                 assertf( ! genC, "C11 _Generic expressions should not reach code generation." );
     847                assertf( ! options.genC, "C11 _Generic expressions should not reach code generation." );
    847848                output << "_Generic(";
    848849                expr->control->accept( *visitor );
     
    854855                                output << "default: ";
    855856                        } else {
    856                                 output << genType( assoc.type, "", pretty, genC ) << ": ";
     857                                output << genType( assoc.type, "", options ) << ": ";
    857858                        }
    858859                        assoc.expr->accept( *visitor );
     
    889890        void CodeGenerator::postvisit( ExprStmt * exprStmt ) {
    890891                assert( exprStmt );
    891                 if ( genC ) {
     892                if ( options.genC ) {
    892893                        // cast the top-level expression to void to reduce gcc warnings.
    893894                        exprStmt->set_expr( new CastExpr( exprStmt->get_expr() ) );
     
    9991000                  case BranchStmt::FallThrough:
    10001001                  case BranchStmt::FallThroughDefault:
    1001                         assertf( ! genC, "fallthru should not reach code generation." );
     1002                        assertf( ! options.genC, "fallthru should not reach code generation." );
    10021003                  output << "fallthru";
    10031004                        break;
    10041005                } // switch
    10051006                // print branch target for labelled break/continue/fallthru in debug mode
    1006                 if ( ! genC && branchStmt->get_type() != BranchStmt::Goto ) {
     1007                if ( ! options.genC && branchStmt->get_type() != BranchStmt::Goto ) {
    10071008                        if ( ! branchStmt->get_target().empty() ) {
    10081009                                output << " " << branchStmt->get_target();
     
    10211022
    10221023        void CodeGenerator::postvisit( ThrowStmt * throwStmt ) {
    1023                 assertf( ! genC, "Throw statements should not reach code generation." );
     1024                assertf( ! options.genC, "Throw statements should not reach code generation." );
    10241025
    10251026                output << ((throwStmt->get_kind() == ThrowStmt::Terminate) ?
     
    10361037        }
    10371038        void CodeGenerator::postvisit( CatchStmt * stmt ) {
    1038                 assertf( ! genC, "Catch statements should not reach code generation." );
     1039                assertf( ! options.genC, "Catch statements should not reach code generation." );
    10391040
    10401041                output << ((stmt->get_kind() == CatchStmt::Terminate) ?
     
    10531054
    10541055        void CodeGenerator::postvisit( WaitForStmt * stmt ) {
    1055                 assertf( ! genC, "Waitfor statements should not reach code generation." );
     1056                assertf( ! options.genC, "Waitfor statements should not reach code generation." );
    10561057
    10571058                bool first = true;
     
    10991100
    11001101        void CodeGenerator::postvisit( WithStmt * with ) {
    1101                 if ( ! genC ) {
     1102                if ( ! options.genC ) {
    11021103                        output << "with ( ";
    11031104                        genCommaList( with->exprs.begin(), with->exprs.end() );
     
    11651166
    11661167        void CodeGenerator::postvisit( ImplicitCtorDtorStmt * stmt ) {
    1167                 assertf( ! genC, "ImplicitCtorDtorStmts should not reach code generation." );
     1168                assertf( ! options.genC, "ImplicitCtorDtorStmts should not reach code generation." );
    11681169                stmt->callStmt->accept( *visitor );
    11691170        }
  • src/CodeGen/CodeGenerator.h

    r3908e5d r42a36d9  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Aug 18 15:40:00 2017
    13 // Update Count     : 56
     12// Last Modified On : Tue Apr 30 12:01:00 2019
     13// Update Count     : 57
    1414//
    1515
     
    2020#include <string>                 // for string
    2121
     22#include "CodeGen/Options.h"      // for Options
    2223#include "Common/Indenter.h"      // for Indenter
    2324#include "Common/PassVisitor.h"   // for PassVisitor
     
    3132
    3233                CodeGenerator( std::ostream &os, bool pretty = false, bool genC = false, bool lineMarks = false, bool printExprTypes = false );
     34                CodeGenerator( std::ostream &os, const Options &options );
    3335
    3436                //*** Turn off visit_children for all nodes
     
    144146                std::ostream & output;
    145147                LabelPrinter printLabels;
    146                 bool pretty = false;  // pretty print
    147                 bool genC = false;    // true if output has to be C code
    148                 bool lineMarks = false;
    149                 bool printExprTypes = false;
     148                Options options;
    150149        public:
    151150                LineEnder endl;
  • src/CodeGen/GenType.cc

    r3908e5d r42a36d9  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 17 09:02:28 2017
    13 // Update Count     : 22
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed May  1 15:24:00 2019
     13// Update Count     : 23
    1414//
    1515#include "GenType.h"
     
    2828        struct GenType : public WithVisitorRef<GenType>, public WithShortCircuiting {
    2929                std::string typeString;
    30                 GenType( const std::string &typeString, bool pretty, bool genC, bool lineMarks );
     30                GenType( const std::string &typeString, const Options &options );
    3131
    3232                void previsit( BaseSyntaxNode * );
     
    5757                void genArray( const Type::Qualifiers &qualifiers, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
    5858
    59                 bool pretty = false;    // pretty print
    60                 bool genC = false;      // generating C code?
    61                 bool lineMarks = false; // lineMarks on for CodeGenerator?
     59                Options options;
    6260        };
    6361
    64         std::string genType( Type *type, const std::string &baseString, bool pretty, bool genC , bool lineMarks ) {
    65                 PassVisitor<GenType> gt( baseString, pretty, genC, lineMarks );
     62        std::string genType( Type *type, const std::string &baseString, const Options &options ) {
     63                PassVisitor<GenType> gt( baseString, options );
    6664                std::ostringstream os;
    6765
    6866                if ( ! type->get_attributes().empty() ) {
    69                         PassVisitor<CodeGenerator> cg( os, pretty, genC, lineMarks );
     67                        PassVisitor<CodeGenerator> cg( os, options );
    7068                        cg.pass.genAttributes( type->get_attributes() );
    7169                } // if
     
    7573        }
    7674
    77   std::string genPrettyType( Type * type, const std::string & baseString ) {
    78         return genType( type, baseString, true, false );
    79   }
    80 
    81         GenType::GenType( const std::string &typeString, bool pretty, bool genC, bool lineMarks ) : typeString( typeString ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ) {}
     75        std::string genType( Type *type, const std::string &baseString, bool pretty, bool genC , bool lineMarks ) {
     76                return genType( type, baseString, Options(pretty, genC, lineMarks, false ) );
     77        }
     78
     79        std::string genPrettyType( Type * type, const std::string & baseString ) {
     80                return genType( type, baseString, true, false );
     81        }
     82
     83        GenType::GenType( const std::string &typeString, const Options &options ) : typeString( typeString ), options( options ) {}
    8284
    8385        // *** BaseSyntaxNode
     
    133135                } // if
    134136                if ( dimension != 0 ) {
    135                         PassVisitor<CodeGenerator> cg( os, pretty, genC, lineMarks );
     137                        PassVisitor<CodeGenerator> cg( os, options );
    136138                        dimension->accept( cg );
    137139                } else if ( isVarLen ) {
     
    167169        void GenType::postvisit( ReferenceType * refType ) {
    168170                assert( refType->base != 0);
    169                 assertf( ! genC, "Reference types should not reach code generation." );
     171                assertf( ! options.genC, "Reference types should not reach code generation." );
    170172                handleQualifiers( refType );
    171173                typeString = "&" + typeString;
     
    195197                        } // if
    196198                } else {
    197                         PassVisitor<CodeGenerator> cg( os, pretty, genC, lineMarks );
     199                        PassVisitor<CodeGenerator> cg( os, options );
    198200                        os << "(" ;
    199201
     
    215217
    216218                // add forall
    217                 if( ! funcType->forall.empty() && ! genC ) {
     219                if( ! funcType->forall.empty() && ! options.genC ) {
    218220                        // assertf( ! genC, "Aggregate type parameters should not reach code generation." );
    219221                        std::ostringstream os;
    220                         PassVisitor<CodeGenerator> cg( os, pretty, genC, lineMarks );
     222                        PassVisitor<CodeGenerator> cg( os, options );
    221223                        os << "forall(";
    222224                        cg.pass.genCommaList( funcType->forall.begin(), funcType->forall.end() );
     
    229231                if ( ! refType->parameters.empty() ) {
    230232                        std::ostringstream os;
    231                         PassVisitor<CodeGenerator> cg( os, pretty, genC, lineMarks );
     233                        PassVisitor<CodeGenerator> cg( os, options );
    232234                        os << "(";
    233235                        cg.pass.genCommaList( refType->parameters.begin(), refType->parameters.end() );
     
    240242        void GenType::postvisit( StructInstType * structInst )  {
    241243                typeString = structInst->name + handleGeneric( structInst ) + " " + typeString;
    242                 if ( genC ) typeString = "struct " + typeString;
     244                if ( options.genC ) typeString = "struct " + typeString;
    243245                handleQualifiers( structInst );
    244246        }
     
    246248        void GenType::postvisit( UnionInstType * unionInst ) {
    247249                typeString = unionInst->name + handleGeneric( unionInst ) + " " + typeString;
    248                 if ( genC ) typeString = "union " + typeString;
     250                if ( options.genC ) typeString = "union " + typeString;
    249251                handleQualifiers( unionInst );
    250252        }
     
    252254        void GenType::postvisit( EnumInstType * enumInst ) {
    253255                typeString = enumInst->name + " " + typeString;
    254                 if ( genC ) typeString = "enum " + typeString;
     256                if ( options.genC ) typeString = "enum " + typeString;
    255257                handleQualifiers( enumInst );
    256258        }
     
    262264
    263265        void GenType::postvisit( TupleType * tupleType ) {
    264                 assertf( ! genC, "Tuple types should not reach code generation." );
     266                assertf( ! options.genC, "Tuple types should not reach code generation." );
    265267                unsigned int i = 0;
    266268                std::ostringstream os;
     
    268270                for ( Type * t : *tupleType ) {
    269271                        i++;
    270                         os << genType( t, "", pretty, genC, lineMarks ) << (i == tupleType->size() ? "" : ", ");
     272                        os << genType( t, "", options ) << (i == tupleType->size() ? "" : ", ");
    271273                }
    272274                os << "] ";
     
    281283        void GenType::postvisit( ZeroType * zeroType ) {
    282284                // ideally these wouldn't hit codegen at all, but should be safe to make them ints
    283                 typeString = (pretty ? "zero_t " : "long int ") + typeString;
     285                typeString = (options.pretty ? "zero_t " : "long int ") + typeString;
    284286                handleQualifiers( zeroType );
    285287        }
     
    287289        void GenType::postvisit( OneType * oneType ) {
    288290                // ideally these wouldn't hit codegen at all, but should be safe to make them ints
    289                 typeString = (pretty ? "one_t " : "long int ") + typeString;
     291                typeString = (options.pretty ? "one_t " : "long int ") + typeString;
    290292                handleQualifiers( oneType );
    291293        }
    292294
    293295        void GenType::postvisit( GlobalScopeType * globalType ) {
    294                 assertf( ! genC, "Global scope type should not reach code generation." );
     296                assertf( ! options.genC, "Global scope type should not reach code generation." );
    295297                handleQualifiers( globalType );
    296298        }
    297299
    298300        void GenType::postvisit( TraitInstType * inst ) {
    299                 assertf( ! genC, "Trait types should not reach code generation." );
     301                assertf( ! options.genC, "Trait types should not reach code generation." );
    300302                typeString = inst->name + " " + typeString;
    301303                handleQualifiers( inst );
     
    304306        void GenType::postvisit( TypeofType * typeof ) {
    305307                std::ostringstream os;
    306                 PassVisitor<CodeGenerator> cg( os, pretty, genC, lineMarks );
     308                PassVisitor<CodeGenerator> cg( os, options );
    307309                os << "typeof(";
    308310                typeof->expr->accept( cg );
     
    313315
    314316        void GenType::postvisit( QualifiedType * qualType ) {
    315                 assertf( ! genC, "Qualified types should not reach code generation." );
    316                 std::ostringstream os;
    317                 os << genType( qualType->parent, "", pretty, genC, lineMarks ) << "." << genType( qualType->child, "", pretty, genC, lineMarks ) << typeString;
     317                assertf( ! options.genC, "Qualified types should not reach code generation." );
     318                std::ostringstream os;
     319                os << genType( qualType->parent, "", options ) << "." << genType( qualType->child, "", options ) << typeString;
    318320                typeString = os.str();
    319321                handleQualifiers( qualType );
     
    333335                        typeString = "_Atomic " + typeString;
    334336                } // if
    335                 if ( type->get_lvalue() && ! genC ) {
     337                if ( type->get_lvalue() && ! options.genC ) {
    336338                        // when not generating C code, print lvalue for debugging.
    337339                        typeString = "lvalue " + typeString;
  • src/CodeGen/GenType.h

    r3908e5d r42a36d9  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:17:23 2017
    13 // Update Count     : 2
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue Apr 30 11:47:00 2019
     13// Update Count     : 3
    1414//
    1515
     
    1818#include <string>  // for string
    1919
     20#include "CodeGen/Options.h" // for Options
     21
    2022class Type;
    2123
    2224namespace CodeGen {
     25        std::string genType( Type *type, const std::string &baseString, const Options &options );
    2326        std::string genType( Type *type, const std::string &baseString, bool pretty = false, bool genC = false, bool lineMarks = false );
    2427  std::string genPrettyType( Type * type, const std::string & baseString );
Note: See TracChangeset for help on using the changeset viewer.