Changeset 6943a987 for src/SymTab


Ignore:
Timestamp:
Aug 29, 2016, 10:33:05 AM (9 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, 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:
5e644d3e
Parents:
79841be (diff), 413ad05 (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 plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/SymTab
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.cc

    r79841be r6943a987  
    6868                copy->get_args().push_back( new VariableExpr( dstParam ) );
    6969                copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) );
    70                 copy->get_args().push_back( new SizeofExpr( unionType ) );
     70                copy->get_args().push_back( new SizeofExpr( srcParam->get_type()->clone() ) );
    7171
    7272                *out++ = new ExprStmt( noLabels, copy );
     
    420420                copyCtorDecl->set_statements( assignDecl->get_statements()->clone() );
    421421
     422                // create a constructor which takes the first member type as a parameter.
     423                // for example, for Union A { int x; double y; }; generate
     424                // void ?{}(A *, int)
     425                // This is to mimic C's behaviour which initializes the first member of the union.
     426                std::list<Declaration *> memCtors;
     427                for ( Declaration * member : aggregateDecl->get_members() ) {
     428                        if ( DeclarationWithType * field = dynamic_cast< DeclarationWithType * >( member ) ) {
     429                                ObjectDecl * srcParam = new ObjectDecl( "src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, field->get_type()->clone(), 0 );
     430
     431                                FunctionType * memCtorType = ctorType->clone();
     432                                memCtorType->get_parameters().push_back( srcParam );
     433                                FunctionDecl * ctor = new FunctionDecl( "?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, memCtorType, new CompoundStmt( noLabels ), true, false );
     434                                ctor->fixUniqueId();
     435
     436                                makeUnionFieldsAssignment( srcParam, dstParam, cloneWithParams( refType, unionParams ), back_inserter( ctor->get_statements()->get_kids() ) );
     437                                memCtors.push_back( ctor );
     438                                // only generate a ctor for the first field
     439                                break;
     440                        }
     441                }
     442
    422443                declsToAdd.push_back( assignDecl );
    423444                declsToAdd.push_back( ctorDecl );
    424445                declsToAdd.push_back( copyCtorDecl );
    425446                declsToAdd.push_back( dtorDecl );
     447                declsToAdd.splice( declsToAdd.end(), memCtors );
    426448        }
    427449
  • src/SymTab/Validate.cc

    r79841be r6943a987  
    5858#include "Autogen.h"
    5959#include "ResolvExpr/typeops.h"
     60#include <algorithm>
    6061
    6162#define debugPrint( x ) if ( doDebug ) { std::cout << x; }
     
    162163
    163164                typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap;
     165                typedef std::map< std::string, TypeDecl * > TypeDeclMap;
    164166                TypedefMap typedefNames;
     167                TypeDeclMap typedeclNames;
    165168                int scopeLevel;
    166169        };
     
    370373                } // if
    371374
    372                 applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), ctx->get_members().begin(), ctx->get_members().end(), back_inserter( contextInst->get_members() ) );
     375                // need to clone members of the context for ownership purposes
     376                std::list< Declaration * > members;
     377                std::transform( ctx->get_members().begin(), ctx->get_members().end(), back_inserter( members ), [](Declaration * dwt) { return dwt->clone(); } );
     378
     379                applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), members.begin(), members.end(), back_inserter( contextInst->get_members() ) );
    373380        }
    374381
     
    521528                        delete typeInst;
    522529                        return ret;
     530                } else {
     531                        TypeDeclMap::const_iterator base = typedeclNames.find( typeInst->get_name() );
     532                        assert( base != typedeclNames.end() );
     533                        typeInst->set_baseType( base->second->clone() );
    523534                } // if
    524535                return typeInst;
     
    565576                        typedefNames.erase( i ) ;
    566577                } // if
     578
     579                typedeclNames[ typeDecl->get_name() ] = typeDecl;
    567580                return typeDecl;
    568581        }
Note: See TracChangeset for help on using the changeset viewer.