public void AddStaticBasedScope(IVariableInstance variable)
 {
     _staticScope.CopyVariable(variable);
     _objectScope.CopyVariable(variable);
     StaticVariables.Add(variable.Provider);
     _parseInfo.TranslateInfo.GetComponent <StaticVariableCollection>().AddVariable(variable);
 }
        public void AddObjectBasedScope(IVariableInstance variable)
        {
            // Add to scope.
            _objectScope.CopyVariable(variable);

            // Make sure the variable is not a macro.
            if (variable.Attributes.StoreType != StoreType.None)
            {
                var variableType = variable.CodeType.GetCodeType(_parseInfo.TranslateInfo);

                // Add to list of variables.
                Variables.Add(variable.Provider);

                // Make the variable unsettable when used locally.
                _contextualVariableModifiers.MakeUnsettable(_parseInfo.TranslateInfo, variable);

                var structCalls = new HashSet <DefinedStructInitializer>();

                // Iterate through each assigning type in the variable's type.
                // An 'assigning type' is a type within a type's tree that may potentially be used to assign a data-type.
                // This is used to ensure that recursive structs do not exist.
                foreach (var descendant in variableType.GetAssigningTypes())
                {
                    // If the variable type contains a struct, add it to the hashset of root variable types.
                    if (descendant is DefinedStructInstance definedStructInstance)
                    {
                        structCalls.Add(definedStructInstance.Provider);
                    }
                    // If the variable type contains an anonymous type, mark that type-arg as an assigner.
                    else if (descendant is AnonymousType anonymousType)
                    {
                        int index = Array.IndexOf(GenericTypes, anonymousType);
                        if (index != -1)
                        {
                            GenericAssigns[index] = true;
                        }
                    }
                }

                _variablesCallTypeAssigners.Add(structCalls);
            }
        }
Пример #3
0
        protected ObjectVariable AddObjectVariable(IIndexReferencer variable)
        {
            // Create an ObjectVariable
            ObjectVariable createdObjectVariable = new ObjectVariable(variable);

            // Add the ObjectVariable to the ObjectVariables list. This will assign the variable a stack when WorkshopInit executes.
            ObjectVariables.Add(createdObjectVariable);
            // Copy the variable to the serve object scope. This allows the variable to be accessed when doing className.variableName.
            serveObjectScope.CopyVariable(variable);
            // Return the created ObjectVariable.
            return(createdObjectVariable);
        }