11use plc_ast:: {
22 ast:: {
33 flatten_expression_list, get_enum_element_name, Assignment , AstFactory , AstNode , AstStatement ,
4- AutoDerefType , DataType , DataTypeDeclaration , RangeStatement , TypeNature , UserTypeDeclaration ,
5- Variable ,
4+ AutoDerefType , DataType , DataTypeDeclaration , LinkageType , RangeStatement , TypeNature ,
5+ UserTypeDeclaration , Variable ,
66 } ,
77 literals:: AstLiteral ,
88 visitor:: { AstVisitor , Walker } ,
@@ -58,9 +58,12 @@ impl AstVisitor for UserTypeIndexer<'_, '_> {
5858
5959 fn visit_data_type ( & mut self , data_type : & DataType ) {
6060 match & data_type {
61- DataType :: StructType { name : Some ( name) , variables } => {
62- self . index_struct_type ( name, variables, StructSource :: OriginalDeclaration )
63- }
61+ DataType :: StructType { name : Some ( name) , variables } => self . index_struct_type (
62+ name,
63+ variables,
64+ StructSource :: OriginalDeclaration ,
65+ self . user_type . linkage ,
66+ ) ,
6467 DataType :: EnumType { name : Some ( name) , numeric_type, elements } => {
6568 self . index_enum_type ( name, numeric_type, elements)
6669 }
@@ -142,6 +145,7 @@ impl UserTypeIndexer<'_, '_> {
142145 } ,
143146 nature : TypeNature :: __VLA,
144147 location : SourceLocation :: internal ( ) ,
148+ linkage : plc_ast:: ast:: LinkageType :: BuiltIn ,
145149 } ) ;
146150
147151 // define internal vla members
@@ -225,6 +229,7 @@ impl UserTypeIndexer<'_, '_> {
225229 inner_type_name : referenced_type,
226230 ndims,
227231 } ) ,
232+ LinkageType :: Internal ,
228233 ) ;
229234 }
230235
@@ -267,7 +272,7 @@ impl UserTypeIndexer<'_, '_> {
267272 dimensions,
268273 } ;
269274
270- self . register_type ( name, information, TypeNature :: Any ) ;
275+ self . register_type ( name, information, TypeNature :: Any , LinkageType :: Internal ) ;
271276 let global_init_name = crate :: index:: get_initializer_name ( name) ;
272277
273278 // TODO unfortunately we cannot share const-expressions between multiple
@@ -321,7 +326,7 @@ impl UserTypeIndexer<'_, '_> {
321326 referenced_type : numeric_type. to_string ( ) ,
322327 } ;
323328
324- self . register_type ( name, information, TypeNature :: Int ) ;
329+ self . register_type ( name, information, TypeNature :: Int , LinkageType :: Internal ) ;
325330 }
326331
327332 fn index_sub_range_type ( & mut self , name : & str , referenced_type : & str , bounds : Option < & AstNode > ) {
@@ -337,16 +342,23 @@ impl UserTypeIndexer<'_, '_> {
337342 DataTypeInformation :: Alias { name : name. into ( ) , referenced_type : referenced_type. into ( ) }
338343 } ;
339344
340- self . register_type ( name, information, TypeNature :: Int ) ;
345+ self . register_type ( name, information, TypeNature :: Int , LinkageType :: Internal ) ;
341346 }
342347
343- fn register_type ( & mut self , name : & str , information : DataTypeInformation , nature : TypeNature ) {
348+ fn register_type (
349+ & mut self ,
350+ name : & str ,
351+ information : DataTypeInformation ,
352+ nature : TypeNature ,
353+ linkage : LinkageType ,
354+ ) {
344355 self . index . register_type ( typesystem:: DataType {
345356 name : name. into ( ) ,
346357 initial_value : self . pending_initializer ,
347358 information,
348359 nature,
349360 location : self . user_type . location . clone ( ) ,
361+ linkage,
350362 } ) ;
351363 }
352364
@@ -357,7 +369,7 @@ impl UserTypeIndexer<'_, '_> {
357369 nature : * nature,
358370 } ;
359371
360- self . register_type ( name, information, TypeNature :: Any ) ;
372+ self . register_type ( name, information, TypeNature :: Any , LinkageType :: Internal ) ;
361373 }
362374
363375 fn index_string_type ( & mut self , name : & str , is_wide : bool , size : Option < & AstNode > ) {
@@ -388,7 +400,7 @@ impl UserTypeIndexer<'_, '_> {
388400 None => TypeSize :: from_literal ( ( DEFAULT_STRING_LEN + 1 ) . into ( ) ) ,
389401 } ;
390402 let information = DataTypeInformation :: String { size, encoding } ;
391- self . register_type ( name, information, TypeNature :: String ) ;
403+ self . register_type ( name, information, TypeNature :: String , LinkageType :: Internal ) ;
392404
393405 //TODO: can we reuse this?
394406 if let Some ( init) = self . pending_initializer {
@@ -434,10 +446,17 @@ impl UserTypeIndexer<'_, '_> {
434446 information,
435447 nature : TypeNature :: Any ,
436448 location : self . user_type . location . clone ( ) ,
449+ linkage : plc_ast:: ast:: LinkageType :: Internal ,
437450 } ) ;
438451 }
439452
440- fn index_struct_type ( & mut self , name : & str , variables : & [ Variable ] , source : StructSource ) {
453+ fn index_struct_type (
454+ & mut self ,
455+ name : & str ,
456+ variables : & [ Variable ] ,
457+ source : StructSource ,
458+ linkage : LinkageType ,
459+ ) {
441460 let scope = Some ( name. to_string ( ) ) ;
442461 let members = variables
443462 . iter ( )
@@ -480,7 +499,7 @@ impl UserTypeIndexer<'_, '_> {
480499 let nature = source. get_type_nature ( ) ;
481500 let information = DataTypeInformation :: Struct { name : name. to_owned ( ) , members, source } ;
482501
483- self . register_type ( name, information, nature) ;
502+ self . register_type ( name, information, nature, linkage ) ;
484503
485504 //Generate an initializer for the struct
486505 let global_struct_name = crate :: index:: get_initializer_name ( name) ;
0 commit comments