This commit is contained in:
Ivan Bondarev 2021-11-07 11:39:36 +01:00
parent 6d798fcce5
commit 289bf45e82
4 changed files with 35 additions and 1 deletions

View file

@ -518,9 +518,20 @@ namespace PascalABCCompiler.NETGenerator {
private MethodInfo arr_mi=null; private MethodInfo arr_mi=null;
private Hashtable pas_defs = new Hashtable(); private Hashtable pas_defs = new Hashtable();
private Hashtable memoized_exprs = new Hashtable(); private Hashtable memoized_exprs = new Hashtable();
private Hashtable dummy_methods = new Hashtable();
public Helper() {} public Helper() {}
public void AddDummyMethod(TypeBuilder tb, MethodBuilder mb)
{
dummy_methods[tb] = mb;
}
public MethodBuilder GetDummyMethod(TypeBuilder tb)
{
return dummy_methods[tb] as MethodBuilder;
}
public void AddPascalTypeReference(ITypeNode tn, Type t) public void AddPascalTypeReference(ITypeNode tn, Type t)
{ {
pas_defs[tn] = t; pas_defs[tn] = t;

View file

@ -276,9 +276,13 @@ namespace PascalABCCompiler.NETGenerator
if (ConvertedConstants.ContainsKey(c)) if (ConvertedConstants.ContainsKey(c))
return ConvertedConstants[c]; return ConvertedConstants[c];
ILGenerator ilb = il; ILGenerator ilb = il;
il = ModulesInitILGenerators[cur_unit_type]; if (entry_type != null && false)
il = ModulesInitILGenerators[entry_type];
else
il = ModulesInitILGenerators[cur_unit_type];
ConvertConstantDefinitionNode(null, GetTempName(), c.type, c); ConvertConstantDefinitionNode(null, GetTempName(), c.type, c);
il = ilb; il = ilb;
il.Emit(OpCodes.Call, helper.GetDummyMethod(cur_unit_type));
return ConvertedConstants[c]; return ConvertedConstants[c];
} }
@ -789,6 +793,9 @@ namespace PascalABCCompiler.NETGenerator
if (save_debug_info) doc = sym_docs[cnns[iii].Location == null ? SourceFileName : cnns[iii].Location.document.file_name]; if (save_debug_info) doc = sym_docs[cnns[iii].Location == null ? SourceFileName : cnns[iii].Location.document.file_name];
cur_type = NamespacesTypes[cnns[iii]]; cur_type = NamespacesTypes[cnns[iii]];
cur_unit_type = NamespacesTypes[cnns[iii]]; cur_unit_type = NamespacesTypes[cnns[iii]];
MethodBuilder mb = cur_unit_type.DefineMethod("$dummy$", MethodAttributes.Public | MethodAttributes.Static);
mb.GetILGenerator().Emit(OpCodes.Ret);
helper.AddDummyMethod(cur_unit_type, mb);
ConvertTypeMemberHeaders(cnns[iii].types); ConvertTypeMemberHeaders(cnns[iii].types);
} }

View file

@ -0,0 +1,12 @@
unit u_classconst2;
type
t1 = class
public const arr: array of string = ('abc', 'def');
public static function f1: array of string := arr;
end;
begin
end.

View file

@ -0,0 +1,4 @@
uses u_classconst2;
begin
assert(ArrEqual(t1.f1, |'abc','def'|));
end.