コード例 #1
0
        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));
            }
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        public Var GetVar()
        {
            _parseInfo   = _contextHandler.ParseInfo;
            _diagnostics = _parseInfo.Script.Diagnostics;
            _nameRange   = _contextHandler.GetNameRange();
            _name        = _contextHandler.GetName() ?? "?";

            // Get then check components.
            ComponentCollection = new VariableComponentCollection(_diagnostics);
            _contextHandler.GetComponents(ComponentCollection);
            CheckComponents();
            ComponentCollection.FinishedObtainingComponents();

            _scope = _scopeHandler.GetScope(ComponentCollection.IsAttribute(AttributeType.Static));

            // Create the varinfo.
            _varInfo       = new VarInfo(_name, _contextHandler.GetDefineLocation(), _parseInfo);
            _varInfo.Scope = _scope;

            // Get the variable type.
            _typeRange = _contextHandler.GetTypeRange();
            GetCodeType();

            // Get the variable being overriden.
            GetOverridenVariable();

            // If the type of the variable is PortableLambdaType, set the TokenType to Function
            if (_varInfo.Type is Lambda.PortableLambdaType)
            {
                _varInfo.TokenType = SemanticTokenType.Function;
            }

            // Apply attributes.
            ComponentCollection.Apply(_varInfo);

            Apply();
            TypeCheck();
            _varInfo.Recursive = IsRecursive();

            // Get the resulting variable.
            var result = new Var(_varInfo);

            // Add the variable to the operational scope.
            if (_nameRange != null)
            {
                _scopeHandler.CheckConflict(_parseInfo, new(_name), _nameRange);
            }
            _scopeHandler.Add(result.GetDefaultInstance(_scopeHandler.DefinedIn()), ComponentCollection.IsAttribute(AttributeType.Static));

            // Done
            return(result);
        }
コード例 #4
0
        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;
            _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);
                }
            }

            // Add the variable to the scope.
            _operationalScope.AddVariable(this, parseInfo.Script.Diagnostics, DefinedAt.range);
            _finalized = true;

            parseInfo.Script.AddHover(DefinedAt.range, GetLabel(true));
            parseInfo.TranslateInfo.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));
        }
コード例 #5
0
        public virtual void Apply(VarInfo varInfo)
        {
            switch (Type)
            {
            // Extended collection attribute.
            case AttributeType.Ext:
                varInfo.InExtendedCollection = true;
                break;

            // Access levels
            case AttributeType.Public: varInfo.AccessLevel = AccessLevel.Public; break;

            case AttributeType.Protected: varInfo.AccessLevel = AccessLevel.Protected; break;

            case AttributeType.Private: varInfo.AccessLevel = AccessLevel.Private; break;

            // globalvar
            case AttributeType.Globalvar:
                varInfo.VariableType = VariableType.Global;
                break;

            // playervar
            case AttributeType.Playervar:
                varInfo.VariableType = VariableType.Player;
                break;

            // ref
            case AttributeType.Ref:
                varInfo.IsWorkshopReference = true;
                break;

            // Static
            case AttributeType.Static:
                varInfo.Static = true;
                break;

            // Should be handled by overrides.
            case AttributeType.ID:
            case AttributeType.Initial:
            // Missing attribute function
            default:
                throw new NotImplementedException();
            }
        }
コード例 #6
0
 public override void Apply(VarInfo varInfo)
 {
     varInfo.InitialValueContext = ExprContext;
 }
コード例 #7
0
 public override void Apply(VarInfo varInfo)
 {
     varInfo.ID = ID;
 }
コード例 #8
0
        public Var GetVar()
        {
            _parseInfo   = _contextHandler.ParseInfo;
            _diagnostics = _parseInfo.Script.Diagnostics;
            _nameRange   = _contextHandler.GetNameRange();

            // Get the attributes.
            _attributes = _contextHandler.GetAttributes();

            // Stores all values in the enum AttributeType as a list.
            List <AttributeType> missingTypes = Enum.GetValues(typeof(AttributeType)).Cast <AttributeType>().ToList();

            // Filter missing attributes.
            foreach (VarBuilderAttribute attribute in _attributes)
            {
                missingTypes.Remove(attribute.Type);
            }

            // Check missing attributes.
            MissingAttribute(missingTypes.ToArray());

            // Check existing attributes.
            CheckAttributes();

            // Create the varinfo.
            _varInfo = new VarInfo(_contextHandler.GetName(), _contextHandler.GetDefineLocation(), _parseInfo);

            // Get the variable type.
            _typeRange = _contextHandler.GetTypeRange();
            GetCodeType();

            if (_varInfo.Type is Lambda.PortableLambdaType)
            {
                _varInfo.TokenType = TokenType.Function;
            }

            // Apply attributes.
            foreach (VarBuilderAttribute attribute in _attributes)
            {
                attribute.Apply(_varInfo);
            }

            Apply();

            // Set the variable and store types.
            if (_varInfo.IsWorkshopReference)
            {
                // If the variable is a workshop reference, set the variable type to ElementReference.
                _varInfo.VariableType = VariableType.ElementReference;
                _varInfo.StoreType    = StoreType.None;
            }
            // In extended collection.
            else if (_varInfo.InExtendedCollection)
            {
                _varInfo.StoreType = StoreType.Indexed;
            }
            // Full workshop variable.
            else
            {
                _varInfo.StoreType = StoreType.FullVariable;
            }

            TypeCheck();
            _varInfo.Recursive = IsRecursive();

            // Set the scope.
            var scope = OperationalScope();

            _varInfo.OperationalScope = scope;

            // Get the resulting variable.
            var result = new Var(_varInfo);

            // Add the variable to the operational scope.
            if (_contextHandler.CheckName())
            {
                scope.AddVariable(result, _diagnostics, _nameRange);
            }
            else
            {
                scope.CopyVariable(result);
            }

            return(result);
        }
コード例 #9
0
        public Var GetVar()
        {
            _parseInfo   = _contextHandler.ParseInfo;
            _diagnostics = _parseInfo.Script.Diagnostics;
            _nameRange   = _contextHandler.GetNameRange();

            // Get the attributes.
            _attributes = _contextHandler.GetAttributes();

            // Stores all values in the enum AttributeType as a list.
            List <AttributeType> missingTypes = Enum.GetValues(typeof(AttributeType)).Cast <AttributeType>().ToList();

            // Filter missing attributes.
            foreach (VarBuilderAttribute attribute in _attributes)
            {
                missingTypes.Remove(attribute.Type);
            }

            // Check missing attributes.
            MissingAttribute(missingTypes.ToArray());

            // Check existing attributes.
            CheckAttributes();

            // Create the varinfo.
            _varInfo = new VarInfo(_contextHandler.GetName(), _contextHandler.GetDefineLocation(), _parseInfo);

            // Get the variable type.
            _typeRange = _contextHandler.GetTypeRange();
            GetCodeType();

            // Apply attributes.
            foreach (VarBuilderAttribute attribute in _attributes)
            {
                attribute.Apply(_varInfo);
            }

            Apply();

            // Set the variable and store types.
            if (_varInfo.IsWorkshopReference)
            {
                // If the variable is a workshop reference, set the variable type to ElementReference.
                _varInfo.VariableType = VariableType.ElementReference;
                _varInfo.StoreType    = StoreType.None;
            }
            // In extended collection.
            else if (_varInfo.InExtendedCollection)
            {
                _varInfo.StoreType = StoreType.Indexed;
            }
            // Full workshop variable.
            else
            {
                _varInfo.StoreType = StoreType.FullVariable;
            }

            TypeCheck();

            return(new Var(_varInfo));
        }