public bool Equal(Declaration opponent) { if (opponent == null) { return(false); } if (Name == opponent.Name) { if (NameSpace == null && opponent.NameSpace == null) { return(true); } else if (NameSpace != null) { if (NameSpace.Equal(opponent.NameSpace)) { return(true); } //foreach (var sibling in NameSpace.Siblings) // if (sibling.Equal(opponent.NameSpace)) // return true; } } foreach (var sibling in Siblings) { if (sibling.Equal(opponent)) { return(true); } } return(false); }
private DeclarationType GetDeclarationType(LuaNode variable, LuaBlockNode block, out Declaration namespaces) { namespaces = null; if (variable is LuaIdentifierNode) { foreach (var localDeclaration in block.Locals) { if (variable.AsString == localDeclaration.Name) { return DeclarationType.None; } } foreach (var globalDeclaration in block.Globals) { if (variable.AsString == globalDeclaration.Name) { return DeclarationType.None; } } } else if (variable is LuaTableAccessNode) { foreach (var localDeclaration in block.Locals) { //List<string> names = new List<string>(variable.AsString.Split('.')); Declaration dummyDeclaration = DeclarationHelper.BuildDeclaration(variable.AsString); if (dummyDeclaration.Equal(localDeclaration)) return DeclarationType.None; if (dummyDeclaration.NameSpace != null && dummyDeclaration.NameSpace.Equal(localDeclaration)) { namespaces = localDeclaration; return DeclarationType.Local; } } foreach (var globalDeclaration in block.Globals) { //List<string> names = new List<string>(variable.AsString.Split('.')); Declaration dummyDeclaration = DeclarationHelper.BuildDeclaration(variable.AsString); if (dummyDeclaration.Equal(globalDeclaration)) return DeclarationType.None; if (dummyDeclaration.NameSpace != null && dummyDeclaration.NameSpace.Equal(globalDeclaration)) { namespaces = globalDeclaration; return DeclarationType.Global; } } } return DeclarationType.Global; }
public static bool TryGetExpressionDeclaration(LuaNode expr, LuaBlockNode block, LuaModel model, out Declaration declaration) { declaration = null; if (expr is LuaIdentifierNode) { foreach (var localDeclaration in block.Locals) { if (expr.AsString == localDeclaration.Name) { declaration = localDeclaration; return(true); } } foreach (var globalDeclaration in block.Globals) { if (expr.AsString == globalDeclaration.Name) { declaration = globalDeclaration; return(true); } } foreach (var globalDeclaration in block.Requires) { if (expr.AsString == globalDeclaration.Name) { declaration = globalDeclaration; // clear siblings in case of adding duplicate declaration declaration.ClearSiblingsinFile(model.FilePath); return(true); } } } else if (expr is LuaTableAccessNode) { foreach (var localDeclaration in block.Locals) { Declaration dummyDeclaration = BuildDeclaration(expr.AsString); if (dummyDeclaration.Equal(localDeclaration)) { declaration = localDeclaration; return(true); } } foreach (var globalDeclaration in block.Globals) { Declaration dummyDeclaration = BuildDeclaration(expr.AsString); if (dummyDeclaration.Equal(globalDeclaration)) { declaration = globalDeclaration; return(true); } } foreach (var globalDeclaration in block.Requires) { Declaration dummyDeclaration = BuildDeclaration(expr.AsString); if (dummyDeclaration.Equal(globalDeclaration)) { declaration = globalDeclaration; // clear siblings in case of adding duplicate declaration declaration.ClearSiblingsinFile(model.FilePath); return(true); } } } return(false); }