public TernaryExpression(IParseExpression condition, IParseExpression consequent, IParseExpression alternative)
 {
     Condition   = condition;
     Consequent  = consequent;
     Alternative = alternative;
     Range       = condition.Range.Start + alternative.Range.End;
 }
        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
                        );
                }
            }
        }
        public Var(VarInfo varInfo)
        {
            Name                 = varInfo.Name;
            DefinedAt            = varInfo.DefinedAt;
            _parseInfo           = varInfo.ParseInfo;
            AccessLevel          = varInfo.AccessLevel;
            WholeContext         = varInfo.WholeContext;
            CodeType             = varInfo.Type;
            InExtendedCollection = varInfo.InExtendedCollection;
            Ref                    = varInfo.Ref;
            ID                     = varInfo.ID;
            Static                 = varInfo.Static;
            Recursive              = varInfo.Recursive;
            BridgeInvocable        = varInfo.BridgeInvocable;
            RequiresCapture        = varInfo.RequiresCapture;
            IsMacro                = varInfo.IsMacro;
            Virtual                = varInfo.Virtual;
            Override               = varInfo.Override;
            _tokenType             = varInfo.TokenType;
            _tokenModifiers        = varInfo.TokenModifiers.ToArray();
            _handleRestrictedCalls = varInfo.HandleRestrictedCalls;
            _inferType             = varInfo.InferType;
            _initialValueContext   = varInfo.InitialValueContext;
            _initialValueResolve   = varInfo.InitialValueResolve;
            _operationalScope      = varInfo.Scope;

            _variableTypeHandler = varInfo.VariableTypeHandler;
            if (!_inferType)
            {
                AddScriptData();
            }

            if (ID != -1)
            {
                if (VariableType == VariableType.Global)
                {
                    _parseInfo.TranslateInfo.VarCollection.Reserve(ID, true, _parseInfo.Script.Diagnostics, DefinedAt.range);
                }
                else if (VariableType == VariableType.Player)
                {
                    _parseInfo.TranslateInfo.VarCollection.Reserve(ID, false, _parseInfo.Script.Diagnostics, DefinedAt.range);
                }
            }

            // Get the initial value.
            if (_initialValueResolve == InitialValueResolve.Instant)
            {
                GetInitialValue();
            }
            else
            {
                _parseInfo.TranslateInfo.StagedInitiation.On(InitiationStage.Content, GetInitialValue);
            }

            if (DefinedAt != null)
            {
                _parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, _parseInfo, varInfo.CodeLensType, DefinedAt.range));
                _parseInfo.Script.Elements.AddDeclarationCall(this, new DeclarationCall(DefinedAt.range, true));
            }
        }
예제 #4
0
 public Foreach(IParseType type, Token identifier, IParseExpression expression, IParseStatement statement)
 {
     Type       = type;
     Identifier = identifier;
     Expression = expression;
     Statement  = statement;
 }
예제 #5
0
 public Assignment(IParseExpression variableExpression, Token assignmentToken, IParseExpression value, Token actionComment)
 {
     VariableExpression = variableExpression;
     AssignmentToken    = assignmentToken;
     Value         = value;
     ActionComment = actionComment;
 }
예제 #6
0
 public MacroVarDeclaration(AttributeTokens attributes, IParseType type, Token identifier, IParseExpression value)
 {
     Attributes = attributes;
     Type       = type;
     Identifier = identifier;
     Value      = value;
 }
예제 #7
0
 public If(IParseExpression expression, IParseStatement statement, List <ElseIf> elseIfs, Else els)
 {
     Expression = expression;
     Statement  = statement;
     ElseIfs    = elseIfs;
     Else       = els;
 }
 public BinaryOperatorExpression(IParseExpression left, IParseExpression right, OperatorInfo op)
 {
     Left     = left;
     Right    = right;
     Operator = op;
     Range    = left.Range.Start + right.Range.End;
 }
