Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r561354f r45e753c  
    279279} // DeclarationNode::newEnum
    280280
    281 DeclarationNode * 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
    289 
    290 
    291281DeclarationNode * DeclarationNode::newName( const string * name ) {
    292282        DeclarationNode * newnode = new DeclarationNode;
     
    315305        } // if
    316306} // DeclarationNode::newEnumValueGeneric
    317 
    318 DeclarationNode * DeclarationNode::newDataConstructor( const string * name ) {
    319         DeclarationNode * newnode = newName(name);
    320         return newnode;
    321 }
    322307
    323308DeclarationNode * DeclarationNode::newEnumInLine( const string name ) {
     
    10981083        }
    10991084        return nullptr;
    1100 }
    1101 
    1102 std::vector<ast::ptr<ast::StructDecl>> buildDataConstructors( DeclarationNode * firstNode ) {
    1103         std::vector<ast::ptr<ast::StructDecl>> outputList;
    1104         std::back_insert_iterator<std::vector<ast::ptr<ast::StructDecl>>> out( outputList );
    1105         for ( const DeclarationNode * cur = firstNode; cur; cur = strict_next( cur ) ) {
    1106                 // td->kind == TypeData::Symbolic
    1107                 assert( cur->type->kind == TypeData::Symbolic );
    1108                 const std::string * name = cur->name;
    1109                 auto ctor = new ast::StructDecl( cur->location,
    1110                         std::string(*name),
    1111                         ast::AggregateDecl::Aggregate::Struct
    1112                 );
    1113                 ctor->set_body(true);
    1114                 TypeData * td = cur->type;
    1115                 TypeData::Symbolic_t st = td->symbolic;
    1116                 DeclarationNode * params = st.params;
    1117                
    1118                 if ( params ) {
    1119                         buildList( params, ctor->members );
    1120                 }
    1121 
    1122                 for ( std::size_t i = 0; i < ctor->members.size(); ++i ) {
    1123                         assert(ctor->members[i]->name == "");
    1124                         ast::Decl * member = ctor->members[i].get_and_mutate();
    1125                         member->name = "field_" + std::to_string(i);
    1126                 }
    1127                 *out++ = ctor;         
    1128         }
    1129         return outputList;
    1130 }
    1131 
    1132 ast::UnionDecl * buildDataUnion( const CodeLocation & loc, const std::vector<ast::ptr<ast::StructDecl>> & typeList ) {
    1133         ast::UnionDecl * out = new ast::UnionDecl( loc, "temp_data_union" );
    1134         // size_t index = 0;
    1135         if ( typeList.size() > 0 ) out->set_body( true );
    1136         size_t i = 0;
    1137         for (const ast::ptr<ast::StructDecl> structDecl : typeList ) {
    1138                 ast::StructInstType * inst = new ast::StructInstType(structDecl);
    1139                 ast::ObjectDecl * instObj = new ast::ObjectDecl(
    1140                         structDecl->location,
    1141                         "option_" + std::to_string(i),
    1142                         inst
    1143                 );
    1144                 i++;
    1145                 out->members.push_back( instObj );
    1146 
    1147         }
    1148         return out;
    1149 }
    1150 
    1151 ast::EnumDecl * buildTag( const CodeLocation & loc, std::vector<ast::ptr<ast::StructDecl>> & typeList ) {
    1152         ast::EnumDecl * out = new ast::EnumDecl( loc, "temp_data_tag" );
    1153         if ( typeList.size() > 0 ) out->set_body( true );
    1154         for ( const ast::ptr<ast::StructDecl> structDecl : typeList ) {
    1155                 ast::EnumInstType * inst = new ast::EnumInstType( out );
    1156                 assert( inst->base != nullptr );
    1157                 ast::ObjectDecl * instObj = new ast::ObjectDecl(
    1158                         structDecl->location,
    1159                         structDecl->name,
    1160                         inst
    1161                 );
    1162                 out->members.push_back( instObj );
    1163         }
    1164         return out;
    1165 }
    1166 
    1167 ast::StructDecl * buildTaggedUnions( const TypeData * data, const ast::EnumDecl * tags, const ast::UnionDecl * data_union ) {
    1168         assert( tags->members.size() == data_union->members.size() );
    1169         ast::StructDecl * out = new ast::StructDecl( data->location, *(data->adt.name) );
    1170         out->kind = ast::AggregateDecl::Adt;
    1171 
    1172         out->set_body( true );
    1173 
    1174         ast::EnumInstType * tag = new ast::EnumInstType( tags );
    1175         ast::ObjectDecl * tag_obj = new ast::ObjectDecl(
    1176                 data->location,
    1177                 "tag",
    1178                 tag
    1179         );
    1180         ast::UnionInstType * value = new ast::UnionInstType( data_union );
    1181         ast::ObjectDecl * value_obj = new ast::ObjectDecl(
    1182                 data->location,
    1183                 "value",
    1184                 value
    1185         );
    1186 
    1187         out->members.push_back( value_obj );
    1188         out->members.push_back( tag_obj );
    1189         return out;
    11901085}
    11911086
Note: See TracChangeset for help on using the changeset viewer.