Yield: some static names capture fix

This commit is contained in:
Oleg Batashov 2016-06-14 23:28:40 +03:00
parent 9ea7408b6b
commit 3d5ac1042c
4 changed files with 30 additions and 12 deletions

View file

@ -662,7 +662,10 @@ namespace PascalABCCompiler.SyntaxTree
{
var sb = new System.Text.StringBuilder();
sb.Append("procedure ");
sb.Append(name.ToString());
if (name != null)
sb.Append(name.ToString());
else
sb.Append("NONAME");
if (template_args != null)
sb.Append("<" + template_args.ToString() + ">");
@ -1175,7 +1178,7 @@ namespace PascalABCCompiler.SyntaxTree
{ }
public override string ToString()
{
return "new "+this.type.ToString()+"("+this.params_list.ToString()+")";
return "new "+ (this.type != null ? this.type.ToString() : "NOTYPE") + "(" +(this.params_list != null ? this.params_list.ToString() : "NOPARAMS") + ")";
}
}
@ -1459,6 +1462,7 @@ namespace PascalABCCompiler.SyntaxTree
{
protected ident _UnknownID;
protected ident _ClassName;
protected bool _IsYieldInStaticMethod;
public ident UnknownID
{
@ -1472,24 +1476,32 @@ namespace PascalABCCompiler.SyntaxTree
set { _ClassName = value; }
}
///<summary>
///Конструктор с параметрами.
///</summary>
public yield_unknown_ident(ident _UnknownID, ident _ClassName)
public bool IsYieldInStaticMethod
{
this._name = _UnknownID.name;
this._UnknownID = _UnknownID;
this._ClassName = _ClassName;
get { return _IsYieldInStaticMethod; }
set { _IsYieldInStaticMethod = value; }
}
///<summary>
///Конструктор с параметрами.
///</summary>
public yield_unknown_ident(ident _UnknownID, ident _ClassName, SourceContext sc)
public yield_unknown_ident(ident _UnknownID, ident _ClassName, bool isYieldInStaticMethod = false)
{
this._name = _UnknownID.name;
this._UnknownID = _UnknownID;
this._ClassName = _ClassName;
this._IsYieldInStaticMethod = isYieldInStaticMethod;
}
///<summary>
///Конструктор с параметрами.
///</summary>
public yield_unknown_ident(ident _UnknownID, ident _ClassName, bool isYieldInStaticMethod, SourceContext sc)
{
this._name = _UnknownID.name;
this._UnknownID = _UnknownID;
this._ClassName = _ClassName;
this._IsYieldInStaticMethod = isYieldInStaticMethod;
source_context = sc;
}
}

View file

@ -18998,6 +18998,7 @@ namespace PascalABCCompiler.TreeConverter
private bool CheckUnknownIdentNeedsClassCapture(SyntaxTree.yield_unknown_ident _unk, out bool isStaticIdent)
{
string Consts__Self = YieldHelpers.YieldConsts.Self;
// Find semantic class containing iterator (yield-method) with unknown ident
@ -19031,6 +19032,9 @@ namespace PascalABCCompiler.TreeConverter
|| found.sym_info is compiled_function_node
|| found.sym_info is compiled_property_node)
{
if (!isStaticIdent && _unk.IsYieldInStaticMethod)
return false;
// frninja 06/06/16 - фиксим private того же модуля
if ((iteratorContainingClass is common_type_node)
&& this.GetUnknownIdentUnit(found.sym_info) ==

View file

@ -755,6 +755,7 @@ namespace SyntaxVisitors
capturedLocalsNamesMap,
capturedFormalParamsNamesMap,
IsClassMethod(pd),
pd.proc_header.class_keyword,
GetClassName(pd)
);
// Replace

View file

@ -23,6 +23,7 @@ namespace SyntaxVisitors
private IDictionary<string, string> CapturedFormalParamsMap = new Dictionary<string, string>();
private bool IsInClassMethod = true;
private bool IsStaticMethod = false;
private ident ClassName;
@ -35,7 +36,7 @@ namespace SyntaxVisitors
IEnumerable<string> unitGlobals,
IDictionary<string, string> localsMap,
IDictionary<string, string> formalParamsMap,
bool isInClassMethod, ident className)
bool isInClassMethod, bool isStaticMethod, ident className)
{
CollectedLocals = new HashSet<string>(locals);
CollectedFormalParams = new HashSet<string>(formalParams);
@ -120,7 +121,7 @@ namespace SyntaxVisitors
if (!id.name.StartsWith("<")) // Check for already captured
{
Replace(id, new yield_unknown_ident(id, ClassName));
Replace(id, new yield_unknown_ident(id, ClassName, this.IsStaticMethod));
}
}
}