Skip to content

Commit 5de6e37

Browse files
[Compiler] Generate error message for recursive preprocessor command
1 parent 04898b0 commit 5de6e37

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/Common/XbasePPCmd.xh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@
2020
#xcommand REQUEST <id1> [,<idn> ] =>
2121
#xcommand ANNOUNCE <id1> [,<idn> ] =>
2222

23-
#xcommand ENDSEQUENCE [<*any*>] => ENDSEQUENCE
23+
#xcommand ENDSEQUENCE [<*any*>] => END SEQUENCE
2424
// Do not map next token to END CLASS
2525
// Otherwise simple classes may be picked up by the normal class rule.
2626
// ENDCLASS is then the only distinguishing factor
2727
#xcommand ENDCLASS <*any*> => ENDCLASS
2828
#xcommand ENDFOR [<*any*>] => ENDFOR
2929

30+
// Map BREAK() function to _Break()
31+
#xtranslate BREAK ([<*any*>] ) => _Break([<any>])
32+
3033
// Override COMMIT for Xbase++ compatibility
3134
#command COMMIT => DbCommitAll()
3235

36+
37+
3338
#endif
3439

3540
// EOF

src/Compiler/src/Compiler/XSharpCodeAnalysis/Preprocessor/XSharpPreprocessor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,6 +2626,8 @@ private bool doProcessTranslates(IList<XSharpToken> line, out IList<XSharpToken>
26262626
{
26272627
// the replacement did not change the tokens, so stop to prevent an endless loop
26282628
result.AddRange(temp);
2629+
var errdata = new ParseErrorData(temp[0], ErrorCode.ERR_PreProcessorError, "Recursive Preprocessor command");
2630+
_parseErrors.Add(errdata);
26292631
temp.Clear();
26302632
break;
26312633
}
@@ -2699,6 +2701,8 @@ private bool doProcessCommands(IList<XSharpToken> line, out IList<XSharpToken> r
26992701
if (isResultUnchanged(prevResult, result))
27002702
{
27012703
// the replacement did not change the tokens, so stop to prevent an endless loop
2704+
var errdata = new ParseErrorData(result[0], ErrorCode.ERR_PreProcessorError, "Recursive Preprocessor command");
2705+
_parseErrors.Add(errdata);
27022706
break;
27032707
}
27042708
if (usedRules.HasRecursion(rule, result))
@@ -2813,6 +2817,8 @@ private List<XSharpToken> doReplace(IList<XSharpToken> line, PPRule rule, PPMatc
28132817

28142818
private static bool isResultUnchanged(IList<XSharpToken> input, IList<XSharpToken> output)
28152819
{
2820+
input = input.Where(t => t.Channel == XSharpLexer.DefaultTokenChannel).ToList();
2821+
output = output.Where(t => t.Channel == XSharpLexer.DefaultTokenChannel).ToList();
28162822
if (input.Count != output.Count)
28172823
return false;
28182824
for (int i = 0; i < input.Count; i++)

0 commit comments

Comments
 (0)