bug fix #888
This commit is contained in:
Бондарев Иван 2018-06-03 12:46:06 +02:00
parent 68627c6908
commit a2c16c54cb
8 changed files with 140 additions and 37 deletions

View file

@ -59,7 +59,7 @@ namespace SyntaxVisitors
else
{
// Нескольких переменных тут всё равно не будет - это ошибка
ReplaceStatement(vs, SeqStatements(vs.var_def.vars.idents.Select(id => new assign(id, vs.var_def.inital_value)).ToArray()));
ReplaceStatement(vs, SeqStatements(vs.var_def.vars.idents.Select(id => new assign(id, vs.var_def.inital_value, vs.source_context)).ToArray()));
}
LocalDeletedDefsNames.UnionWith(vs.var_def.vars.idents.Select(id => id.name));

14
TestSuite/yieldnil2.pas Normal file
View file

@ -0,0 +1,14 @@
type
t1 = class end;
t2 = class
function f1: sequence of t1;//должен быть какой то класс, sequence of object не вызывает ошибку
begin
yield nil;
end;
end;
begin
var o := new t2;
var o2 := o.f1.ToArray()[0];
assert(o2 = nil);
end.

View file

@ -172,7 +172,10 @@ namespace TreeConverter.LambdaExpressions.Closure
var varName = ((IVAriableDefinitionNode)symbolInfo.SymbolInfo.sym_info).name.ToLower();
var ff = symbolInfo.SymbolInfo.sym_info.GetType();
var isSelfWordInClass = scope is CapturedVariablesTreeNodeClassScope && varName == compiler_string_consts.self_word;
SourceContext sourceCtxt = null;
if (symbolInfo.SymbolInfo.sym_info.location != null)
sourceCtxt = new SourceContext(symbolInfo.SymbolInfo.sym_info.location.begin_line_num, symbolInfo.SymbolInfo.sym_info.location.begin_column_num,
symbolInfo.SymbolInfo.sym_info.location.end_line_num, symbolInfo.SymbolInfo.sym_info.location.end_column_num);
foreach (var referencingLambda in symbolInfo.ReferencingLambdas.OrderByDescending(rl => rl.ScopeIndex))
{
if (scope != referencingLambda.ParentNode)
@ -211,7 +214,7 @@ namespace TreeConverter.LambdaExpressions.Closure
new dot_node(
new ident(
_capturedVarsClassDefs[upperScopeWhereVarsAreCaptured.ScopeIndex]
.GeneratedSubstitutingFieldName), new ident(varName)));
.GeneratedSubstitutingFieldName, sourceCtxt), new ident(varName, sourceCtxt), sourceCtxt));
}
while (upperScopesStack.Count != 0)
@ -246,10 +249,10 @@ namespace TreeConverter.LambdaExpressions.Closure
new dot_node(
new ident(
_capturedVarsClassDefs[upperScopeWhereVarsAreCaptured.ScopeIndex]
.GeneratedSubstitutingFieldName),
.GeneratedSubstitutingFieldName, sourceCtxt),
new ident(
_capturedVarsClassDefs[upperScopeWhereVarsAreCaptured.ScopeIndex]
.GeneratedUpperClassFieldName));
.GeneratedUpperClassFieldName, sourceCtxt), sourceCtxt);
var nodeForDotNodeCalc = upperScopeWhereVarsAreCaptured.ParentNode;
while (nodeForDotNodeCalc != scope)
@ -269,7 +272,7 @@ namespace TreeConverter.LambdaExpressions.Closure
}
if (!isSelfWordInClass)
{
dotnode = new dot_node(dotnode, new ident(varName));
dotnode = new dot_node(dotnode, new ident(varName, sourceCtxt), sourceCtxt);
}
}
else
@ -277,8 +280,8 @@ namespace TreeConverter.LambdaExpressions.Closure
dotnode = new dot_node(new ident(
_capturedVarsClassDefs[
upperScopeWhereVarsAreCaptured.ScopeIndex]
.GeneratedSubstitutingFieldName),
new ident(varName));
.GeneratedSubstitutingFieldName, sourceCtxt),
new ident(varName, sourceCtxt), sourceCtxt);
}
if (!_substitutions.ContainsKey(substKey))
@ -319,7 +322,7 @@ namespace TreeConverter.LambdaExpressions.Closure
{
new ident(
_capturedVarsClassDefs[nextNodeWhereVarsAreCaptured.ScopeIndex]
.GeneratedUpperClassFieldName)
.GeneratedUpperClassFieldName, sourceCtxt)
},
new List<type_definition> {fieldType});
@ -331,13 +334,14 @@ namespace TreeConverter.LambdaExpressions.Closure
new dot_node(
new ident(
_capturedVarsClassDefs[nextNodeWhereVarsAreCaptured.ScopeIndex]
.GeneratedSubstitutingFieldName),
.GeneratedSubstitutingFieldName, sourceCtxt),
new ident(
_capturedVarsClassDefs[nextNodeWhereVarsAreCaptured.ScopeIndex]
.GeneratedUpperClassFieldName)),
.GeneratedUpperClassFieldName), sourceCtxt),
new ident(
_capturedVarsClassDefs[upperScopeWhereVarsAreCaptured.ScopeIndex]
.GeneratedSubstitutingFieldName));
.GeneratedSubstitutingFieldName, sourceCtxt),
sourceCtxt);
}
substKey = new SubstitutionKey(varName, symbolInfo.SyntaxTreeNodeWithVarDeclaration,
@ -362,7 +366,7 @@ namespace TreeConverter.LambdaExpressions.Closure
dot = new dot_node(dot,
new ident(
_capturedVarsClassDefs[nodeForDotNodeCalculation.ScopeIndex]
.GeneratedUpperClassFieldName));
.GeneratedUpperClassFieldName, sourceCtxt), sourceCtxt);
}
nodeForDotNodeCalculation = nodeForDotNodeCalculation.ParentNode;
@ -370,13 +374,13 @@ namespace TreeConverter.LambdaExpressions.Closure
if (!isSelfWordInClass)
{
dot = new dot_node(dot, new ident(varName));
dot = new dot_node(dot, new ident(varName, sourceCtxt), sourceCtxt);
}
if (!_substitutions.ContainsKey(substKey))
{
if (ClassField != null && ClassField.IsStatic)
_substitutions.Add(substKey, new dot_node(ClassName, new ident(varName)));// sc не заполнен, что плохо!
_substitutions.Add(substKey, new dot_node(ClassName, new ident(varName, sourceCtxt), sourceCtxt));// sc не заполнен, что плохо!
else
_substitutions.Add(substKey, dot);
}
@ -397,10 +401,10 @@ namespace TreeConverter.LambdaExpressions.Closure
dotnode1 = new dot_node(ClassName, new ident(varName));
else
dotnode1 = new dot_node(
new ident(compiler_string_consts.self_word),
new ident(compiler_string_consts.self_word, sourceCtxt),
new ident(
_capturedVarsClassDefs[upperScopeWhereVarsAreCaptured.ScopeIndex]
.GeneratedUpperClassFieldName));
.GeneratedUpperClassFieldName, sourceCtxt), sourceCtxt);
if (upperScopeWhereVarsAreCaptured != scope)
{
@ -414,7 +418,7 @@ namespace TreeConverter.LambdaExpressions.Closure
dotnode1 = new dot_node(dotnode1,
new ident(
_capturedVarsClassDefs[nodeForDotNodeCalc.ScopeIndex]
.GeneratedUpperClassFieldName));
.GeneratedUpperClassFieldName, sourceCtxt), sourceCtxt);
}
nodeForDotNodeCalc = nodeForDotNodeCalc.ParentNode;
@ -429,17 +433,17 @@ namespace TreeConverter.LambdaExpressions.Closure
Tuple<string, class_field, semantic_node> publicProperty;
if (classScope.NonPublicMembersNamesMapping.TryGetValue(varName, out publicProperty))
{
dotnode1 = new dot_node(dotnode1, new ident(publicProperty.Item1));
dotnode1 = new dot_node(dotnode1, new ident(publicProperty.Item1, sourceCtxt), sourceCtxt);
}
else
{
if (!(ClassField != null && ClassField.IsStatic))
dotnode1 = new dot_node(dotnode1, new ident(varName));
dotnode1 = new dot_node(dotnode1, new ident(varName, sourceCtxt), sourceCtxt);
}
}
else
{
dotnode1 = new dot_node(dotnode1, new ident(varName));
dotnode1 = new dot_node(dotnode1, new ident(varName, sourceCtxt), sourceCtxt);
}
}
_lambdaIdReferences.Add(new LambdaReferencesSubstitutionInfo
@ -453,8 +457,8 @@ namespace TreeConverter.LambdaExpressions.Closure
else
{
var dotnode1 = new dot_node(
new ident(compiler_string_consts.self_word),
new ident(varName));
new ident(compiler_string_consts.self_word, sourceCtxt),
new ident(varName, sourceCtxt), sourceCtxt);
_lambdaIdReferences.Add(new LambdaReferencesSubstitutionInfo
{
@ -508,13 +512,13 @@ namespace TreeConverter.LambdaExpressions.Closure
new dot_node(
new ident(
_capturedVarsClassDefs[scope.ScopeIndex]
.GeneratedSubstitutingFieldName), new ident(propertyName ?? varName)));
.GeneratedSubstitutingFieldName, sourceCtxt), new ident(propertyName ?? varName, sourceCtxt), sourceCtxt));
}
}
var dotnode1 = new dot_node(
new ident(compiler_string_consts.self_word),
new ident(varName));
new ident(compiler_string_consts.self_word, sourceCtxt),
new ident(varName, sourceCtxt), sourceCtxt);
_lambdaIdReferences.Add(new LambdaReferencesSubstitutionInfo
{

View file

@ -2141,8 +2141,8 @@ namespace PascalABCCompiler.TreeConverter
}
else
{
type_node tn = converted_type.ImplementingInterfaces.Find(x=>(x as type_node).full_name.StartsWith("System.Collections.Generic.IEnumerable")) as type_node;
return new List<SymbolInfo> { new SymbolInfo(tn.instance_params[0]) };
type_node tn = converted_type.ImplementingInterfaces.Find(x=>(x as type_node).BaseFullName.StartsWith("System.Collections.Generic.IEnumerable")) as type_node;
return new List<SymbolInfo> { new SymbolInfo(tn.instance_params[0]) };
}
}

