Changeset f006f01 for src


Ignore:
Timestamp:
Sep 12, 2016, 7:08:41 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
fd782b2
Parents:
6eb8948
Message:

replace tuple types with an equivalent struct type

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/ReferenceToType.cc

    r6eb8948 rf006f01  
    5656        }
    5757} // namespace
     58
     59StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct ) : Parent( tq, baseStruct->get_name() ), baseStruct( baseStruct ) {}
    5860
    5961std::string StructInstType::typeString() const { return "struct"; }
  • src/SynTree/Type.h

    r6eb8948 rf006f01  
    234234  public:
    235235        StructInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseStruct( 0 ) {}
     236        StructInstType( const Type::Qualifiers &tq, StructDecl * baseStruct );
    236237        StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {}
    237238
  • src/Tuples/TupleExpansion.cc

    r6eb8948 rf006f01  
    1818#include <cassert>
    1919#include "Tuples.h"
    20 #include "GenPoly/PolyMutator.h"
     20#include "GenPoly/DeclMutator.h"
     21#include "SynTree/Mutator.h"
    2122#include "SynTree/Statement.h"
     23#include "SynTree/Declaration.h"
     24#include "SynTree/Type.h"
     25#include "SymTab/Mangler.h"
     26#include "Common/ScopedMap.h"
    2227
    2328namespace Tuples {
    24         class TupleAssignExpander : public GenPoly::PolyMutator {
     29        class TupleAssignExpander : public Mutator {
    2530        public:
    2631                virtual Expression * mutate( TupleAssignExpr * tupleExpr );
     32        };
     33
     34        class TupleTypeReplacer : public GenPoly::DeclMutator {
     35          public:
     36                typedef GenPoly::DeclMutator Parent;
     37
     38                virtual Type * mutate( TupleType * tupleType );
     39
     40                virtual CompoundStmt * mutate( CompoundStmt * stmt ) {
     41                        typeMap.beginScope();
     42                        stmt = Parent::mutate( stmt );
     43                        typeMap.endScope();
     44                        return stmt;
     45                }
     46          private:
     47                ScopedMap< std::string, StructDecl * > typeMap;
    2748        };
    2849
     
    3051                TupleAssignExpander expander;
    3152                mutateAll( translationUnit, expander );
     53
     54                TupleTypeReplacer replacer;
     55                replacer.mutateDeclarationList( translationUnit );
    3256        }
    3357
     
    4771        }
    4872
     73        Type * TupleTypeReplacer::mutate( TupleType * tupleType ) {
     74                std::string mangleName = SymTab::Mangler::mangleType( tupleType );
     75                TupleType * newType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) );
     76                if ( ! typeMap.count( mangleName ) ) {
     77                        // generate struct type to replace tuple type
     78                        StructDecl * decl = new StructDecl( "_tuple_type_" + mangleName );
     79                        decl->set_body( true );
     80                        int cnt = 0;
     81                        for ( Type * t : *newType ) {
     82                                decl->get_members().push_back( new ObjectDecl( "field_"+std::to_string(++cnt), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, t->clone(), nullptr ) );
     83                        }
     84                        typeMap[mangleName] = decl;
     85                        addDeclaration( decl );
     86                }
     87                delete newType;
     88                return new StructInstType( newType->get_qualifiers(), typeMap[mangleName] );
     89        }
     90
    4991} // namespace Tuples
    5092
Note: See TracChangeset for help on using the changeset viewer.