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 MacroVar GetMacro(Scope objectScope, Scope staticScope, MacroVarDeclaration macroContext)
        {
            // Get the return type.
            CodeType returnType = CodeType.GetCodeTypeFromContext(this, macroContext.Type);

            MacroVar newMacro = new MacroVar(this, objectScope, staticScope, macroContext, returnType);

            TranslateInfo.ApplyBlock((IApplyBlock)newMacro);
            return(newMacro);
        }