예제 #9
0
        /// <summary>Gets an IExpression from an ExprContext.</summary>
        /// <param name="scope">The scope the expression was called in.</param>
        /// <param name="exprContext">The context of the expression/</param>
        /// <param name="selfContained">Determines if the expression is not an expression tree.</param>
        /// <param name="usedAsValue">Determines if the expression is being used as a value.</param>
        /// <param name="getter">The getter scope. Used for preserving scope through parameters.</param>
        /// <returns>An IExpression created from the ExprContext.</returns>
        public IExpression GetExpression(Scope scope, IParseExpression exprContext, bool selfContained = true, bool usedAsValue = true, Scope getter = null)
        {
            if (getter == null)
            {
                getter = scope;
            }

            switch (exprContext)
            {
            case NumberExpression number: return(new NumberAction(Script, number));

            case BooleanExpression boolean: return(new BoolAction(Script, boolean.Value));

            case NullExpression @null: return(new NullAction());

            case StringExpression @string: return(new StringAction(this, scope, @string));

            case Identifier identifier: return(GetVariable(scope, getter, identifier, selfContained));

            case FunctionExpression method: return(new CallMethodAction(this, scope, method, usedAsValue, getter));

            case NewExpression newObject: return(new CreateObjectAction(this, scope, newObject));

            case BinaryOperatorExpression op:
                if (op.IsDotExpression())
                {
                    return(new ExpressionTree(this, scope, op, usedAsValue));
                }
                else
                {
                    return(new OperatorAction(this, scope, op));
                }

            case UnaryOperatorExpression op: return(new UnaryOperatorAction(this, scope, op));

            case TernaryExpression op: return(new TernaryConditionalAction(this, scope, op));

            case ValueInArray arrayIndex: return(new ValueInArrayAction(this, scope, arrayIndex));

            case CreateArray createArray: return(new CreateArrayAction(this, scope, createArray));

            case ExpressionGroup group: return(GetExpression(scope, group.Expression));

            case TypeCast typeCast: return(new TypeConvertAction(this, scope, typeCast));

            case ThisExpression @this: return(new ThisAction(this, scope, @this));

            case RootExpression root: return(new RootAction(this.TranslateInfo));

            case LambdaExpression lambda: return(new Lambda.LambdaAction(this, scope, lambda));

            case AsyncContext asyncContext: return(AsyncInfo.ParseAsync(this, scope, asyncContext, usedAsValue));

            // Missing
            case MissingElement missing: return(MissingElementAction.MissingElement);

            default: throw new Exception($"Could not determine the expression type '{exprContext.GetType().Name}'.");
            }
        }
예제 #10
0
 public MacroFunctionContext(AttributeTokens attributes, IParseType type, Token identifier, List <VariableDeclaration> parameters, IParseExpression expression)
 {
     Attributes = attributes;
     Type       = type;
     Identifier = identifier;
     Parameters = parameters;
     Expression = expression;
 }
예제 #11
0
 public For(IParseStatement initializer, IParseExpression condition, IParseStatement iterator, IParseStatement block, Token initializerSemicolon)
 {
     Initializer          = initializer;
     Condition            = condition;
     Iterator             = iterator;
     Block                = block;
     InitializerSemicolon = initializerSemicolon;
 }
