コード例 #1
0
        public MacroVar(ParseInfo parseInfo, Scope objectScope, Scope staticScope, MacroVarDeclaration macroContext, CodeType returnType)
        {
            _context = macroContext;

            Name = macroContext.Identifier.Text;

            // Get the attributes.
            FunctionAttributesGetter attributeResult = new MacroAttributesGetter(macroContext, new MacroVarAttribute(this));

            attributeResult.GetAttributes(parseInfo.Script.Diagnostics);

            DocRange nameRange = macroContext.Identifier.Range;

            ContainingType        = (Static ? staticScope : objectScope).This;
            DefinedAt             = new Location(parseInfo.Script.Uri, nameRange);
            _recursiveCallHandler = new RecursiveCallHandler(this);
            CallInfo           = new CallInfo(_recursiveCallHandler, parseInfo.Script);
            CodeType           = returnType;
            _expressionToParse = macroContext.Value;
            _scope             = Static ? staticScope : objectScope;
            this._parseInfo    = parseInfo;

            _scope.AddMacro(this, parseInfo.Script.Diagnostics, nameRange, !Override);
            parseInfo.TranslateInfo.GetComponent <SymbolLinkComponent>().AddSymbolLink(this, DefinedAt, true);
            parseInfo.Script.AddHover(nameRange, GetLabel(true));
            parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, parseInfo, CodeLensSourceType.Variable, DefinedAt.range));

            if (Override)
            {
                MacroVar overriding = (MacroVar)objectScope.GetMacroOverload(Name, DefinedAt);

                if (overriding == this)
                {
                    parseInfo.Script.Diagnostics.Error("Overriding itself!", nameRange);
                }

                // No method with the name and parameters found.
                if (overriding == null)
                {
                    parseInfo.Script.Diagnostics.Error("Could not find a macro to override.", nameRange);
                }
                else if (!overriding.IsOverridable)
                {
                    parseInfo.Script.Diagnostics.Error("The specified macro is not marked as virtual.", nameRange);
                }
                else
                {
                    overriding.Overriders.Add(this);
                }

                if (overriding != null && overriding.DefinedAt != null)
                {
                    // Make the override keyword go to the base method.
                    parseInfo.Script.AddDefinitionLink(
                        attributeResult.ObtainedAttributes.First(at => at.Type == MethodAttributeType.Override).Range,
                        overriding.DefinedAt
                        );
                }
            }
        }
コード例 #2
0
        public DefinedMacro(ParseInfo parseInfo, Scope objectScope, Scope staticScope, DeltinScriptParser.Define_macroContext context, CodeType returnType)
            : base(parseInfo, context.name.Text, new LanguageServer.Location(parseInfo.Script.Uri, DocRange.GetRange(context.name)))
        {
            this.context = context;
            DocRange nameRange = DocRange.GetRange(context.name);

            Attributes.ContainingType = (Static ? staticScope: objectScope).This;

            // Get the attributes.
            MethodAttributeAppender  attributeResult = new MethodAttributeAppender(Attributes);
            FunctionAttributesGetter attributeInfo   = new MacroAttributesGetter(context, attributeResult);

            attributeInfo.GetAttributes(parseInfo.Script.Diagnostics);

            // Copy attribute results
            Static      = attributeResult.Static;
            AccessLevel = attributeResult.AccessLevel;

            SetupScope(Static ? staticScope : objectScope);
            ReturnType        = returnType;
            ExpressionToParse = context.expr();
            DoesReturnValue   = true;

            SetupParameters(context.setParameters(), false);

            if (Attributes.Override)
            {
                IMethod overriding = objectScope.GetMethodOverload(this);

                // No method with the name and parameters found.
                if (overriding == null)
                {
                    parseInfo.Script.Diagnostics.Error("Could not find a macro to override.", nameRange);
                }
                else if (!overriding.Attributes.IsOverrideable)
                {
                    parseInfo.Script.Diagnostics.Error("The specified method is not marked as virtual.", nameRange);
                }
                else
                {
                    overriding.Attributes.AddOverride(this);
                }

                if (overriding != null && overriding.DefinedAt != null)
                {
                    // Make the override keyword go to the base method.
                    parseInfo.Script.AddDefinitionLink(
                        attributeInfo.ObtainedAttributes.First(at => at.Type == MethodAttributeType.Override).Range,
                        overriding.DefinedAt
                        );
                }
            }

            containingScope.AddMethod(this, parseInfo.Script.Diagnostics, DefinedAt.range, !Attributes.Override);

            if (Attributes.IsOverrideable && AccessLevel == AccessLevel.Private)
            {
                parseInfo.Script.Diagnostics.Error("A method marked as virtual or abstract must have the protection level 'public' or 'protected'.", nameRange);
            }

            if (Attributes.IsOverrideable)
            {
                parseInfo.Script.AddCodeLensRange(new ImplementsCodeLensRange(this, parseInfo.Script, CodeLensSourceType.Function, nameRange));
            }
        }