Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CParser: Define __REKO_DECOMPILER__ macro #1323

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Core/Hll/C/CDirectiveLexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public CDirectiveLexer(ParserState state, CLexer lexer)
{
this.parserState = state;
this.lexer = lexer;
this.macros = new();
this.macros = new()
{
{ "__REKO_DECOMPILER__", new () { new CToken(CTokenType.NumericLiteral, 1) } }
};
this.state = State.StartLine;
this.ifdefs = new Stack<(bool, bool)>();
this.expandedTokens = new();
Expand Down
20 changes: 20 additions & 0 deletions src/UnitTests/Core/Hll/C/CDirectiveLexerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,5 +416,25 @@ public void CDirectiveLexer_nested_defines()
Assert.AreEqual(CTokenType.RParen, lexer.Read().Type);
Assert.AreEqual(CTokenType.EOF, lexer.Read().Type);
}

[Test]
public void CDirectiveLexer_reko_macro()
{
Lex(
"#ifdef __REKO_DECOMPILER__\r\n" +
"# define result1 good1\r\n" +
"#else\r\n" +
"# define result1 bad1\r\n" +
"#endif\r\n" +
"#ifndef __REKO_DECOMPILER__\r\n" +
"# define result2 bad2\r\n" +
"#else\r\n" +
"# define result2 good2\r\n" +
"#endif\r\n" +
"result1 result2");
Assert.AreEqual("good1", lexer.Read().Value);
Assert.AreEqual("good2", lexer.Read().Value);
Assert.AreEqual(CTokenType.EOF, lexer.Read().Type);
}
}
}
Loading