public MacroVar(ParseInfo parseInfo, Scope objectScope, Scope staticScope, DeltinScriptParser.Define_macroContext macroContext, CodeType returnType)
        {
            _context = macroContext;

            Name = macroContext.name.Text;

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

            attributeResult.GetAttributes(parseInfo.Script.Diagnostics);

            ContainingType        = (Static ? staticScope : objectScope).This;
            DefinedAt             = new Location(parseInfo.Script.Uri, DocRange.GetRange(macroContext.name));
            _recursiveCallHandler = new RecursiveCallHandler(this);
            CallInfo           = new CallInfo(_recursiveCallHandler, parseInfo.Script);
            ReturnType         = returnType;
            _expressionToParse = macroContext.expr();
            _scope             = Static ? staticScope : objectScope;
            this._parseInfo    = parseInfo;

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

            DocRange nameRange = DocRange.GetRange(_context.name);

            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
                        );
                }
            }
        }
 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;
     Static       = context.STATIC() != null;
     SetupScope(Static ? staticScope : objectScope);
     AccessLevel       = context.accessor().GetAccessLevel();
     ReturnType        = returnType;
     ExpressionToParse = context.expr();
 }
 public static void GetMacro(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Define_macroContext macroContext, List <IApplyBlock> applyMethods)
 {
     if (macroContext.LEFT_PAREN() != null || macroContext.RIGHT_PAREN() != null)
     {
         var newMacro = new DefinedMacro(parseInfo, scope, macroContext);
         scope.AddMethod(newMacro, parseInfo.Script.Diagnostics, DocRange.GetRange(macroContext.name));
         applyMethods.Add(newMacro);
     }
     else
     {
         var newMacro = new MacroVar(parseInfo, scope, macroContext);
         scope.AddVariable(newMacro, parseInfo.Script.Diagnostics, DocRange.GetRange(macroContext.name));
         applyMethods.Add(newMacro);
     }
 }
Esempio n. 4
0
        public MacroVar(ParseInfo parseInfo, Scope objectScope, Scope staticScope, DeltinScriptParser.Define_macroContext macroContext, CodeType returnType)
        {
            Name        = macroContext.name.Text;
            AccessLevel = macroContext.accessor().GetAccessLevel();
            DefinedAt   = new Location(parseInfo.Script.Uri, DocRange.GetRange(macroContext.name));
            CallInfo    = new CallInfo(this, parseInfo.Script);
            Static      = macroContext.STATIC() != null;

            ReturnType        = returnType;
            ExpressionToParse = macroContext.expr();

            scope          = Static ? staticScope : objectScope;
            this.parseInfo = parseInfo;

            parseInfo.TranslateInfo.AddSymbolLink(this, DefinedAt, true);
            scope.AddVariable(this, parseInfo.Script.Diagnostics, DocRange.GetRange(macroContext.name));
            parseInfo.Script.AddHover(DocRange.GetRange(macroContext.name), GetLabel(true));
        }
        public DefinedMacro(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Define_macroContext context)
            : base(parseInfo, scope, context.name.Text, new LanguageServer.Location(parseInfo.Script.Uri, DocRange.GetRange(context.name)))
        {
            AccessLevel = context.accessor().GetAccessLevel();
            SetupParameters(context.setParameters());

            if (context.TERNARY_ELSE() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected :", DocRange.GetRange(context).end.ToRange());
            }
            else
            {
                ExpressionToParse = context.expr();
                if (ExpressionToParse == null)
                {
                    parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(context.TERNARY_ELSE()));
                }
            }

            parseInfo.Script.AddHover(DocRange.GetRange(context.name), GetLabel(true));
        }
        /// <summary>Creates a macro from a Define_macroContext.</summary>
        /// <param name="objectScope">The scope of the macro if there is no static attribute.</param>
        /// <param name="staticScope">The scope of the macro if there is a static attribute.</param>
        /// <param name="macroContext">The context of the macro.</param>
        /// <returns>A DefinedMacro if the macro has parameters, a MacroVar if there are no parameters.</returns>
        public IScopeable GetMacro(Scope objectScope, Scope staticScope, DeltinScriptParser.Define_macroContext macroContext)
        {
            // If the ; is missing, syntax error.
            if (macroContext.STATEMENT_END() == null)
            {
                Script.Diagnostics.Error("Expected ;", DocRange.GetRange((object)macroContext.TERNARY_ELSE() ?? (object)macroContext.name ?? (object)macroContext).end.ToRange());
            }

            // If the : is missing, syntax error.
            if (macroContext.TERNARY_ELSE() == null)
            {
                Script.Diagnostics.Error("Expected :", DocRange.GetRange(macroContext).end.ToRange());
            }
            else
            {
                // Get the expression that will be parsed.
                if (macroContext.expr() == null)
                {
                    Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(macroContext.TERNARY_ELSE()));
                }
            }

            // Get the return type.
            CodeType returnType = CodeType.GetCodeTypeFromContext(this, macroContext.code_type());

            IScopeable newMacro;

            if (macroContext.LEFT_PAREN() != null || macroContext.RIGHT_PAREN() != null)
            {
                newMacro = new DefinedMacro(this, objectScope, staticScope, macroContext, returnType);
            }
            else
            {
                newMacro = new MacroVar(this, objectScope, staticScope, macroContext, returnType);
            }

            TranslateInfo.ApplyBlock((IApplyBlock)newMacro);
            return(newMacro);
        }
        public MacroVar(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Define_macroContext macroContext)
        {
            Name        = macroContext.name.Text;
            AccessLevel = macroContext.accessor()?.GetAccessLevel() ?? AccessLevel.Private;
            DefinedAt   = new Location(parseInfo.Script.Uri, DocRange.GetRange(macroContext.name));
            CallInfo    = new CallInfo(this, parseInfo.Script);

            if (macroContext.TERNARY_ELSE() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected :", DocRange.GetRange(macroContext).end.ToRange());
            }
            else
            {
                ExpressionToParse = macroContext.expr();
                if (ExpressionToParse == null)
                {
                    parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(macroContext.TERNARY_ELSE()));
                }
            }

            this.scope     = scope;
            this.parseInfo = parseInfo;
        }
Esempio n. 8
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));
            }
        }
 public MacroAttributesGetter(DeltinScriptParser.Define_macroContext context, IFunctionAppendResult result) : base(result)
 {
     Context = context;
 }