Ignore:
Timestamp:
Apr 6, 2016, 5:11:32 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
eab39cd
Parents:
39786813 (diff), 3aba311 (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 'fix-memory-error' into ctor

Conflicts:

src/CodeGen/CodeGenerator.cc
src/Makefile.in
src/Parser/DeclarationNode.cc
src/Parser/ParseNode.h
src/Parser/TypeData.cc
src/Parser/parser.cc
src/Parser/parser.yy
src/ResolvExpr/Resolver.cc
src/SymTab/Validate.cc
src/SynTree/Declaration.h
src/SynTree/Mutator.cc
src/SynTree/Mutator.h
src/SynTree/SynTree.h
src/SynTree/Visitor.cc
src/SynTree/Visitor.h
src/libcfa/prelude.cf

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r39786813 ra5a71d0  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jan 07 13:18:02 2016
    13 // Update Count     : 130
     12// Last Modified On : Mon Apr 04 17:09:46 2016
     13// Update Count     : 142
    1414//
    1515
     
    3434const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "" };
    3535const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" };
    36 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary" };
     36const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary", };
    3737const char *DeclarationNode::modifierName[]  = { "signed", "unsigned", "short", "long" };
    3838const char *DeclarationNode::aggregateName[] = { "struct", "union", "context" };
    3939const char *DeclarationNode::typeClassName[] = { "type", "dtype", "ftype" };
     40const char *DeclarationNode::builtinTypeName[] = { "__builtin_va_list" };
    4041
    4142UniqueName DeclarationNode::anonymous( "__anonymous" );
    4243
    43 extern LinkageSpec::Type linkage;               /* defined in cfa.y */
     44extern LinkageSpec::Type linkage;                                               // defined in parser.yy
    4445
    4546DeclarationNode *DeclarationNode::clone() const {
     
    5455        newnode->linkage = linkage;
    5556        return newnode;
    56 }
     57} // DeclarationNode::clone
    5758
    5859DeclarationNode::DeclarationNode() : type( 0 ), bitfieldWidth( 0 ), initializer( 0 ), hasEllipsis( false ), linkage( ::linkage ) {
     
    118119        newnode->type->function->newStyle = newStyle;
    119120        newnode->type->function->body = body;
     121        typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
    120122
    121123        if ( body ) {
     
    130132
    131133        return newnode;
    132 }
     134} // DeclarationNode::newFunction
    133135
    134136DeclarationNode *DeclarationNode::newQualifier( Qualifier q ) {
     
    137139        newnode->type->qualifiers.push_back( q );
    138140        return newnode;
    139 }
     141} // DeclarationNode::newQualifier
    140142
    141143DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {
     
    143145        newnode->storageClasses.push_back( sc );
    144146        return newnode;
    145 }
     147} // DeclarationNode::newStorageClass
    146148
    147149DeclarationNode *DeclarationNode::newBasicType( BasicType bt ) {
     
    150152        newnode->type->basic->typeSpec.push_back( bt );
    151153        return newnode;
    152 }
     154} // DeclarationNode::newBasicType
     155
     156DeclarationNode *DeclarationNode::newBuiltinType( BuiltinType bt ) {
     157        DeclarationNode *newnode = new DeclarationNode;
     158        newnode->type = new TypeData( TypeData::Builtin );
     159        newnode->type->builtin->type = bt;
     160        return newnode;
     161} // DeclarationNode::newBuiltinType
    153162
    154163DeclarationNode *DeclarationNode::newModifier( Modifier mod ) {
     
    157166        newnode->type->basic->modifiers.push_back( mod );
    158167        return newnode;
    159 }
     168} // DeclarationNode::newModifier
    160169
    161170DeclarationNode *DeclarationNode::newForall( DeclarationNode *forall ) {
     
    164173        newnode->type->forall = forall;
    165174        return newnode;
    166 }
     175} // DeclarationNode::newForall
    167176
    168177DeclarationNode *DeclarationNode::newFromTypedef( std::string *name ) {
     
    173182        newnode->type->symbolic->params = 0;
    174183        return newnode;
    175 }
     184} // DeclarationNode::newFromTypedef
    176185
    177186DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields ) {
     
    182191        if ( newnode->type->aggregate->name == "" ) {           // anonymous aggregate ?
    183192                newnode->type->aggregate->name = DeclarationNode::anonymous.newName();
    184         } else {
    185                 // SKULLDUGGERY: generate a typedef for the aggregate name so that the aggregate does not have to be qualified
    186                 // by "struct"
     193        } else if ( ! typedefTable.exists( newnode->type->aggregate->name ) ) {
     194                // SKULLDUGGERY: Generate a typedef for the aggregate name so the aggregate does not have to be qualified by
     195                // "struct". Only generate the typedef, if the name is not in use. The typedef is implicitly (silently) removed
     196                // if the name is explicitly used.
    187197                typedefTable.addToEnclosingScope( newnode->type->aggregate->name, TypedefTable::TD );
    188198                DeclarationNode *typedf = new DeclarationNode;
     
    193203        newnode->type->aggregate->fields = fields;
    194204        return newnode;
    195 }
     205} // DeclarationNode::newAggregate
    196206
    197207DeclarationNode *DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) {
     
    202212        if ( newnode->type->enumeration->name == "" ) {         // anonymous enumeration ?
    203213                newnode->type->enumeration->name = DeclarationNode::anonymous.newName();
    204         } else {
    205                 // SKULLDUGGERY: generate a typedef for the enumeration name so that the enumeration does not have to be
    206                 // qualified by "enum"
     214        } else if ( ! typedefTable.exists( newnode->type->enumeration->name ) ) {
     215                // SKULLDUGGERY: Generate a typedef for the enumeration name so the enumeration does not have to be qualified by
     216                // "enum". Only generate the typedef, if the name is not in use. The typedef is implicitly (silently) removed if
     217                // the name is explicitly used.
    207218                typedefTable.addToEnclosingScope( newnode->type->enumeration->name, TypedefTable::TD );
    208219                DeclarationNode *typedf = new DeclarationNode;
     
    212223        newnode->type->enumeration->constants = constants;
    213224        return newnode;
    214 }
     225} // DeclarationNode::newEnum
    215226
    216227DeclarationNode *DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) {
    217228        DeclarationNode *newnode = new DeclarationNode;
    218229        newnode->name = assign_strptr( name );
    219         // do something with the constant
    220         return newnode;
    221 }
     230        newnode->enumeratorValue = constant;
     231        typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
     232        return newnode;
     233} // DeclarationNode::newEnumConstant
    222234
    223235DeclarationNode *DeclarationNode::newName( std::string *name ) {
     
    225237        newnode->name = assign_strptr( name );
    226238        return newnode;
    227 }
     239} // DeclarationNode::newName
    228240
    229241DeclarationNode *DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) {
     
    234246        newnode->type->symbolic->actuals = params;
    235247        return newnode;
    236 }
     248} // DeclarationNode::newFromTypeGen
    237249
    238250DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) {
     
    243255        newnode->type->variable->name = newnode->name;
    244256        return newnode;
    245 }
    246 
    247 DeclarationNode *DeclarationNode::newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {
     257} // DeclarationNode::newTypeParam
     258
     259DeclarationNode *DeclarationNode::newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {
    248260        DeclarationNode *newnode = new DeclarationNode;
    249261        newnode->type = new TypeData( TypeData::Aggregate );
    250         newnode->type->aggregate->kind = Context;
     262        newnode->type->aggregate->kind = Trait;
    251263        newnode->type->aggregate->params = params;
    252264        newnode->type->aggregate->fields = asserts;
    253265        newnode->type->aggregate->name = assign_strptr( name );
    254266        return newnode;
    255 }
    256 
    257 DeclarationNode *DeclarationNode::newContextUse( std::string *name, ExpressionNode *params ) {
     267} // DeclarationNode::newTrait
     268
     269DeclarationNode *DeclarationNode::newTraitUse( std::string *name, ExpressionNode *params ) {
    258270        DeclarationNode *newnode = new DeclarationNode;
    259271        newnode->type = new TypeData( TypeData::AggregateInst );
    260272        newnode->type->aggInst->aggregate = new TypeData( TypeData::Aggregate );
    261         newnode->type->aggInst->aggregate->aggregate->kind = Context;
     273        newnode->type->aggInst->aggregate->aggregate->kind = Trait;
    262274        newnode->type->aggInst->aggregate->aggregate->name = assign_strptr( name );
    263275        newnode->type->aggInst->params = params;
    264276        return newnode;
    265 }
     277} // DeclarationNode::newTraitUse
    266278
    267279DeclarationNode *DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) {
     
    273285        newnode->type->symbolic->name = newnode->name;
    274286        return newnode;
    275 }
     287} // DeclarationNode::newTypeDecl
    276288
    277289DeclarationNode *DeclarationNode::newPointer( DeclarationNode *qualifiers ) {
     
    279291        newnode->type = new TypeData( TypeData::Pointer );
    280292        return newnode->addQualifiers( qualifiers );
    281 }
     293} // DeclarationNode::newPointer
    282294
    283295DeclarationNode *DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) {
     
    292304        } // if
    293305        return newnode->addQualifiers( qualifiers );
    294 }
     306} // DeclarationNode::newArray
    295307
    296308DeclarationNode *DeclarationNode::newVarArray( DeclarationNode *qualifiers ) {
     
    796808                        errors.append( e );
    797809                } // try
    798                 cur = dynamic_cast< DeclarationNode *>( cur->get_link() );
     810                cur = dynamic_cast<DeclarationNode *>( cur->get_link() );
    799811        } // while
    800812        if ( ! errors.isEmpty() ) {
     
    883895                          ret = new UnionInstType( type->buildQualifiers(), type->aggregate->name );
    884896                          break;
    885                         case DeclarationNode::Context:
    886                           ret = new ContextInstType( type->buildQualifiers(), type->aggregate->name );
     897                        case DeclarationNode::Trait:
     898                          ret = new TraitInstType( type->buildQualifiers(), type->aggregate->name );
    887899                          break;
    888900                        default:
Note: See TracChangeset for help on using the changeset viewer.