public override void ResolveMember(SyntaxTreeNode_Leaf leaf, Scope_Base context, int numTypeArgs, bool asTypeOnly)
    {
        genericTypeDefinition.ResolveMember(leaf, context, numTypeArgs, asTypeOnly);

        var genericMember = leaf.ResolvedSymbol;

        if (genericMember == null)// || genericMember is MethodGroupDefinition)// !genericMember.IsGeneric)
        {
            return;
        }

        SymbolDefinition constructed;

        if (constructedMembers != null && constructedMembers.TryGetValue(genericMember, out constructed))
        {
            leaf.ResolvedSymbol = constructed;
        }
        else
        {
            leaf.ResolvedSymbol = GetConstructedMember(genericMember);
        }

        if (asTypeOnly && !(leaf.ResolvedSymbol is TypeDefinitionBase))
        {
            leaf.ResolvedSymbol = null;
        }
    }
    public override void GetCompletionData(Dictionary <string, SymbolDefinition> data, bool fromInstance, SD_Assembly assembly)
    {
        if (definition != null)
        {
            definition.GetCompletionData(data, fromInstance, assembly);
        }

        Scope_Base scope = this;

        while (fromInstance && scope != null)
        {
            var asBodyScope = scope as Scope_Body;
            if (asBodyScope != null)
            {
                var symbol = asBodyScope.definition;
                if (symbol != null && symbol.kind != SymbolKind.LambdaExpression)
                {
                    if (!symbol.IsInstanceMember)
                    {
                        fromInstance = false;
                    }
                    break;
                }
            }
            scope = scope.parentScope;
        }
        base.GetCompletionData(data, fromInstance, assembly);
    }
示例#3
0
    public override void ResolveMember(SyntaxTreeNode_Leaf leaf, Scope_Base context, int numTypeArgs, bool asTypeOnly)
    {
        base.ResolveMember(leaf, context, numTypeArgs, asTypeOnly);

        if (!resolvingInBase && leaf.ResolvedSymbol == null)
        {
            resolvingInBase = true;

            var baseType   = BaseType();
            var interfaces = Interfaces();

            if (!asTypeOnly && interfaces != null && (kind == SymbolKind.Interface || kind == SymbolKind.TypeParameter))
            {
                foreach (var i in interfaces)
                {
                    i.Definition.ResolveMember(leaf, context, numTypeArgs, asTypeOnly);
                    if (leaf.ResolvedSymbol != null)
                    {
                        resolvingInBase = false;
                        return;
                    }
                }
            }

            if (baseType != null && baseType != this)
            {
                baseType.ResolveMember(leaf, context, numTypeArgs, asTypeOnly);
            }

            resolvingInBase = false;
        }
    }
示例#4
0
    public override void ResolveMember(SyntaxTreeNode_Leaf leaf, Scope_Base context, int numTypeArgs, bool asTypeOnly)
    {
        var symbolType = TypeOf() as TypeDefinitionBase;

        if (symbolType != null)
        {
            symbolType.ResolveMember(leaf, context, numTypeArgs, asTypeOnly);
        }
    }
示例#5
0
 public SD_Assembly GetAssembly()
 {
     for (Scope_Base scope = this; scope != null; scope = scope.parentScope)
     {
         var cuScope = scope as Scope_CompilationUnit;
         if (cuScope != null)
         {
             return(cuScope.assembly);
         }
     }
     throw new Exception("No Assembly for scope???");
 }
示例#6
0
 public override void ResolveMember(SyntaxTreeNode_Leaf leaf, Scope_Base context, int numTypeArgs, bool asTypeOnly)
 {
     if (!asTypeOnly && parameters != null)
     {
         var leafText   = DecodeId(leaf.token.text);
         var definition = parameters.Find(x => x.name == leafText);
         if (definition != null)
         {
             leaf.ResolvedSymbol = definition;
             return;
         }
     }
     base.ResolveMember(leaf, context, numTypeArgs, asTypeOnly);
 }
    public override void ResolveMember(SyntaxTreeNode_Leaf leaf, Scope_Base context, int numTypeArgs, bool asTypeOnly)
    {
        if (asTypeOnly)
        {
            leaf.ResolvedSymbol = null;
            return;
        }

        TypeOf();
        if (type == null || type.Definition == null || type.Definition == unknownType || type.Definition == unknownSymbol)
        {
            leaf.ResolvedSymbol = null;
            return;
        }
        type.Definition.ResolveMember(leaf, context, numTypeArgs, false);
    }
    public void CollectExtensionMethods(
        SD_NameSpace namespaceDefinition,
        string id,
        SymbolReference[] typeArgs,
        TypeDefinitionBase extendedType,
        HashSet <MethodDefinition> extensionsMethods,
        Scope_Base context)
    {
        namespaceDefinition.CollectExtensionMethods(id, typeArgs, extendedType, extensionsMethods, context);

        foreach (var ra in referencedAssemblies)
        {
            var nsDef = ra.FindSameNamespace(namespaceDefinition);
            if (nsDef != null)
            {
                nsDef.CollectExtensionMethods(id, typeArgs, extendedType, extensionsMethods, context);
            }
        }
    }
