Changeset 67cf18c for src/Parser


Ignore:
Timestamp:
May 26, 2017, 6:37:49 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:
01b9928
Parents:
ff03f5c
git-author:
Rob Schluntz <rschlunt@…> (05/26/17 18:34:50)
git-committer:
Rob Schluntz <rschlunt@…> (05/26/17 18:37:49)
Message:

implement default type arguments for generic types [closes #13]

Location:
src/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    rff03f5c r67cf18c  
    5757        variable.tyClass = NoTypeClass;
    5858        variable.assertions = nullptr;
     59        variable.initializer = nullptr;
    5960
    6061//      attr.name = nullptr;
     
    7071//      delete variable.name;
    7172        delete variable.assertions;
     73        delete variable.initializer;
    7274
    7375        delete type;
     
    101103        newnode->variable.tyClass = variable.tyClass;
    102104        newnode->variable.assertions = maybeClone( variable.assertions );
     105        newnode->variable.initializer = maybeClone( variable.initializer );
    103106
    104107//      newnode->attr.name = attr.name ? new string( *attr.name ) : nullptr;
     
    857860}
    858861
     862DeclarationNode * DeclarationNode::addTypeInitializer( DeclarationNode * init ) {
     863        assertf( variable.tyClass != NoTypeClass, "Called addTypeInitializer on something that isn't a type variable." );
     864        variable.initializer = init;
     865        return this;
     866}
     867
    859868DeclarationNode * DeclarationNode::cloneType( string * newName ) {
    860869        DeclarationNode * newnode = new DeclarationNode;
     
    10141023                assertf( sizeof(kindMap)/sizeof(kindMap[0] == NoTypeClass-1), "DeclarationNode::build: kindMap is out of sync." );
    10151024                assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." );
    1016                 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ] );
     1025                TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.initializer ? variable.initializer->buildType() : nullptr );
    10171026                buildList( variable.assertions, ret->get_assertions() );
    10181027                return ret;
  • src/Parser/ParseNode.h

    rff03f5c r67cf18c  
    274274        DeclarationNode * addIdList( DeclarationNode * list ); // old-style functions
    275275        DeclarationNode * addInitializer( InitializerNode * init );
     276        DeclarationNode * addTypeInitializer( DeclarationNode * init );
    276277
    277278        DeclarationNode * cloneType( std::string * newName );
     
    301302                DeclarationNode::TypeClass tyClass;
    302303                DeclarationNode * assertions;
     304                DeclarationNode * initializer;
    303305        };
    304306        Variable_t variable;
  • src/Parser/parser.yy

    rff03f5c r67cf18c  
    16061606
    16071607typegen_name:                                                                                   // CFA
    1608         TYPEGENname '(' type_list ')'
     1608        TYPEGENname '(' ')'
     1609                { $$ = DeclarationNode::newFromTypeGen( $1, nullptr ); }
     1610        | TYPEGENname '(' type_list ')'
    16091611                { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }
    16101612        ;
     
    19831985
    19841986type_parameter_list:                                                                    // CFA
    1985         type_parameter type_initializer_opt
    1986         | type_parameter_list ',' type_parameter type_initializer_opt
     1987        type_parameter
     1988                { $$ = $1; }
     1989        | type_parameter_list ',' type_parameter
    19871990                { $$ = $1->appendList( $3 ); }
    19881991        ;
     
    19982001        type_class no_attr_identifier_or_type_name
    19992002                { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); }
    2000           assertion_list_opt
    2001                 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addAssertions( $4 ); }
     2003          type_initializer_opt assertion_list_opt
     2004                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
    20022005        | type_specifier identifier_parameter_declarator
    20032006        ;
Note: See TracChangeset for help on using the changeset viewer.