Пример #1
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);
        }
Пример #2
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));
        }