Changeset fa2c005 for src/Parser
- Timestamp:
- Jun 8, 2023, 3:19:43 PM (2 years ago)
- Branches:
- ADT
- Parents:
- 044ae62
- Location:
- src/Parser
- Files:
-
- 4 edited
-
DeclarationNode.cc (modified) (5 diffs)
-
DeclarationNode.h (modified) (1 diff)
-
TypeData.cc (modified) (4 diffs)
-
TypeData.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r044ae62 rfa2c005 1104 1104 std::back_insert_iterator<std::vector<ast::ptr<ast::StructDecl>>> out( outputList ); 1105 1105 for ( const DeclarationNode * cur = firstNode; cur; cur = strict_next( cur ) ) { 1106 // td->kind == TypeData::Symbolic 1106 1107 1107 assert( cur->type->kind == TypeData::Symbolic ); 1108 1108 const std::string * name = cur->name; … … 1125 1125 member->name = "field_" + std::to_string(i); 1126 1126 } 1127 1127 1128 *out++ = ctor; 1128 1129 } … … 1130 1131 } 1131 1132 1132 ast::UnionDecl * buildDataUnion( const CodeLocation & loc, const std::vector<ast::ptr<ast::StructDecl>> & typeList ) { 1133 void buildDataConstructorsAsMember( DeclarationNode * firstNode, ast::AdtDecl * adtDecl ) { 1134 std::back_insert_iterator<std::vector<ast::ptr<ast::Decl>>> out( adtDecl->members ); 1135 for ( const DeclarationNode * cur = firstNode; cur; cur = strict_next( cur ) ) { 1136 1137 assert( cur->type->kind == TypeData::Symbolic ); 1138 const std::string * name = cur->name; 1139 auto ctor = new ast::StructDecl( cur->location, 1140 std::string(*name), 1141 ast::AggregateDecl::Aggregate::Struct 1142 ); 1143 ctor->set_body(true); 1144 TypeData * td = cur->type; 1145 TypeData::Symbolic_t st = td->symbolic; 1146 DeclarationNode * params = st.params; 1147 1148 if ( params ) { 1149 buildList( params, ctor->members ); 1150 } 1151 1152 for ( std::size_t i = 0; i < ctor->members.size(); ++i ) { 1153 assert(ctor->members[i]->name == ""); 1154 ast::Decl * member = ctor->members[i].get_and_mutate(); 1155 member->name = "field_" + std::to_string(i); 1156 } 1157 1158 *out++ = ctor; 1159 } 1160 } 1161 1162 ast::UnionDecl * buildDataUnion( const CodeLocation & loc, const std::vector<ast::ptr<ast::Decl>> & typeList ) { 1133 1163 ast::UnionDecl * out = new ast::UnionDecl( loc, "temp_data_union" ); 1134 1164 // size_t index = 0; 1135 1165 if ( typeList.size() > 0 ) out->set_body( true ); 1136 1166 size_t i = 0; 1137 for (const ast::ptr<ast:: StructDecl> structDecl : typeList ) {1138 ast::StructInstType * inst = new ast::StructInstType( structDecl);1167 for (const ast::ptr<ast::Decl> structDecl : typeList ) { 1168 ast::StructInstType * inst = new ast::StructInstType( structDecl.as< ast::StructDecl >() ); 1139 1169 ast::ObjectDecl * instObj = new ast::ObjectDecl( 1140 1170 structDecl->location, … … 1149 1179 } 1150 1180 1151 ast::EnumDecl * buildTag( const CodeLocation & loc, std::vector<ast::ptr<ast:: StructDecl>> & typeList ) {1181 ast::EnumDecl * buildTag( const CodeLocation & loc, std::vector<ast::ptr<ast::Decl>> & typeList ) { 1152 1182 ast::EnumDecl * out = new ast::EnumDecl( loc, "temp_data_tag" ); 1153 1183 if ( typeList.size() > 0 ) out->set_body( true ); 1154 for ( const ast::ptr<ast:: StructDecl> structDecl : typeList ) {1184 for ( const ast::ptr<ast::Decl> structDecl : typeList ) { 1155 1185 ast::EnumInstType * inst = new ast::EnumInstType( out ); 1156 1186 assert( inst->base != nullptr ); … … 1167 1197 ast::StructDecl * buildTaggedUnions( const TypeData * data, const ast::EnumDecl * tags, const ast::UnionDecl * data_union ) { 1168 1198 assert( tags->members.size() == data_union->members.size() ); 1169 ast::StructDecl * out = new ast::StructDecl( data->location, *(data->adt.name));1199 ast::StructDecl * out = new ast::StructDecl( data->location, (*(data->adt.name)) + "_tag_union" ); 1170 1200 out->kind = ast::AggregateDecl::Adt; 1171 1201 -
src/Parser/DeclarationNode.h
r044ae62 rfa2c005 218 218 219 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 ); 220 void buildDataConstructorsAsMember( DeclarationNode * firstNode, ast::AdtDecl * adtDecl ); 221 ast::UnionDecl * buildDataUnion( const CodeLocation & loc, const std::vector<ast::ptr<ast::Decl>> & typeList ); 222 ast::EnumDecl * buildTag( const CodeLocation & loc, std::vector<ast::ptr<ast::Decl>> & typeList ); 222 223 ast::StructDecl * buildTaggedUnions( const TypeData * data, const ast::EnumDecl * tag, const ast::UnionDecl * data_union ); 223 224 -
src/Parser/TypeData.cc
r044ae62 rfa2c005 81 81 case Symbolic: 82 82 case SymbolicInst: 83 aggregate.kind = ast::AggregateDecl::Aggregate::Undecided; 84 83 85 symbolic.name = nullptr; 84 86 symbolic.params = nullptr; … … 225 227 newtype->enumeration.body = enumeration.body; 226 228 newtype->enumeration.anon = enumeration.anon; 227 newtype->enumeration.data_constructors = maybeClone( enumeration.data_constructors );228 229 break; 229 230 case Adt: 230 newtype->adt.data_constructors = maybeClone( enumeration.data_constructors );231 newtype->adt.data_constructors = maybeClone( adt.data_constructors ); 231 232 newtype->adt.name = new string ( *adt.name ); 232 233 break; … … 1276 1277 ); 1277 1278 buildList( td->enumeration.constants, ret->members ); 1278 if ( td->enumeration.data_constructors != nullptr ) { 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() ); 1284 } 1285 1286 // if ( ret->data_constructors.size() > 0 ) ret->isData = true; 1279 1287 1280 auto members = ret->members.begin(); 1288 1281 ret->hide = td->enumeration.hiding == EnumHiding::Hide ? ast::EnumDecl::EnumHiding::Hide : ast::EnumDecl::EnumHiding::Visible; … … 1317 1310 assert( td->kind == TypeData::Adt ); 1318 1311 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 ); 1312 1313 buildDataConstructorsAsMember( td->adt.data_constructors, ret ); 1314 1315 ret->data_union = buildDataUnion( td->location, ret->members ); 1316 ret->tag = buildTag( td->location, ret->members ); 1322 1317 ret->tag_union = buildTaggedUnions( td, ret->tag.get(), ret->data_union.get() ); 1323 1318 return ret; -
src/Parser/TypeData.h
r044ae62 rfa2c005 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, Adt, Ctor,Unknown };27 SymbolicInst, Tuple, Basetypeof, Typeof, Vtable, Builtin, GlobalScope, Qualified, Adt, Unknown }; 28 28 29 29 struct Aggregate_t { … … 59 59 EnumHiding hiding; 60 60 bool isData = false; 61 62 DeclarationNode * data_constructors = nullptr;63 61 }; 64 62
Note:
See TracChangeset
for help on using the changeset viewer.