Ignore:
Timestamp:
Apr 19, 2017, 10:31:57 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
12d3187, 4e9151f, 6a8ac0b
Parents:
5c3632f (diff), e3987770 (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.
Message:

Merge branch 'master' of plg2:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/GenType.cc

    r5c3632f rb3d70eba  
    2828        class GenType : public Visitor {
    2929          public:
    30                 GenType( const std::string &typeString, bool pretty = false );
     30                GenType( const std::string &typeString, bool pretty = false, bool genC = false );
    3131                std::string get_typeString() const { return typeString; }
    3232                void set_typeString( const std::string &newValue ) { typeString = newValue; }
     
    4848          private:
    4949                void handleQualifiers( Type *type );
     50                std::string handleGeneric( ReferenceToType * refType );
    5051                void genArray( const Type::Qualifiers &qualifiers, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
    5152
    5253                std::string typeString;
    5354                bool pretty = false; // pretty print
     55                bool genC = false;   // generating C code?
    5456        };
    5557
    56         std::string genType( Type *type, const std::string &baseString, bool pretty ) {
    57                 GenType gt( baseString, pretty );
     58        std::string genType( Type *type, const std::string &baseString, bool pretty, bool genC ) {
     59                GenType gt( baseString, pretty, genC );
    5860                std::ostringstream os;
    5961
    6062                if ( ! type->get_attributes().empty() ) {
    61                         CodeGenerator cg( os, pretty );
     63                        CodeGenerator cg( os, pretty, genC );
    6264                        cg.genAttributes( type->get_attributes() );
    6365                } // if
     
    6870
    6971  std::string genPrettyType( Type * type, const std::string & baseString ) {
    70         return genType( type, baseString, true );
     72        return genType( type, baseString, true, false );
    7173  }
    7274
    73         GenType::GenType( const std::string &typeString, bool pretty ) : typeString( typeString ), pretty( pretty ) {}
     75        GenType::GenType( const std::string &typeString, bool pretty, bool genC ) : typeString( typeString ), pretty( pretty ), genC( genC ) {}
    7476
    7577        void GenType::visit( VoidType *voidType ) {
     
    112114                } // if
    113115                if ( dimension != 0 ) {
    114                         CodeGenerator cg( os, pretty );
     116                        CodeGenerator cg( os, pretty, genC );
    115117                        dimension->accept( cg );
    116118                } else if ( isVarLen ) {
     
    166168                        } // if
    167169                } else {
    168                         CodeGenerator cg( os, pretty );
     170                        CodeGenerator cg( os, pretty, genC );
    169171                        os << "(" ;
    170172
     
    184186                        funcType->get_returnVals().front()->get_type()->accept( *this );
    185187                } // if
     188
     189                // add forall
     190                if( ! funcType->get_forall().empty() && ! genC ) {
     191                        // assertf( ! genC, "Aggregate type parameters should not reach code generation." );
     192                        std::ostringstream os;
     193                        CodeGenerator cg( os, pretty, genC );
     194                        os << "forall(";
     195                        cg.genCommaList( funcType->get_forall().begin(), funcType->get_forall().end() );
     196                        os << ")" << std::endl;
     197                        typeString = os.str() + typeString;
     198                }
     199        }
     200
     201        std::string GenType::handleGeneric( ReferenceToType * refType ) {
     202                if ( ! refType->get_parameters().empty() ) {
     203                        std::ostringstream os;
     204                        CodeGenerator cg( os, pretty, genC );
     205                        os << "(";
     206                        cg.genCommaList( refType->get_parameters().begin(), refType->get_parameters().end() );
     207                        os << ") ";
     208                        return os.str();
     209                }
     210                return "";
    186211        }
    187212
    188213        void GenType::visit( StructInstType *structInst )  {
    189                 typeString = "struct " + structInst->get_name() + " " + typeString;
     214                typeString = structInst->get_name() + handleGeneric( structInst ) + " " + typeString;
     215                if ( genC ) typeString = "struct " + typeString;
    190216                handleQualifiers( structInst );
    191217        }
    192218
    193219        void GenType::visit( UnionInstType *unionInst ) {
    194                 typeString = "union " + unionInst->get_name() + " " + typeString;
     220                typeString = unionInst->get_name() + handleGeneric( unionInst ) + " " + typeString;
     221                if ( genC ) typeString = "union " + typeString;
    195222                handleQualifiers( unionInst );
    196223        }
    197224
    198225        void GenType::visit( EnumInstType *enumInst ) {
    199                 typeString = "enum " + enumInst->get_name() + " " + typeString;
     226                typeString = enumInst->get_name() + " " + typeString;
     227                if ( genC ) typeString = "enum " + typeString;
    200228                handleQualifiers( enumInst );
    201229        }
     
    207235
    208236        void GenType::visit( TupleType * tupleType ) {
    209                 assertf( pretty, "Tuple types should not make it to Code Gen." );
     237                assertf( ! genC, "Tuple types should not reach code generation." );
    210238                Visitor::visit( tupleType );
    211239                unsigned int i = 0;
     
    214242                for ( Type * t : *tupleType ) {
    215243                        i++;
    216                         os << genType( t, "", pretty ) << (i == tupleType->size() ? "" : ", ");
     244                        os << genType( t, "", pretty, genC ) << (i == tupleType->size() ? "" : ", ");
    217245                }
    218246                os << "]";
Note: See TracChangeset for help on using the changeset viewer.