55// Copyright (c) 2019, Olof Kraigher olof.kraigher@gmail.com
66
77use super :: named_entity:: * ;
8+ use super :: visibility:: Visibility ;
89use super :: * ;
910use crate :: ast:: * ;
1011use crate :: data:: * ;
@@ -14,16 +15,15 @@ use region::*;
1415impl < ' a > AnalyzeContext < ' a > {
1516 pub fn analyze_primary_unit (
1617 & self ,
17- ent : EntRef < ' a > ,
1818 unit : & mut AnyPrimaryUnit ,
1919 diagnostics : & mut dyn DiagnosticHandler ,
2020 ) -> FatalResult {
2121 match unit {
22- AnyPrimaryUnit :: Entity ( unit) => self . analyze_entity ( ent , unit, diagnostics) ,
22+ AnyPrimaryUnit :: Entity ( unit) => self . analyze_entity ( unit, diagnostics) ,
2323 AnyPrimaryUnit :: Configuration ( unit) => self . analyze_configuration ( unit, diagnostics) ,
24- AnyPrimaryUnit :: Package ( unit) => self . analyze_package ( ent , unit, diagnostics) ,
24+ AnyPrimaryUnit :: Package ( unit) => self . analyze_package ( unit, diagnostics) ,
2525 AnyPrimaryUnit :: PackageInstance ( unit) => {
26- self . analyze_package_instance ( ent , unit, diagnostics)
26+ self . analyze_package_instance ( unit, diagnostics)
2727 }
2828 AnyPrimaryUnit :: Context ( unit) => self . analyze_context ( unit, diagnostics) ,
2929 }
@@ -42,10 +42,17 @@ impl<'a> AnalyzeContext<'a> {
4242
4343 fn analyze_entity (
4444 & self ,
45- ent : EntRef < ' a > ,
4645 unit : & mut EntityDeclaration ,
4746 diagnostics : & mut dyn DiagnosticHandler ,
4847 ) -> FatalResult {
48+ // Pre-define entity and overwrite it later
49+ let ent = self . arena . explicit (
50+ unit. name ( ) . clone ( ) ,
51+ self . work_library ( ) ,
52+ AnyEntKind :: Design ( Design :: Entity ( Visibility :: default ( ) , Region :: default ( ) ) ) ,
53+ Some ( unit. pos ( ) ) ,
54+ ) ;
55+
4956 unit. ident . decl = Some ( ent. id ( ) ) ;
5057 let root_scope = Scope :: default ( ) ;
5158 self . add_implicit_context_clause ( & root_scope) ?;
@@ -123,10 +130,16 @@ impl<'a> AnalyzeContext<'a> {
123130
124131 fn analyze_package (
125132 & self ,
126- ent : EntRef < ' a > ,
127133 unit : & mut PackageDeclaration ,
128134 diagnostics : & mut dyn DiagnosticHandler ,
129135 ) -> FatalResult {
136+ let ent = self . arena . explicit (
137+ unit. name ( ) . clone ( ) ,
138+ self . work_library ( ) ,
139+ AnyEntKind :: Design ( Design :: Package ( Visibility :: default ( ) , Region :: default ( ) ) ) ,
140+ Some ( unit. pos ( ) ) ,
141+ ) ;
142+
130143 unit. ident . decl = Some ( ent. id ( ) ) ;
131144
132145 let root_scope = Scope :: default ( ) ;
@@ -165,10 +178,16 @@ impl<'a> AnalyzeContext<'a> {
165178
166179 fn analyze_package_instance (
167180 & self ,
168- ent : EntRef < ' a > ,
169181 unit : & mut PackageInstantiation ,
170182 diagnostics : & mut dyn DiagnosticHandler ,
171183 ) -> FatalResult {
184+ let ent = self . arena . explicit (
185+ unit. name ( ) . clone ( ) ,
186+ self . work_library ( ) ,
187+ AnyEntKind :: Design ( Design :: PackageInstance ( Region :: default ( ) ) ) ,
188+ Some ( unit. pos ( ) ) ,
189+ ) ;
190+
172191 unit. ident . decl = Some ( ent. id ( ) ) ;
173192 let root_scope = Scope :: default ( ) ;
174193 self . add_implicit_context_clause ( & root_scope) ?;
0 commit comments