internal static IProductionRuleItem Expand(this IPreprocessorIfDirective directive, IOilexerGrammarProductionRuleEntry currentEntry, IList <IOilexerGrammarTokenEntry> availableStock, ProductionRuleTemplateArgumentSeries argumentLookup, IOilexerGrammarProductionRuleTemplateEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors) { bool process = true; if (directive.Type != EntryPreprocessorType.Else) { switch (directive.Type) { case EntryPreprocessorType.If: case EntryPreprocessorType.ElseIf: process = directive.Condition.Evaluate(currentEntry, availableStock, argumentLookup, entry, file, errors); break; case EntryPreprocessorType.IfNotDefined: process = !directive.Condition.IsDefined(currentEntry, availableStock, argumentLookup, entry, file, errors); break; case EntryPreprocessorType.ElseIfDefined: case EntryPreprocessorType.IfDefined: process = directive.Condition.IsDefined(currentEntry, availableStock, argumentLookup, entry, file, errors); break; default: break; } } if (process) { List <IProductionRuleItem> result = new List <IProductionRuleItem>(); foreach (IPreprocessorDirective ipd in directive.Body) { IProductionRuleItem ipri = ipd.Expand(currentEntry, availableStock, argumentLookup, entry, file, errors); if (ipri != null) { result.Add(ipri); } } if (result.Count > 1) { return(new ProductionRuleGroupItem(new IProductionRule[] { new ProductionRule(result, entry.FileName, entry.Column, entry.Line, entry.Position) }, directive.Column, directive.Line, directive.Position)); } else if (result.Count > 0) { return(result[0]); } else { return(null); } } else if (directive.Next != null) { return(directive.Next.Expand(currentEntry, availableStock, argumentLookup, entry, file, errors)); } return(null); }
public static IPreprocessorDirective ResolveProductionRuleItem<T>(this IPreprocessorDirective item, T entry, OilexerGrammarFile file, ICompilerErrorCollection errors) where T : IOilexerGrammarProductionRuleEntry { switch (item.Type) { case EntryPreprocessorType.If: case EntryPreprocessorType.IfNotDefined: case EntryPreprocessorType.IfDefined: case EntryPreprocessorType.ElseIf: case EntryPreprocessorType.ElseIfDefined: case EntryPreprocessorType.Else: IPreprocessorIfDirective ipid = ((IPreprocessorIfDirective)(item)); PreprocessorIfDirective pid = new PreprocessorIfDirective(item.Type, ((IPreprocessorIfDirective)item).Condition, entry.FileName, item.Column, item.Line, item.Position); foreach (IPreprocessorDirective ipd in ipid.Body) ((PreprocessorIfDirective.DirectiveBody)(pid.Body)).Add(ipd.ResolveProductionRuleItem(entry, file, errors)); if (ipid.Next != null) pid.Next = (IPreprocessorIfDirective)ipid.Next.ResolveProductionRuleItem(entry, file, errors); return pid; case EntryPreprocessorType.DefineRule: IPreprocessorDefineRuleDirective ipdd = ((IPreprocessorDefineRuleDirective)(item)); IProductionRule[] dr = new IProductionRule[ipdd.DefinedRules.Length]; for (int i = 0; i < ipdd.DefinedRules.Length; i++) { dr[i] = ipdd.DefinedRules[i].Clone(); dr[i].ResolveProductionRule(entry, file, errors); } return new PreprocessorDefineRuleDirective(ipdd.DeclareTarget, dr, ipdd.Column, ipdd.Line, ipdd.Position); case EntryPreprocessorType.AddRule: IPreprocessorAddRuleDirective ipard = ((IPreprocessorAddRuleDirective)(item)); IProductionRule[] ar = new IProductionRule[ipard.Rules.Length]; for (int i = 0; i < ipard.Rules.Length; i++) { ar[i] = ipard.Rules[i].Clone(); ar[i].ResolveProductionRule(entry, file, errors); } return new PreprocessorAddRuleDirective(ipard.InsertTarget, ar, ipard.Column, ipard.Line, ipard.Position); case EntryPreprocessorType.Throw: return item; case EntryPreprocessorType.Return: IPreprocessorConditionalReturnDirective ipcrd = ((IPreprocessorConditionalReturnDirective)(item)); IProductionRule[] crd = new IProductionRule[ipcrd.Result.Length]; for (int i = 0; i < ipcrd.Result.Length; i++) { crd[i] = ipcrd.Result[i].Clone(); crd[i].ResolveProductionRule(entry, file, errors); } return new PreprocessorConditionalReturnDirective(crd, ipcrd.Column, ipcrd.Line, ipcrd.Position); } return item; }
/// <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; }
public OilexerGrammarPreprocessorIfDirectiveRegion(IPreprocessorIfDirective directive, long bodyStart, long bodyEnd) { this.directive = directive; this.Start = (int)bodyStart; this.End = (int)bodyEnd; }
internal void AddIfRegion(IPreprocessorIfDirective directive, long bodyStart, long bodyEnd) { this.myRegions.Add(new OilexerGrammarPreprocessorIfDirectiveRegion(directive, bodyStart, bodyEnd)); }