/// <summary> /// Creates a new <see cref="PreprocessorCExp"/> with the <paramref name="preCLogicalOrExp"/>, /// <paramref name="column"/>, <paramref name="line"/>, and <paramref name="position"/>. /// </summary> /// <param name="preCLogicalOrExp">The logical or expression that was in parameters that was encountered by the <see cref="PreprocessorCPrimary"/>.</param> /// <param name="column">The column at the current <paramref name="line"/> the /// <see cref="PreprocessorCExp"/> was declared at. </param> /// <param name="line">The line index the <see cref="PreprocessorCExp"/> was declared at.</param> /// <param name="position">The position in the file the <see cref="PreprocessorCExp"/> /// was declared at.</param> public PreprocessorCPrimary(OilexerGrammarTokens.OperatorToken openingParenthesis, IPreprocessorCLogicalOrConditionExp preCLogicalOrExp, int column, int line, long position) : base(column, line, position) { this.rule = 3; this.openingParenthesis = openingParenthesis; this.preCLogicalOrExp = preCLogicalOrExp; }
internal static bool IsDefined(this IPreprocessorCLogicalOrConditionExp expression, IOilexerGrammarProductionRuleEntry currentEntry, IList <IOilexerGrammarTokenEntry> availableStock, ProductionRuleTemplateArgumentSeries argumentLookup, IOilexerGrammarProductionRuleTemplateEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors) { if (expression.Left == null && expression.Right.Left == null && expression.Right.Right.Rule == 3 && expression.Right.Right.PreCPrimary.Rule == 4) { string name = expression.Right.Right.PreCPrimary.Identifier.Name; if (argumentLookup.ContainsParameter(name)) { IProductionRuleTemplatePart iprtp = argumentLookup.GetParameter(name); if (iprtp.SpecialExpectancy == TemplatePartExpectedSpecial.Rule) { IProductionRuleSeries iprs = argumentLookup[name]; if (iprs.Count == 1 && iprs[0].Count == 1) { IProductionRuleItem ipri = iprs[0][0]; if (ipri != null) { if (ipri is IRuleReferenceProductionRuleItem) { name = ((IRuleReferenceProductionRuleItem)(ipri)).Reference.Name; } else if (ipri is ISoftReferenceProductionRuleItem) { //No guarantee that just being a soft-reference guarantees //lack of definition. //Reason: if another template defines this later, //it exists, but hasn't been resolved. -- It will be later in the expansion/resolution phase. name = ((ISoftReferenceProductionRuleItem)(ipri)).PrimaryName; } } } } else { errors.SourceError(OilexerGrammarCore.CompilerErrors.IsDefinedTemplateParameterMustExpectRule, new LineColumnPair(expression.Line, expression.Column), LineColumnPair.Zero, new Uri(entry.FileName, UriKind.RelativeOrAbsolute), name); } } foreach (IOilexerGrammarEntry ientry in file.ToArray()) { if (ientry is IOilexerGrammarProductionRuleEntry && (!(ientry is IOilexerGrammarProductionRuleTemplateEntry))) { if (((IOilexerGrammarProductionRuleEntry)ientry).Name == name) { return(true); } } } return(false); } errors.SourceError(OilexerGrammarCore.CompilerErrors.InvalidDefinedTarget, new LineColumnPair(expression.Line, expression.Column), LineColumnPair.Zero, new Uri(entry.FileName, UriKind.RelativeOrAbsolute), expression.ToString()); return(false); }
internal static bool Evaluate(this IPreprocessorCLogicalOrConditionExp expression, IOilexerGrammarProductionRuleEntry currentEntry, IList <IOilexerGrammarTokenEntry> availableStock, ProductionRuleTemplateArgumentSeries argumentLookup, IOilexerGrammarProductionRuleTemplateEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors) { //rule 2. if (expression.Left == null) { return(expression.Right.Evaluate(currentEntry, availableStock, argumentLookup, entry, file, errors)); } //rule 1. else { return(expression.Left.Evaluate(currentEntry, availableStock, argumentLookup, entry, file, errors) || expression.Right.Evaluate(currentEntry, availableStock, argumentLookup, entry, file, errors)); } }
/// <summary> /// Creates a new <see cref="PreprocessorIfDirective"/> with the <paramref name="condition"/> /// <paramref name="column"/>, <paramref name="line"/>, and <paramref name="position"/>. /// </summary> /// <param name="condition">The condition which determines whether the <see cref="IPreprocessorIfDirective"/> /// is entered.</param> /// <param name="fileName">The file in which the <see cref="PreprocessorIfDirective"/> was declared /// in.</param> /// <param name="column">The column at the current <paramref name="line"/> the /// <see cref="PreprocessorIfDirective"/> was declared at. </param> /// <param name="line">The line index the <see cref="PreprocessorIfDirective"/> was declared at.</param> /// <param name="position">The position in the file the <see cref="PreprocessorIfDirective"/> /// was declared at.</param> public PreprocessorIfDirective(EntryPreprocessorType ppType, IPreprocessorCLogicalOrConditionExp condition, string filename, int column, int line, long position) : base(column, line, position) { this.filename = filename; switch (ppType) { case EntryPreprocessorType.If: case EntryPreprocessorType.IfIn: case EntryPreprocessorType.IfNotDefined: case EntryPreprocessorType.IfDefined: case EntryPreprocessorType.ElseIf: case EntryPreprocessorType.ElseIfIn: case EntryPreprocessorType.ElseIfDefined: case EntryPreprocessorType.Else: break; default: throw new ArgumentException("ppType"); } this.ppType = ppType; this.condition = condition; this.next = null; this.previous = null; }
/// <summary> /// Creates a new <see cref="PreprocessorCLogicalOrConditionExp"/> with the <paramref name="left"/> /// <paramref name="right"/>, <paramref name="column"/>, /// <paramref name="line"/>, and <paramref name="position"/> provided. /// </summary> /// <param name="left">The previous <see cref="IPreprocessorCLogicalOrConditionExp"/>.</param> /// <param name="right">The <see cref="IPreprocessorCLogicalAndConditionExp"/> /// that is next.</param> /// <remarks>Rule 1</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 PreprocessorCLogicalOrConditionExp(IPreprocessorCLogicalOrConditionExp left, IPreprocessorCLogicalAndConditionExp right, int column, int line, long position) : base(column, line, position) { this.left = left; this.right = right; }