示例#9
0
    public override void ResolveAttributeMember(SyntaxTreeNode_Leaf leaf, Scope_Base context)
    {
        if (resolvingMember)
        {
            return;
        }
        resolvingMember = true;

        leaf.ResolvedSymbol = null;
        base.ResolveAttributeMember(leaf, context);

        resolvingMember = false;

        if (leaf.ResolvedSymbol == null)
        {
            var assemblyDefinition = context.GetAssembly();
            assemblyDefinition.ResolveAttributeInReferencedAssemblies(leaf, this);
        }
    }
    public override void ResolveMember(SyntaxTreeNode_Leaf leaf, Scope_Base context, int numTypeArgs, bool asTypeOnly)
    {
        if (!allPublicMembersReflected)
        {
            if (!allNonPublicMembersReflected)
            {
                ReflectAllMembers(BindingFlags.Public | BindingFlags.NonPublic);
            }
            else
            {
                ReflectAllMembers(BindingFlags.Public);
            }
        }
        else if (!allNonPublicMembersReflected)
        {
            ReflectAllMembers(BindingFlags.NonPublic);
        }

        base.ResolveMember(leaf, context, numTypeArgs, asTypeOnly);
    }
示例#11
0
    public override void ResolveMember(SyntaxTreeNode_Leaf leaf, Scope_Base context, int numTypeArgs, bool asTypeOnly)
    {
        if (asTypeOnly)
        {
            return;
        }

        if (numTypeArgs == 0)
        {
            var leafText = DecodeId(leaf.token.text);

            if (parameters != null)
            {
                for (var i = parameters.Count; i-- > 0;)
                {
                    if (parameters[i].name == leafText)
                    {
                        leaf.ResolvedSymbol = parameters[i];
                        return;
                    }
                }
            }

            if (typeParameters != null)
            {
                for (var i = typeParameters.Count; i-- > 0;)
                {
                    if (typeParameters[i].name == leafText)
                    {
                        leaf.ResolvedSymbol = typeParameters[i];
                        return;
                    }
                }
            }
        }

        base.ResolveMember(leaf, context, numTypeArgs, asTypeOnly);
    }
示例#12
0
    public override void ResolveMember(SyntaxTreeNode_Leaf leaf, Scope_Base context, int numTypeArgs, bool asTypeOnly)
    {
        if (resolvingMember)
        {
            return;
        }
        resolvingMember = true;

        leaf.ResolvedSymbol = null;

        base.ResolveMember(leaf, context, numTypeArgs, asTypeOnly);

        resolvingMember = false;

        if (leaf.ResolvedSymbol == null)
        {
            if (context != null)
            {
                var assemblyDefinition = context.GetAssembly();
                assemblyDefinition.ResolveInReferencedAssemblies(leaf, this, numTypeArgs);
            }
        }
    }
    public bool IsValid()
    {
        var node = parseTreeNode;

        if (node != null)
        {
            while (node.Parent != null)
            {
                node = node.Parent;
            }
            if (node.RuleName == "compilationUnit")
            {
                return(true);
            }
        }

        if (scope != null)
        {
            scope.RemoveDeclaration(this);
            ++LR_SyntaxTree.resolverVersion;
            if (LR_SyntaxTree.resolverVersion == 0)
            {
                ++LR_SyntaxTree.resolverVersion;
            }
        }
        else if (definition != null)
        {
            Debug.Log("Scope is null for declaration " + name + ". Removing " + definition);
            if (definition.parentSymbol != null)
            {
                definition.parentSymbol.RemoveDeclaration(this);
            }
        }
        scope = null;
        return(false);
    }
    public override SymbolDefinition ResolveMethodOverloads(SyntaxTreeNode_Rule argumentListNode, SymbolReference[] typeArgs, Scope_Base scope, SyntaxTreeNode_Leaf invokedLeaf)
    {
        Modifiers[] modifiers;
        List <TypeDefinitionBase> argumentTypes;

        ProcessArgumentListNode(argumentListNode, out modifiers, out argumentTypes, null);

        var resolved = ResolveMethodOverloads(argumentTypes, modifiers, scope, invokedLeaf);

        return(resolved);
    }
    public virtual MethodDefinition ResolveMethodOverloads(List <TypeDefinitionBase> argumentTypes, Modifiers[] modifiers, Scope_Base scope, SyntaxTreeNode_Leaf invokedLeaf)
    {
        var candidates = CollectCandidates(argumentTypes, modifiers, scope, invokedLeaf);

        if (candidates == null)
        {
            return(unresolvedMethodOverload);
        }

        return(ResolveMethodOverloads(argumentTypes.Count, argumentTypes, modifiers, candidates));
    }