View file

@ -142,6 +142,14 @@ namespace PascalABCCompiler.TreeRealization
}
}
public virtual location location
{
get
{
return null;
}
}
public virtual semantic_node find_by_location(int line, int col)
{
return null;

View file

@ -857,6 +857,14 @@ namespace PascalABCCompiler.TreeRealization
}
}
public override location location
{
get
{
return _loc;
}
}
/// <summary>
/// Расположение имени функции в программе.
/// Используется при обходе дерева посетителем.

View file

@ -861,7 +861,15 @@ namespace PascalABCCompiler.TreeRealization
set { _loc = value; }
}
public ref_type_node(type_node pointed_type)
public override location location
{
get
{
return _loc;
}
}
public ref_type_node(type_node pointed_type)
{
_pointed_type = pointed_type;
SystemLibrary.SystemLibrary.init_reference_type(this);
@ -1116,6 +1124,14 @@ namespace PascalABCCompiler.TreeRealization
_loc = loc;
}
public override location location
{
get
{
return _loc;
}
}
public string name
{
get
@ -1659,7 +1675,15 @@ namespace PascalABCCompiler.TreeRealization
}
}
public SemanticTree.ILocation Location
public override location location
{
get
{
return _loc;
}
}
public SemanticTree.ILocation Location
{
get
{
@ -2374,6 +2398,13 @@ namespace PascalABCCompiler.TreeRealization
set { _loc = value; }
}
public override location location
{
get
{
return _loc;
}
}
/*public short_string_type_node(SemanticTree.type_access_level type_access_level,
common_namespace_node comprehensive_namespace, SymbolTable.ClassScope cs, location loc, int length)
:base(null,type_access_level,comprehensive_namespace,cs,loc)

View file

@ -195,7 +195,15 @@ namespace PascalABCCompiler.TreeRealization
}
}
public bool is_used_as_unlocal
public override location location
{
get
{
return _loc;
}
}
public bool is_used_as_unlocal
{
get
{
@ -292,7 +300,13 @@ namespace PascalABCCompiler.TreeRealization
}
}
public override location location
{
get
{
return _loc;
}
}
public SemanticTree.ILocation Location
{
@ -378,7 +392,15 @@ namespace PascalABCCompiler.TreeRealization
}
}
public SemanticTree.ILocation Location
public override location location
{
get
{
return _loc;
}
}
public SemanticTree.ILocation Location
{
get
{
@ -474,7 +496,15 @@ namespace PascalABCCompiler.TreeRealization
}
}
public SemanticTree.ILocation Location
public override location location
{
get
{
return _loc;
}
}
public SemanticTree.ILocation Location
{
get
{
@ -891,7 +921,15 @@ namespace PascalABCCompiler.TreeRealization
}
}
public SemanticTree.ILocation Location
public override location location
{
get
{
return _loc;
}
}
public SemanticTree.ILocation Location
{
get
{