Exemple #1
0
        /// <summary>
        /// Adds a constant.
        /// </summary>
        /// <returns>The constant.</returns>
        /// <param name="id">Identifier.</param>
        /// <param name="type">Type.</param>
        public static Variable AddConstant(string id, GraphicFooType type)
        {
            if (constants.Contains(id))
            {
                return(constants.ReadVariable(id));
            }
            Variable variable = new Variable(id, type);

            constants.AddVariable(variable);
            return(variable);
        }
Exemple #2
0
        /// <summary>
        /// Finds a variable on a given scope.
        /// </summary>
        /// <returns>The variable.</returns>
        /// <param name="scope">Scope.</param>
        /// <param name="id">Identifier.</param>
        public static Variable FindVariable(Procedure scope, string id)
        {
            Variable variable = null;

            // Variables are only found on a procedure if a scope is given
            if (scope != null)
            {
                variable = scope.ReadVariable(id);
                if (variable != null)
                {
                    return(variable);
                }
            }

            // Continue search on globals
            variable = globalVariables.ReadVariable(id);
            if (variable != null)
            {
                return(variable);
            }

            variable = globalTemporary.ReadVariable(id);
            if (variable != null)
            {
                return(variable);
            }

            variable = constants.ReadVariable(id);
            if (variable != null)
            {
                return(variable);
            }

            Console.WriteLine(
                "Variable {0} not found on scope {1}",
                id,
                (scope == null) ? "global" : scope.name
                );
            return(variable);
        }
Exemple #3
0
        /// <summary>
        /// Reads a variable from the procedure.
        /// </summary>
        /// <returns>The variable.</returns>
        /// <param name="id">Identifier.</param>
        public Variable ReadVariable(string id)
        {
            // Search first in parameters, then in local variables and last in
            // temporary variables
            Variable variable = parameters.ReadVariable(id);

            if (variable == null)
            {
                variable = procedureVariables.ReadVariable(id);
            }
            if (variable == null)
            {
                variable = temporaryVariables.ReadVariable(id);
            }
            return(variable);
        }