diff --git a/compiler/pdecl.pas b/compiler/pdecl.pas index 69aa1f6704..dd73e32e22 100644 --- a/compiler/pdecl.pas +++ b/compiler/pdecl.pas @@ -165,7 +165,7 @@ implementation var orgname : TIDString; hdef : tdef; - sym : tsym; + sym, tmp : tsym; dummysymoptions : tsymoptions; deprecatedmsg : pshortstring; storetokenpos,filepos : tfileposinfo; @@ -173,6 +173,8 @@ implementation skipequal : boolean; tclist : tasmlist; varspez : tvarspez; + static_name : string; + sl : tpropaccesslist; begin old_block_type:=block_type; block_type:=bt_const; @@ -218,10 +220,30 @@ implementation varspez:=vs_const else varspez:=vs_value; - sym:=tstaticvarsym.create(orgname,varspez,hdef,[]); - sym.visibility:=symtablestack.top.currentvisibility; + { if we are dealing with structure const then we need to handle it as a + structure static variable: create a symbol in unit symtable and a reference + to it from the structure or linking will fail } + if symtablestack.top.symtabletype in [recordsymtable,ObjectSymtable] then + begin + { generate the symbol which reserves the space } + static_name:=lower(generate_nested_name(symtablestack.top,'_'))+'_'+orgname; + sym:=tstaticvarsym.create('$_static_'+static_name,varspez,hdef,[]); + include(sym.symoptions,sp_internal); + tabstractrecordsymtable(symtablestack.top).get_unit_symtable.insert(sym); + { generate the symbol for the access } + sl:=tpropaccesslist.create; + sl.addsym(sl_load,sym); + tmp:=tabsolutevarsym.create_ref(orgname,hdef,sl); + tmp.visibility:=symtablestack.top.currentvisibility; + symtablestack.top.insert(tmp); + end + else + begin + sym:=tstaticvarsym.create(orgname,varspez,hdef,[]); + sym.visibility:=symtablestack.top.currentvisibility; + symtablestack.top.insert(sym); + end; current_tokenpos:=storetokenpos; - symtablestack.top.insert(sym); { procvar can have proc directives, but not type references } if (hdef.typ=procvardef) and (hdef.typesym=nil) then diff --git a/compiler/pexpr.pas b/compiler/pexpr.pas index 94455140fb..4efb0521ec 100644 --- a/compiler/pexpr.pas +++ b/compiler/pexpr.pas @@ -1302,9 +1302,17 @@ implementation end; staticvarsym: begin - // typed constant is a staticvarsym + { typed constant is a staticvarsym + now they are absolutevarsym } p1.free; p1:=cloadnode.create(sym,sym.Owner); + end; + absolutevarsym: + begin + p1.free; + p1:=nil; + { typed constants are absolutebarsyms now to handle storage properly } + propaccesslist_to_node(p1,nil,tabsolutevarsym(sym).ref); end else internalerror(16);