示例#16
0
    public void CollectExtensionMethods(
        string id,
        SymbolReference[] typeArgs,
        TypeDefinitionBase extendedType,
        HashSet <MethodDefinition> extensionsMethods,
        Scope_Base context)
    {
        var numTypeArguments = typeArgs == null ? -1 : typeArgs.Length;

        var contextAssembly = context.GetAssembly();

        for (var i = members.Count; i-- > 0;)
        {
            var typeDefinition = members[i];
            if (typeDefinition.kind != SymbolKind.Class || !typeDefinition.IsValid() || (typeDefinition as TypeDefinitionBase).numExtensionMethods == 0 || !typeDefinition.IsStatic || typeDefinition.NumTypeParameters > 0)
            {
                continue;
            }

            var accessLevelMask = AccessLevelMask.Public;
            if (typeDefinition.Assembly != null && typeDefinition.Assembly.InternalsVisibleIn(contextAssembly))
            {
                accessLevelMask |= AccessLevelMask.Internal;
            }

            if (!typeDefinition.IsAccessible(accessLevelMask))
            {
                continue;
            }

            SymbolDefinition member;
            if (typeDefinition.members.TryGetValue(id, numTypeArguments, out member))
            {
                if (member.kind == SymbolKind.MethodGroup)
                {
                    var methodGroup = member as SD_MethodGroup;
                    if (methodGroup != null)
                    {
                        foreach (var method in methodGroup.methods)
                        {
                            if (method.IsExtensionMethod && method.IsAccessible(accessLevelMask))
                            {
                                var extendsType = method.parameters[0].TypeOf() as TypeDefinitionBase;
                                if (extendedType.CanConvertTo(extendsType))
                                {
                                    if (numTypeArguments > 0)
                                    {
                                        var constructedMethod = method.ConstructMethod(typeArgs);
                                        extensionsMethods.Add(constructedMethod);
                                    }
                                    else
                                    {
                                        extensionsMethods.Add(method);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Debug.LogError("Expected a method group: " + member.GetTooltipText());
                    }
                }
            }
        }
    }
示例#17
0
    public override SymbolDefinition ResolveMethodOverloads(SyntaxTreeNode_Rule argumentListNode, SymbolReference[] typeArgs, Scope_Base scope, SyntaxTreeNode_Leaf invokedLeaf)
    {
        if (kind != SymbolKind.MethodGroup)
        {
            return(null);
        }
        var genericMethod = ((SD_MethodGroup)referencedSymbol).ResolveMethodOverloads(argumentListNode, typeArgs, scope, invokedLeaf);

        if (genericMethod == null || genericMethod.kind != SymbolKind.Method)
        {
            return(null);
        }
        return(((SD_Type_Constructed)parentSymbol).GetConstructedMember(genericMethod));
    }
示例#18
0
 public virtual SymbolDefinition ResolveAsExtensionMethod(SyntaxTreeNode_Leaf invokedLeaf, SymbolDefinition invokedSymbol, TypeDefinitionBase memberOf, SyntaxTreeNode_Rule argumentListNode, SymbolReference[] typeArgs, Scope_Base context)
 {
     return(parentScope != null?parentScope.ResolveAsExtensionMethod(invokedLeaf, invokedSymbol, memberOf, argumentListNode, typeArgs, context) : null);
 }
    public static IEnumerable <SD_SnippetCompletion> EnumSnippets(SymbolDefinition context, TokenSet expected, LexerToken tokenLeft, Scope_Base scope)
    {
        foreach (var snippet in snippets)
        {
            var text = snippet.Value;
            if (IsValid(ref text, context, expected))
            {
                yield return(new SD_SnippetCompletion(snippet.Key + "..."));
            }
        }

        if (snippetsProviders == null)
        {
            snippetsProviders = new List <ISnippetProvider>();
            var types = typeof(CodeSnippets).Assembly.GetTypes();
            foreach (var type in types)
            {
                if (typeof(ISnippetProvider).IsAssignableFrom(type) && type.IsClass && !type.IsAbstract)
                {
                    try
                    {
                        var instance = System.Activator.CreateInstance(type) as ISnippetProvider;
                        snippetsProviders.Add(instance);
                    }
                    catch (System.Exception e)
                    {
                        Debug.LogException(e);
                    }
                }
            }
        }

        foreach (var snippetsProvider in snippetsProviders)
        {
            foreach (var snippet in snippetsProvider.EnumSnippets(context, expected, tokenLeft, scope))
            {
                yield return(snippet);
            }
        }
    }
    public List <MethodDefinition> CollectCandidates(List <TypeDefinitionBase> argumentTypes, Modifiers[] modifiers, Scope_Base scope, SyntaxTreeNode_Leaf invokedLeaf)
    {
        var accessLevelMask = AccessLevelMask.Public;
        var parentType      = parentSymbol as TypeDefinitionBase ?? parentSymbol.parentSymbol as TypeDefinitionBase;
        var contextType     = scope.EnclosingType();

        if (contextType != null)
        {
            if (parentType.Assembly != null && parentType.Assembly.InternalsVisibleIn(contextType.Assembly))
            {
                accessLevelMask |= AccessLevelMask.Internal;
            }

            if (contextType == parentType || parentType.IsSameOrParentOf(contextType))
            {
                accessLevelMask |= AccessLevelMask.Public | AccessLevelMask.Protected | AccessLevelMask.Private;
            }
            else if (contextType.DerivesFrom(parentType))
            {
                accessLevelMask |= AccessLevelMask.Public | AccessLevelMask.Protected;
            }
        }

        var candidates = new List <MethodDefinition>();

        foreach (var method in methods)
        {
            if (!method.IsOverride && method.IsAccessible(accessLevelMask) &&
                (argumentTypes == null || method.CanCallWith(modifiers, false)))
            {
                candidates.Add(method);
            }
        }

        var thisAsConstructedMG = this as SD_ConstructedMethodGroup;

        for (var i = candidates.Count; i-- > 0;)
        {
            var candidate = candidates[i];
            if (thisAsConstructedMG == null)
            {
                if (candidate.NumTypeParameters == 0 || argumentTypes == null)
                {
                    continue;
                }

                candidate = InferMethodTypeArguments(candidate, argumentTypes, invokedLeaf);
                if (candidate == null)
                {
                    candidates.RemoveAt(i);
                }
                else
                {
                    candidates[i] = candidate;
                }
            }
            else
            {
                candidate = candidate.ConstructMethod(thisAsConstructedMG.typeArguments);
            }
        }

        if (candidates.Count != 0)
        {
            return(candidates);
        }

        var baseType = (TypeDefinitionBase)parentSymbol;

        while ((baseType = baseType.BaseType()) != null)
        {
            var baseSymbol = baseType.FindName(name, 0, false) as SD_MethodGroup;
            if (baseSymbol != null)
            {
                return(baseSymbol.CollectCandidates(argumentTypes, modifiers, scope, invokedLeaf));
            }
        }
        return(null);
    }
    public override MethodDefinition ResolveMethodOverloads(List <TypeDefinitionBase> argumentTypes, Modifiers[] modifiers, Scope_Base scope, SyntaxTreeNode_Leaf invokedLeaf)
    {
        var genericMethods = genericMethodGroupDefinition.methods;

        methods.RemoveWhere(m => !genericMethods.Contains(m.GetGenericSymbol() as MethodDefinition));
        foreach (var m in genericMethods)
        {
            if (m.NumTypeParameters == typeArguments.Length && methods.All(method => method.GetGenericSymbol() != m))
            {
                var constructedMethod = m.ConstructMethod(typeArguments);
                if (constructedMethod != null)
                {
                    methods.Add(constructedMethod);
                }
            }
        }
        return(base.ResolveMethodOverloads(argumentTypes, modifiers, scope, invokedLeaf));
    }
    public override SymbolDefinition ResolveAsExtensionMethod(SyntaxTreeNode_Leaf invokedLeaf, SymbolDefinition invokedSymbol, TypeDefinitionBase memberOf, SyntaxTreeNode_Rule argumentListNode, SymbolReference[] typeArgs, Scope_Base context)
    {
        if (invokedLeaf == null && (invokedSymbol == null || invokedSymbol.kind == SymbolKind.Error))
        {
            return(null);
        }

        var id = invokedSymbol != null && invokedSymbol.kind != SymbolKind.Error ? invokedSymbol.name : invokedLeaf != null?SymbolDefinition.DecodeId(invokedLeaf.token.text) : "";

        int numArguments = 1;

        Modifiers[] modifiers = null;
        List <TypeDefinitionBase> argumentTypes = null;

        MethodDefinition firstAccessibleMethod = null;

        var thisAssembly = GetAssembly();

        var extensionsMethods = new HashSet <MethodDefinition>();

        thisAssembly.CollectExtensionMethods(definition, id, typeArgs, memberOf, extensionsMethods, context);
        if (extensionsMethods.Count > 0)
        {
            firstAccessibleMethod = extensionsMethods.First();

            if (argumentTypes == null)
            {
                numArguments = SD_MethodGroup.ProcessArgumentListNode(argumentListNode, out modifiers, out argumentTypes, memberOf);
            }

            var candidates = new List <MethodDefinition>(extensionsMethods.Count);
            foreach (var method in extensionsMethods)
            {
                if (argumentTypes == null || method.CanCallWith(modifiers, true))
                {
                    candidates.Add(method);
                }
            }

            if (typeArgs == null)
            {
                for (var i = candidates.Count; i-- > 0;)
                {
                    var candidate = candidates[i];
                    if (candidate.NumTypeParameters == 0 || argumentTypes == null)
                    {
                        continue;
                    }

                    candidate = SD_MethodGroup.InferMethodTypeArguments(candidate, argumentTypes, invokedLeaf);
                    if (candidate == null)
                    {
                        candidates.RemoveAt(i);
                    }
                    else
                    {
                        candidates[i] = candidate;
                    }
                }
            }

            var resolved = SD_MethodGroup.ResolveMethodOverloads(numArguments, argumentTypes, modifiers, candidates);
            if (resolved != null && resolved.kind != SymbolKind.Error)
            {
                return(resolved);
            }
        }

        extensionsMethods.Clear();

        var importedNamespaces = declaration.importedNamespaces;

        for (var i = importedNamespaces.Count; i-- > 0;)
        {
            var nsDef = importedNamespaces[i].Definition as SD_NameSpace;
            if (nsDef != null)
            {
                thisAssembly.CollectExtensionMethods(nsDef, id, typeArgs, memberOf, extensionsMethods, context);
            }
        }
        if (extensionsMethods.Count > 0)
        {
            if (firstAccessibleMethod == null)
            {
                firstAccessibleMethod = extensionsMethods.First();
            }

            if (argumentTypes == null)
            {
                numArguments = SD_MethodGroup.ProcessArgumentListNode(argumentListNode, out modifiers, out argumentTypes, memberOf);
            }

            var candidates = new List <MethodDefinition>(extensionsMethods.Count);
            foreach (var method in extensionsMethods)
            {
                if (argumentTypes == null || method.CanCallWith(modifiers, true))
                {
                    candidates.Add(method);
                }
            }

            if (typeArgs == null)
            {
                for (var i = candidates.Count; i-- > 0;)
                {
                    var candidate = candidates[i];
                    if (candidate.NumTypeParameters == 0 || argumentTypes == null)
                    {
                        continue;
                    }

                    candidate = SD_MethodGroup.InferMethodTypeArguments(candidate, argumentTypes, invokedLeaf);
                    if (candidate == null)
                    {
                        candidates.RemoveAt(i);
                    }
                    else
                    {
                        candidates[i] = candidate;
                    }
                }
            }

            var resolved = SD_MethodGroup.ResolveMethodOverloads(numArguments, argumentTypes, modifiers, candidates);
            if (resolved != null && resolved.kind != SymbolKind.Error)
            {
                return(resolved);
            }
        }

        if (parentScope != null)
        {
            var resolved = parentScope.ResolveAsExtensionMethod(invokedLeaf, invokedSymbol, memberOf, argumentListNode, typeArgs, context);
            if (resolved != null)
            {
                return(resolved);
            }
        }

        if (firstAccessibleMethod != null)
        {
            invokedLeaf.ResolvedSymbol   = firstAccessibleMethod;
            invokedLeaf.m_sSemanticError = SD_MethodGroup.unresolvedMethodOverload.name;
        }
        return(null);
    }