Changeset 561354f for src/Parser
- Timestamp:
- May 17, 2023, 1:33:39 AM (2 years ago)
- Branches:
- ADT
- Children:
- d6c464d
- Parents:
- 28f8f15
- Location:
- src/Parser
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r28f8f15 r561354f 279 279 } // DeclarationNode::newEnum 280 280 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 } 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 287 289 288 290 … … 1098 1100 } 1099 1101 1100 void buildDataConstructors( DeclarationNode * firstNode, std::vector<ast::ptr<ast::StructDecl>> & outputList ) { 1102 std::vector<ast::ptr<ast::StructDecl>> buildDataConstructors( DeclarationNode * firstNode ) { 1103 std::vector<ast::ptr<ast::StructDecl>> outputList; 1101 1104 std::back_insert_iterator<std::vector<ast::ptr<ast::StructDecl>>> out( outputList ); 1102 1105 for ( const DeclarationNode * cur = firstNode; cur; cur = strict_next( cur ) ) { … … 1124 1127 *out++ = ctor; 1125 1128 } 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 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" ); 1130 1134 // size_t index = 0; 1131 1135 if ( typeList.size() > 0 ) out->set_body( true ); … … 1145 1149 } 1146 1150 1147 ast::EnumDecl * buildTag( ast::EnumDecl * data, conststd::vector<ast::ptr<ast::StructDecl>> & typeList ) {1148 ast::EnumDecl * out = new ast::EnumDecl( data->location, "temp_data_tag" );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" ); 1149 1153 if ( typeList.size() > 0 ) out->set_body( true ); 1150 1154 for ( const ast::ptr<ast::StructDecl> structDecl : typeList ) { … … 1161 1165 } 1162 1166 1163 ast::StructDecl * buildTaggedUnions( const ast::EnumDecl* data, const ast::EnumDecl * tags, const ast::UnionDecl * data_union ) {1167 ast::StructDecl * buildTaggedUnions( const TypeData * data, const ast::EnumDecl * tags, const ast::UnionDecl * data_union ) { 1164 1168 assert( tags->members.size() == data_union->members.size() ); 1165 ast::StructDecl * out = new ast::StructDecl( data->location, data->name);1166 out->kind = ast::AggregateDecl::A DT;1169 ast::StructDecl * out = new ast::StructDecl( data->location, *(data->adt.name) ); 1170 out->kind = ast::AggregateDecl::Adt; 1167 1171 1168 1172 out->set_body( true ); -
src/Parser/DeclarationNode.h
r28f8f15 r561354f 77 77 78 78 // Experimental algebric data type 79 static DeclarationNode * newA DT( const std::string * name, DeclarationNode * constructors );79 static DeclarationNode * newAdt( const std::string * name, DeclarationNode * constructors ); 80 80 static DeclarationNode * newDataConstructor( const std::string * name ); 81 81 // static DeclarationNode * newDataConstructor( const std::string * name, DeclarationNode * typeSpecifiers ); … … 216 216 void buildList( DeclarationNode * firstNode, std::vector<ast::ptr<ast::DeclWithType>> & outputList ); 217 217 void 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 219 std::vector<ast::ptr<ast::StructDecl>> buildDataConstructors( DeclarationNode * firstNode ); 220 ast::UnionDecl * buildDataUnion( const CodeLocation & loc, const std::vector<ast::ptr<ast::StructDecl>> & typeList ); 221 ast::EnumDecl * buildTag( const CodeLocation & loc, std::vector<ast::ptr<ast::StructDecl>> & typeList ); 222 ast::StructDecl * buildTaggedUnions( const TypeData * data, const ast::EnumDecl * tag, const ast::UnionDecl * data_union ); 222 223 223 224 template<typename AstType, typename NodeType, -
src/Parser/TypeData.cc
r28f8f15 r561354f 59 59 enumeration.anon = false; 60 60 break; 61 case Adt: 62 adt.name = nullptr; 63 adt.data_constructors = nullptr; 64 break; 61 65 case Aggregate: 62 66 aggregate.kind = ast::AggregateDecl::NoAggregate; … … 160 164 delete qualified.child; 161 165 break; 166 case Adt: 167 delete adt.data_constructors; 168 delete adt.name; 169 break; 162 170 } // switch 163 171 } // TypeData::~TypeData … … 217 225 newtype->enumeration.body = enumeration.body; 218 226 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 ); 219 232 break; 220 233 case Symbolic: … … 459 472 case Enum: 460 473 return enumeration.name; 474 case Adt: 475 return adt.name; 461 476 case Symbolic: 462 477 case SymbolicInst: … … 822 837 case TypeData::Symbolic: 823 838 case TypeData::Enum: 839 case TypeData::Adt: 824 840 case TypeData::Aggregate: 825 841 assert( false ); … … 1261 1277 buildList( td->enumeration.constants, ret->members ); 1262 1278 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() ); 1267 1284 } 1268 1285 1269 if ( ret->data_constructors.size() > 0 ) ret->isData = true;1286 // if ( ret->data_constructors.size() > 0 ) ret->isData = true; 1270 1287 auto members = ret->members.begin(); 1271 1288 ret->hide = td->enumeration.hiding == EnumHiding::Hide ? ast::EnumDecl::EnumHiding::Hide : ast::EnumDecl::EnumHiding::Visible; … … 1294 1311 return ret; 1295 1312 } // buildEnum 1313 1314 ast::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 } 1296 1325 1297 1326 … … 1437 1466 } else if ( td->kind == TypeData::Enum ) { 1438 1467 return buildEnum( td, std::move( attributes ), linkage ); 1468 } else if ( td->kind == TypeData::Adt) { 1469 return buildAdt( td, std::move( attributes), linkage ); 1439 1470 } else if ( td->kind == TypeData::Symbolic ) { 1440 1471 return buildSymbolic( td, std::move( attributes ), name, scs, linkage ); -
src/Parser/TypeData.h
r28f8f15 r561354f 25 25 struct TypeData { 26 26 enum Kind { Basic, Pointer, Reference, Array, Function, Aggregate, AggregateInst, Enum, EnumConstant, Symbolic, 27 SymbolicInst, Tuple, Basetypeof, Typeof, Vtable, Builtin, GlobalScope, Qualified, A DT, Ctor, Unknown };27 SymbolicInst, Tuple, Basetypeof, Typeof, Vtable, Builtin, GlobalScope, Qualified, Adt, Ctor, Unknown }; 28 28 29 29 struct Aggregate_t { … … 65 65 struct ADT_t { 66 66 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; 73 68 }; 74 69 … … 112 107 Enumeration_t enumeration; 113 108 ADT_t adt; 114 Constructor_t data_constructor;115 109 116 110 Function_t function; … … 140 134 ast::TypeDecl * buildVariable( const TypeData * ); 141 135 ast::EnumDecl * buildEnum( const TypeData *, std::vector<ast::ptr<ast::Attribute>> &&, ast::Linkage::Spec ); 136 ast::EnumDecl * buildAst( const TypeData *, std::vector<ast::ptr<ast::Attribute>> &&, ast::Linkage::Spec ); 142 137 ast::TypeInstType * buildSymbolicInst( const TypeData * ); 143 138 ast::TupleType * buildTuple( const TypeData * ); -
src/Parser/parser.yy
r28f8f15 r561354f 2702 2702 '{' value_list '}' 2703 2703 { 2704 $$ = DeclarationNode::newA DT( $2, $5 );2704 $$ = DeclarationNode::newAdt( $2, $5 ); 2705 2705 } 2706 2706 ;
Note:
See TracChangeset
for help on using the changeset viewer.