Changeset 561354f for src/Parser


Ignore:
Timestamp:
May 17, 2023, 1:33:39 AM (2 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT
Children:
d6c464d
Parents:
28f8f15
Message:

Save progress

Location:
src/Parser
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r28f8f15 r561354f  
    279279} // DeclarationNode::newEnum
    280280
    281 DeclarationNode * DeclarationNode::newADT( const string * name, DeclarationNode * constructors ) {
    282         DeclarationNode * newnode = newEnum( name, nullptr, true, false );
    283         newnode->type->enumeration.isData = true;
    284         newnode->type->enumeration.data_constructors = constructors;
    285         return newnode;
    286 }
     281DeclarationNode * DeclarationNode::newAdt( const string * name, DeclarationNode * constructors ) {
     282        assert( name );
     283        DeclarationNode * newnode = new DeclarationNode;
     284        newnode->type = new TypeData( TypeData::Adt );
     285        newnode->type->adt.name = name;
     286        newnode->type->adt.data_constructors = constructors;
     287        return newnode;
     288} // DeclarationNode::newAdt
    287289
    288290
     
    10981100}
    10991101
    1100 void buildDataConstructors( DeclarationNode * firstNode, std::vector<ast::ptr<ast::StructDecl>> & outputList ) {
     1102std::vector<ast::ptr<ast::StructDecl>> buildDataConstructors( DeclarationNode * firstNode ) {
     1103        std::vector<ast::ptr<ast::StructDecl>> outputList;
    11011104        std::back_insert_iterator<std::vector<ast::ptr<ast::StructDecl>>> out( outputList );
    11021105        for ( const DeclarationNode * cur = firstNode; cur; cur = strict_next( cur ) ) {
     
    11241127                *out++ = ctor;         
    11251128        }
    1126 }
    1127 
    1128 ast::UnionDecl * buildDataUnion( ast::EnumDecl * data, const std::vector<ast::ptr<ast::StructDecl>> & typeList ) {
    1129         ast::UnionDecl * out = new ast::UnionDecl( data->location, "temp_data_union" );
     1129        return outputList;
     1130}
     1131
     1132ast::UnionDecl * buildDataUnion( const CodeLocation & loc, const std::vector<ast::ptr<ast::StructDecl>> & typeList ) {
     1133        ast::UnionDecl * out = new ast::UnionDecl( loc, "temp_data_union" );
    11301134        // size_t index = 0;
    11311135        if ( typeList.size() > 0 ) out->set_body( true );
     
    11451149}
    11461150
    1147 ast::EnumDecl * buildTag( ast::EnumDecl * data, const std::vector<ast::ptr<ast::StructDecl>> & typeList ) {
    1148         ast::EnumDecl * out = new ast::EnumDecl( data->location, "temp_data_tag" );
     1151ast::EnumDecl * buildTag( const CodeLocation & loc, std::vector<ast::ptr<ast::StructDecl>> & typeList ) {
     1152        ast::EnumDecl * out = new ast::EnumDecl( loc, "temp_data_tag" );
    11491153        if ( typeList.size() > 0 ) out->set_body( true );
    11501154        for ( const ast::ptr<ast::StructDecl> structDecl : typeList ) {
     
    11611165}
    11621166
    1163 ast::StructDecl * buildTaggedUnions( const ast::EnumDecl * data, const ast::EnumDecl * tags, const ast::UnionDecl * data_union ) {
     1167ast::StructDecl * buildTaggedUnions( const TypeData * data, const ast::EnumDecl * tags, const ast::UnionDecl * data_union ) {
    11641168        assert( tags->members.size() == data_union->members.size() );
    1165         ast::StructDecl * out = new ast::StructDecl( data->location, data->name );
    1166         out->kind = ast::AggregateDecl::ADT;
     1169        ast::StructDecl * out = new ast::StructDecl( data->location, *(data->adt.name) );
     1170        out->kind = ast::AggregateDecl::Adt;
    11671171
    11681172        out->set_body( true );
  • src/Parser/DeclarationNode.h

    r28f8f15 r561354f  
    7777
    7878        // Experimental algebric data type
    79         static DeclarationNode * newADT( const std::string * name, DeclarationNode * constructors );
     79        static DeclarationNode * newAdt( const std::string * name, DeclarationNode * constructors );
    8080        static DeclarationNode * newDataConstructor( const std::string * name );
    8181        // static DeclarationNode * newDataConstructor( const std::string * name, DeclarationNode * typeSpecifiers );
     
    216216void buildList( DeclarationNode * firstNode, std::vector<ast::ptr<ast::DeclWithType>> & outputList );
    217217void buildTypeList( const DeclarationNode * firstNode, std::vector<ast::ptr<ast::Type>> & outputList );
    218 void buildDataConstructors( DeclarationNode * firstNode, std::vector<ast::ptr<ast::StructDecl>> & outputList );
    219 ast::UnionDecl * buildDataUnion( ast::EnumDecl * data, const std::vector<ast::ptr<ast::StructDecl>> & typeList );
    220 ast::EnumDecl * buildTag( ast::EnumDecl * data, const std::vector<ast::ptr<ast::StructDecl>> & typeList );
    221 ast::StructDecl * buildTaggedUnions( const ast::EnumDecl * data, const ast::EnumDecl * tags, const ast::UnionDecl * data_union );
     218
     219std::vector<ast::ptr<ast::StructDecl>> buildDataConstructors( DeclarationNode * firstNode );
     220ast::UnionDecl * buildDataUnion( const CodeLocation & loc, const std::vector<ast::ptr<ast::StructDecl>> & typeList );
     221ast::EnumDecl * buildTag( const CodeLocation & loc, std::vector<ast::ptr<ast::StructDecl>> & typeList );
     222ast::StructDecl * buildTaggedUnions( const TypeData * data, const ast::EnumDecl * tag, const ast::UnionDecl * data_union );
    222223
    223224template<typename AstType, typename NodeType,
  • src/Parser/TypeData.cc

    r28f8f15 r561354f  
    5959                enumeration.anon = false;
    6060                break;
     61        case Adt:
     62                adt.name = nullptr;
     63                adt.data_constructors = nullptr;
     64                break;
    6165        case Aggregate:
    6266                aggregate.kind = ast::AggregateDecl::NoAggregate;
     
    160164                delete qualified.child;
    161165                break;
     166        case Adt:
     167                delete adt.data_constructors;
     168                delete adt.name;
     169                break;
    162170        } // switch
    163171} // TypeData::~TypeData
     
    217225                newtype->enumeration.body = enumeration.body;
    218226                newtype->enumeration.anon = enumeration.anon;
     227                newtype->enumeration.data_constructors = maybeClone( enumeration.data_constructors );
     228                break;
     229        case Adt:
     230                newtype->adt.data_constructors = maybeClone( enumeration.data_constructors );
     231                newtype->adt.name = new string ( *adt.name );
    219232                break;
    220233        case Symbolic:
     
    459472        case Enum:
    460473                return enumeration.name;
     474        case Adt:
     475                return adt.name;
    461476        case Symbolic:
    462477        case SymbolicInst:
     
    822837        case TypeData::Symbolic:
    823838        case TypeData::Enum:
     839        case TypeData::Adt:
    824840        case TypeData::Aggregate:
    825841                assert( false );
     
    12611277        buildList( td->enumeration.constants, ret->members );
    12621278        if ( td->enumeration.data_constructors != nullptr ) {
    1263                 buildDataConstructors( td->enumeration.data_constructors, ret->data_constructors );
    1264                 ret->data_union = buildDataUnion( ret, ret->data_constructors );
    1265                 ret->tag = buildTag( ret, ret->data_constructors );
    1266                 ret->tag_union = buildTaggedUnions( ret, ret->tag.get(), ret->data_union.get() );
     1279                assert( false );
     1280                // ret->data_constructors = buildDataConstructors( td->enumeration.data_constructors );
     1281                // ret->data_union = buildDataUnion( td->location, ret->data_constructors );
     1282                // ret->tag = buildTag( td->location, ret->data_constructors );
     1283                // ret->tag_union = buildTaggedUnions( td, ret->tag.get(), ret->data_union.get() );
    12671284        }
    12681285
    1269         if ( ret->data_constructors.size() > 0 ) ret->isData = true;
     1286        // if ( ret->data_constructors.size() > 0 ) ret->isData = true;
    12701287        auto members = ret->members.begin();
    12711288        ret->hide = td->enumeration.hiding == EnumHiding::Hide ? ast::EnumDecl::EnumHiding::Hide : ast::EnumDecl::EnumHiding::Visible;
     
    12941311        return ret;
    12951312} // buildEnum
     1313
     1314ast::AdtDecl * buildAdt(const TypeData * td,
     1315        std::vector<ast::ptr<ast::Attribute>> && attributes,
     1316        ast::Linkage::Spec linkage ) {
     1317        assert( td->kind == TypeData::Adt );
     1318        ast::AdtDecl * ret = new ast::AdtDecl( td->location, *(td->adt.name) );
     1319        ret->data_constructors = buildDataConstructors( td->adt.data_constructors );
     1320        ret->data_union = buildDataUnion( td->location, ret->data_constructors );
     1321        ret->tag = buildTag( td->location, ret->data_constructors );
     1322        ret->tag_union = buildTaggedUnions( td, ret->tag.get(), ret->data_union.get() );
     1323        return ret;
     1324}
    12961325
    12971326
     
    14371466        } else if ( td->kind == TypeData::Enum ) {
    14381467                return buildEnum( td, std::move( attributes ), linkage );
     1468        } else if ( td->kind == TypeData::Adt) {
     1469                return buildAdt( td, std::move( attributes), linkage );
    14391470        } else if ( td->kind == TypeData::Symbolic ) {
    14401471                return buildSymbolic( td, std::move( attributes ), name, scs, linkage );
  • src/Parser/TypeData.h

    r28f8f15 r561354f  
    2525struct TypeData {
    2626        enum Kind { Basic, Pointer, Reference, Array, Function, Aggregate, AggregateInst, Enum, EnumConstant, Symbolic,
    27                                 SymbolicInst, Tuple, Basetypeof, Typeof, Vtable, Builtin, GlobalScope, Qualified, ADT, Ctor, Unknown };
     27                                SymbolicInst, Tuple, Basetypeof, Typeof, Vtable, Builtin, GlobalScope, Qualified, Adt, Ctor, Unknown };
    2828
    2929        struct Aggregate_t {
     
    6565        struct ADT_t {
    6666                const std::string * name = nullptr;
    67                 DeclarationNode * constructors;
    68         };
    69 
    70         struct Constructor_t {
    71                 const std::string * name;
    72                 DeclarationNode * type; // types?
     67                DeclarationNode * data_constructors;
    7368        };
    7469
     
    112107        Enumeration_t enumeration;
    113108        ADT_t adt;
    114         Constructor_t data_constructor;
    115109
    116110        Function_t function;
     
    140134ast::TypeDecl * buildVariable( const TypeData * );
    141135ast::EnumDecl * buildEnum( const TypeData *, std::vector<ast::ptr<ast::Attribute>> &&, ast::Linkage::Spec );
     136ast::EnumDecl * buildAst( const TypeData *, std::vector<ast::ptr<ast::Attribute>> &&, ast::Linkage::Spec );
    142137ast::TypeInstType * buildSymbolicInst( const TypeData * );
    143138ast::TupleType * buildTuple( const TypeData * );
  • src/Parser/parser.yy

    r28f8f15 r561354f  
    27022702         '{' value_list '}'
    27032703         {
    2704                 $$ = DeclarationNode::newADT( $2, $5 );
     2704                $$ = DeclarationNode::newAdt( $2, $5 );
    27052705         }
    27062706        ;
Note: See TracChangeset for help on using the changeset viewer.