示例#1
0
文件: ParsedItem.cs 项目: zhitian/3P
        /// <summary>
        /// This function returns a value of 1 if the argument was a name defined with the & GLOBAL-DEFINE directive;
        /// a value of 2 if the argument was passed as an include file parameter;
        /// and a value of 3 if the argument was a name defined with the & SCOPED-DEFINE directive.
        /// If the argument was not defined and was not an include file parameter, then this function returns a value of 0.
        /// </summary>
        /// <param name="variableName">Can be a position e.g. "1" or a name e.g. "& name"</param>
        /// <returns></returns>
        public int GetScopedPreProcVariableDefinedLevel(string variableName)
        {
            // TODO: this does not work correctly because we can't distinguish between a scope variable on root file and a global variable.
            if (string.IsNullOrEmpty(variableName))
            {
                return(0);
            }
            if (variableName.Equals("0"))
            {
                return(2);
            }
            // &scoped-define variables prevail over preproc parameters passed to the include
            if (DefinedPreProcVariables != null && DefinedPreProcVariables.ContainsKey(variableName))
            {
                return(3);
            }
            if (ParametersPreProcVariables != null && ParametersPreProcVariables.ContainsKey(variableName))
            {
                return(2);
            }
            // search for the value in parent scope
            // the global preproc, available to the whole include stack, are defined in the "root" include (which is the compiled program).
            var parentInclude = Parent;

            while (parentInclude != null)
            {
                if (parentInclude.DefinedPreProcVariables != null && parentInclude.DefinedPreProcVariables.ContainsKey(variableName))
                {
                    return(1);
                }
                parentInclude = parentInclude.Parent;
            }
            return(0);
        }
示例#2
0
文件: ParsedItem.cs 项目: zhitian/3P
        /// <summary>
        /// Returns the value of a given preproc variable.
        /// </summary>
        /// <param name="variableName">Can be a position e.g. "1" or a name e.g. "& name"</param>
        /// <returns></returns>
        public string GetScopedPreProcVariableValue(string variableName)
        {
            if (string.IsNullOrEmpty(variableName))
            {
                return(null);
            }
            if (variableName.Equals("0"))
            {
                return(string.IsNullOrEmpty(IncludeFilePath) ? null : Path.GetFileName(IncludeFilePath));
            }
            // &scoped-define variables prevail over preproc parameters passed to the include
            if (DefinedPreProcVariables != null && DefinedPreProcVariables.ContainsKey(variableName))
            {
                return(DefinedPreProcVariables[variableName]);
            }
            if (ParametersPreProcVariables != null && ParametersPreProcVariables.ContainsKey(variableName))
            {
                return(ParametersPreProcVariables[variableName]);
            }
            // search for the value in parent scope
            // the global preproc, available to the whole include stack, are defined in the "root" include (which is the compiled program).
            var parentInclude = Parent;

            while (parentInclude != null)
            {
                if (parentInclude.DefinedPreProcVariables != null && parentInclude.DefinedPreProcVariables.ContainsKey(variableName))
                {
                    return(parentInclude.DefinedPreProcVariables[variableName]);
                }
                parentInclude = parentInclude.Parent;
            }
            return(null);
        }