Exemple #1
0
 /// <summary>
 /// Creates a new <see cref="PreprocessorCEqualityExp"/> with the <paramref name="preCEqualityExp"/>,
 /// <paramref name="preCPrimary"/>, <paramref name="termIsEq"/>, <paramref name="column"/>,
 /// <paramref name="line"/>, and <paramref name="position"/> provided.
 /// </summary>
 /// <param name="termIsEq">Whether the term encountered is '==' (true) or '!=' (false).</param>
 /// <param name="preCEqualityExp">The previous <see cref="IPreprocessorCEqualityExp"/>.</param>
 /// <param name="preCPrimary">The <see cref="IPreprocessorCPrimary"/>
 /// that is next.</param>
 /// <remarks>Rule 1 or 2</remarks>
 /// <param name="column">The column at the current <paramref name="line"/> the
 /// <see cref="PreprocessorCEqualityExp"/> was declared at. </param>
 /// <param name="line">The line index the <see cref="PreprocessorCEqualityExp"/> was declared at.</param>
 /// <param name="position">The position in the file the <see cref="PreprocessorCEqualityExp"/>
 /// was declared at.</param>
 public PreprocessorCEqualityExp(IPreprocessorCEqualityExp preCEqualityExp, bool termIsEq, IPreprocessorCPrimary preCPrimary, int column, int line, long position)
     : base(column, line, position)
 {
     rule                 = (termIsEq ? 1 : 2);
     this.preCPrimary     = preCPrimary;
     this.preCEqualityExp = preCEqualityExp;
 }
Exemple #2
0
 /// <summary>
 /// Creates a new <see cref="PreprocessorCLogicalAndConditionExp"/> with the <paramref name="right"/>,
 /// <paramref name="column"/>, <paramref name="line"/>, and <paramref name="position"/>
 /// provided.
 /// </summary>
 /// <param name="right">The <see cref="IPreprocessorCEqualityExp"/> the
 /// <see cref="PreprocessorCLogicalAndConditionExp"/> links to.</param>
 /// <remarks>Rule 2</remarks>
 /// <param name="column">The column at the current <paramref name="line"/> the
 /// <see cref="PreprocessorCLogicalOrConditionExp"/> was declared at. </param>
 /// <param name="line">The line index the <see cref="PreprocessorCLogicalOrConditionExp"/> was declared at.</param>
 /// <param name="position">The position in the file the <see cref="PreprocessorCLogicalOrConditionExp"/>
 /// was declared at.</param>
 public PreprocessorCLogicalAndConditionExp(IPreprocessorCEqualityExp right, int column, int line, long position)
     : base(column, line, position)
 {
     this.right = right;
 }
Exemple #3
0
        internal static object Evaluate(this IPreprocessorCEqualityExp expression, IOilexerGrammarProductionRuleEntry currentEntry, IList <IOilexerGrammarTokenEntry> availableStock, ProductionRuleTemplateArgumentSeries argumentLookup, IOilexerGrammarProductionRuleTemplateEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors)
        {
            IOilexerGrammarTokenEntry lookup;
            ILiteralTokenItem         reference = null;

            //Hack #1.
            if (expression.Rule == 1 || expression.Rule == 2)
            {
                string name = null;
                //If the left side is a parameter reference and the right side
                //is an identifier...
                if (expression.PreCEqualityExp.Rule == 3 && expression.PreCPrimary.Rule == 4 && expression.PreCEqualityExp.PreCPrimary.Rule == 4 &&
                    argumentLookup.ContainsParameter(name = expression.PreCEqualityExp.PreCPrimary.Identifier.Name))
                {
                    //Obtain the parameter
                    IProductionRuleTemplatePart part = argumentLookup.GetParameter(name);
                    if (part.SpecialExpectancy == TemplatePartExpectedSpecial.None && part.ExpectedSpecific != null)
                    {
                        //If the specific expectency is a production rule reference...
                        if (part.ExpectedSpecific is ITokenReferenceProductionRuleItem)
                        {
                            //Lookup the expectency.
                            ILiteralTokenItem secondHalf = null;
                            lookup = ((ITokenReferenceProductionRuleItem)(part.ExpectedSpecific)).Reference;
                            //Lookup the right-hand requirement for the condition.
                            ITokenItem sRef = lookup.FindTokenItem(expression.PreCPrimary.Identifier.Name);
                            if (sRef is ILiteralTokenItem)
                            {
                                reference = ((ILiteralTokenItem)(sRef));
                            }
                            else
                            {
                                goto notValidReference;
                            }
                            //Obtain the expression series for the left-hand side.
                            IProductionRuleSeries series = argumentLookup[part];
                            //If it's a single unit.
                            if (series.Count == 1 && series[0].Count == 1)
                            {
                                //If it's a soft-reference item...
                                IProductionRuleItem e = series[0][0];
                                if (e is ISoftReferenceProductionRuleItem)
                                {
                                    ISoftReferenceProductionRuleItem sre = ((ISoftReferenceProductionRuleItem)e);
                                    if (((sre.SecondaryName == null || sre.SecondaryName == string.Empty)) && sre.PrimaryName != null)
                                    {
                                        secondHalf = (ILiteralTokenItem)lookup.FindTokenItemByValue(sre.PrimaryName, file, true);
                                    }
                                }
                                //If they used the fully qualified name...
                                else if (e is ILiteralReferenceProductionRuleItem)
                                {
                                    ILiteralReferenceProductionRuleItem lr = ((ILiteralReferenceProductionRuleItem)e);
                                    //So much easier...
                                    secondHalf = lr.Literal;
                                }
                                if (expression.Rule == 1)
                                {
                                    return(secondHalf == reference);
                                }
                                else if (expression.Rule == 2)
                                {
                                    return(secondHalf != reference);
                                }
                            }
                        }
                    }
                }
                else if (expression.PreCEqualityExp.Rule == 3 && expression.PreCPrimary.Rule == 5 && expression.PreCEqualityExp.PreCPrimary.Rule == 4 &&
                         expression.PreCEqualityExp.PreCPrimary.Identifier.Name.ToLower() == "index")
                {
                    if (expression.Rule == 1)
                    {
                        return(expression.PreCPrimary.Number.GetCleanValue() == argumentLookup.Index);
                    }
                    else if (expression.Rule == 2)
                    {
                        return(expression.PreCPrimary.Number.GetCleanValue() != argumentLookup.Index);
                    }
                }
            }
notValidReference:
            switch (expression.Rule)
            {
            case 1:     //PreprocessorCEqualityExp "==" PreprocessorCPrimary
                return(expression.PreCEqualityExp.Evaluate(currentEntry, availableStock, argumentLookup, entry, file, errors) == expression.PreCPrimary.Evaluate(currentEntry, availableStock, argumentLookup, entry, file, errors));

            case 2:     //PreprocessorCEqualityExp "!=" PreprocessorCPrimary
                return(expression.PreCEqualityExp.Evaluate(currentEntry, availableStock, argumentLookup, entry, file, errors) != expression.PreCPrimary.Evaluate(currentEntry, availableStock, argumentLookup, entry, file, errors));

            case 3:     //PreprocessorCPrimary
                return(expression.PreCPrimary.Evaluate(currentEntry, availableStock, argumentLookup, entry, file, errors));
            }
            return(false);
        }