Exemple #1
0
        public static IndexedVar AssignVar(VarCollection collection, ScopeGroup scope, string name, bool isGlobal, WorkshopVariable variable, Node node)
        {
            string workshopName = variable.Name;

            if (workshopName == null)
            {
                workshopName = collection.WorkshopNameFromCodeName(isGlobal, name);
            }

            int id = variable.ID;

            if (id == -1)
            {
                id = collection.NextFree(isGlobal);
            }
            else
            {
                WorkshopVariable assigned = collection.FromID(isGlobal, variable.ID);
                if (assigned != null)
                {
                    throw new SyntaxErrorException("Variable ID '" + variable.ID + "' has already been assigned by '" + assigned.Name + "'.", node.Location);
                }
            }

            WorkshopVariable use = new WorkshopVariable(isGlobal, id, workshopName);

            IndexedVar var = CreateVar(
                collection.WorkshopArrayBuilder,
                scope,
                name,
                isGlobal,
                use,
                null,
                node
                );

            collection.AllVars.Add(var);
            collection.UseCollection(isGlobal)[id] = use;
            return(var);
        }