예제 #12
0
 public VariableDeclaration(AttributeTokens attributes, IParseType type, Token identifier, IParseExpression initialValue, Token ext, Token id)
 {
     Attributes   = attributes;
     Type         = type;
     Identifier   = identifier;
     InitialValue = initialValue;
     Extended     = ext;
     ID           = id;
 }
        public Var(VarInfo varInfo)
        {
            Name                 = varInfo.Name;
            DefinedAt            = varInfo.DefinedAt;
            parseInfo            = varInfo.ParseInfo;
            AccessLevel          = varInfo.AccessLevel;
            DefinedAt            = varInfo.DefinedAt;
            WholeContext         = varInfo.WholeContext;
            CodeType             = varInfo.Type;
            VariableType         = varInfo.VariableType;
            StoreType            = varInfo.StoreType;
            InExtendedCollection = varInfo.InExtendedCollection;
            ID                     = varInfo.ID;
            Static                 = varInfo.Static;
            Recursive              = varInfo.Recursive;
            BridgeInvocable        = varInfo.BridgeInvocable;
            RequiresCapture        = varInfo.RequiresCapture;
            _tokenType             = varInfo.TokenType;
            _tokenModifiers        = varInfo.TokenModifiers.ToArray();
            _handleRestrictedCalls = varInfo.HandleRestrictedCalls;
            _initalValueContext    = varInfo.InitialValueContext;
            _initialValueResolve   = varInfo.InitialValueResolve;
            _operationalScope      = varInfo.OperationalScope;

            if (ID != -1)
            {
                if (VariableType == VariableType.Global)
                {
                    parseInfo.TranslateInfo.VarCollection.Reserve(ID, true, parseInfo.Script.Diagnostics, DefinedAt.range);
                }
                else if (VariableType == VariableType.Player)
                {
                    parseInfo.TranslateInfo.VarCollection.Reserve(ID, false, parseInfo.Script.Diagnostics, DefinedAt.range);
                }
            }

            if (DefinedAt.range != null)
            {
                parseInfo.Script.AddToken(DefinedAt.range, _tokenType, _tokenModifiers);
                parseInfo.Script.AddHover(DefinedAt.range, GetLabel(true));
                parseInfo.TranslateInfo.GetComponent <SymbolLinkComponent>().AddSymbolLink(this, DefinedAt, true);
            }

            if (_initialValueResolve == InitialValueResolve.Instant)
            {
                GetInitialValue();
            }
            else
            {
                parseInfo.TranslateInfo.ApplyBlock(this);
            }

            parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, parseInfo, varInfo.CodeLensType, DefinedAt.range));
        }
예제 #14
0
 public SwitchCase(Token caseToken, IParseExpression value)
 {
     Token     = caseToken;
     Value     = value;
     IsDefault = false;
 }
예제 #15
0
 public Switch(IParseExpression expression, List <IParseStatement> statements)
 {
     Expression = expression;
     Statements = statements;
 }
예제 #16
0
 public ElseIf(IParseExpression expression, IParseStatement statement)
 {
     Expression = expression;
     Statement  = statement;
 }
예제 #17
0
 public Return(Token token, IParseExpression expression)
 {
     Token      = token;
     Expression = expression;
 }
예제 #18
0
 public Increment(IParseExpression variableExpression, bool decrement)
 {
     VariableExpression = variableExpression;
     Decrement          = decrement;
 }
예제 #19
0
 public FunctionExpression(IParseExpression target, List <ParameterValue> parameters)
 {
     Target     = target;
     Parameters = parameters;
 }
예제 #20
0
 public AsyncContext(Token asyncToken, Token ignoreIfRunning, IParseExpression expression)
 {
     AsyncToken      = asyncToken;
     IgnoreIfRunning = ignoreIfRunning;
     Expression      = expression;
 }
예제 #21
0
 public TypeCast(IParseType type, IParseExpression expression)
 {
     Type       = type;
     Expression = expression;
 }
예제 #22
0
 public ExpressionGroup(IParseExpression expression, Token left, Token right)
 {
     Expression = expression;
     Left       = left;
     Right      = right;
 }
예제 #23
0
 public Delete(IParseExpression deleting)
 {
     Deleting = deleting;
 }
예제 #24
0
 public EnumValue(Token identifier, IParseExpression value)
 {
     Identifier = identifier;
     Value      = value;
 }
예제 #25
0
 public ParameterValue(Token pickyParameter, IParseExpression value)
 {
     PickyParameter = pickyParameter;
     Expression     = value;
 }
예제 #26
0
 public ExpressionStatement(IParseExpression expression, Token actionComment)
 {
     Expression    = expression;
     ActionComment = actionComment;
     Range         = expression.Range;
 }
예제 #27
0
 public ArrayIndex(IParseExpression expression, Token leftBracket, Token rightBracket)
 {
     Expression   = expression;
     LeftBracket  = leftBracket;
     RightBracket = rightBracket;
 }
예제 #28
0
 public Hook(IParseExpression variable, IParseExpression value)
 {
     Variable = variable;
     Value    = value;
 }
예제 #29
0
 public InitialValueAttribute(IParseExpression exprContext) : base(AttributeType.Initial, exprContext.Range)
 {
     ExprContext = exprContext;
 }
예제 #30
0
 public ValueInArray(IParseExpression array, IParseExpression index, Token closingToken)
 {
     Array = array;
     Index = index;
     Range = new DocRange(Array.Range.Start, closingToken.Range.End);
 }