Repository navigation
[Compiler] Preprocessor modes for the IDE and a lexer hook in the preprocessor - #2209
Open
hpetriffer wants to merge 2 commits into
Open
hpetriffer wants to merge 2 commits into
hpetriffer wants to merge 2 commits into
Conversation
…processor - IPPLexerServices: what the preprocessor takes from its lexer (HasPPIfdefs, ReclassifyTokens, lexing an include file). New constructors take the services; the constructors that take an XSharpLexer wrap it and behave as before. The include cache is partitioned per kind of services; the lexer's own path keeps its keys. - XSharpLexer.KeywordTables and a static ReclassifyTokens give the keyword tables and the reclassification without a lexer object; KwIds keeps its shared table per lexer. - PPMode/PPState: a conditionals-only mode (defines and #if, inactive code marked, own include cache) and a rules-only mode (the UDC rule set, nothing substituted); marking of inactive code outside the VSPARSER build; read-only questions to PPRule and PPRuleDictionary. - The IDE modes are in their own partial files (XSharpPreprocessor.Ide.cs, XSharpPPRule.Ide.cs), so the part the compiler shares with the macro compiler stays easy to compare. - Additive and opt-in: the compile path enters none of the new modes. Compiler tests give the same results as before (LogBroken.Log identical, LogFixed.Log identical apart from memory addresses and the worktree path, 390/392 runtime tests in both runs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and the lexer The private helper methods that the previous commit added follow the naming rule of src/Compiler/.editorconfig (members in PascalCase). The private worker beside XSharpLexer.ReclassifyTokens is now ReclassifyTokensCore, and the static method that reads the include cache partition is GetIncludeCachePartition (IPPLexerServices has a property IncludeCachePartition). Only names change. Compiler tests give the same results as before (390/392 runtime tests, LogBroken.Log identical, LogFixed.Log identical apart from memory addresses, the date and the freed PSZ that test C629 prints). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The second PR of the series for the new IDE parser: preprocessor modes for the IDE and a lexer hook in the preprocessor. Everything is additive and opt-in: the compile path does not enter the new modes and keeps using its
XSharpLexer, soxscoutput does not change.This PR targets
CompilerChangesand builds on #2207 (preprocessor keyword table per dialect, include cache), which is merged there.Lexer hook (
IPPLexerServices)Today the preprocessor reads several things from its
XSharpLexer:HasPPIfdefs,ReclassifyTokensfor rule results, and a newXSharpLexerfor every include file. The new interfaceIPPLexerServicesnames exactly these. New constructors take the services instead of a lexer. The constructors that take a lexer wrap it inXSharpLexerServices, so the preprocessor behaves as before.XSharpLexer.KeywordTables(options)and a staticReclassifyTokens(tokens, tables)give the keyword tables and the reclassification without a lexer object.KwIdskeeps a reference to its shared table, so a lexer no longer takes the lock once per identifier.The same hook is what lets the macro compiler share the compiler's preprocessor source (the "linked items" proposal); that will be a PR of its own.
Preprocessor modes for the IDE (
PPMode,PPState)#define,#undef,#if,#ifdef,#ifndef,#elseand#endif(also through include files) and marks inactive code. Commands, translates and macros are not applied. It has its own include cache for the define state an include produces, keyed by the include, its write time, the options that affect#ifand the define state before it; the compiler'sPPIncludeFilecache is not involved.#command/#translaterules of a file and its includes (the UDC rule set of the IDE), without rewriting the code.VSPARSERbuild: the marking of inactive code thatXSharpVSParserdoes today can be switched on inXSharp.CodeAnalysistoo (markInactiveCode).PPRule.Matchesreturns the matched tokens,FirstWordMatches,ResultStartsText, the rule ordinal,PPRuleDictionary.HasKeyFor/Keys/Clone. The preprocessor itself does not call the new ones.The IDE code is in partial files of its own:
XSharpPreprocessor.Ide.cs(the modes, their constructors and the conditionals-only include cache) andXSharpPPRule.Ide.cs(the read-only questions toPPRuleandPPRuleDictionary).XSharpPreprocessor.cs,XSharpPPRule.csandXSharpPPHelpers.cskeep the hook and the small checks of the mode in the existing methods, so the part the compiler shares with the macro compiler stays easy to compare.Files:
XSharpPreprocessor.cs,XSharpPreprocessor.Ide.cs(new),XSharpPPRule.cs,XSharpPPRule.Ide.cs(new),XSharpPPHelpers.cs,XSharpPPState.cs(new types),XSharpLexerCode.cs. The macro compiler's preprocessor copy is not touched; nothing here is used on a macro path.Tests
The unit tests for the hook and the modes (marking, conditionals-only include cache, rules-only, UDC matching) live in the test project of the
XSharp.Syntaxlibrary, which comes with the next PR of the series.devhas no unit test project forXSharp.CodeAnalysisto put them in now.Before and after this change, on the same machine (before = #2207):
compiler.slnxRelease (xsc,XSCompiler,XSharp.CodeAnalysis,XSharpVSParser)src/CompilerTests/runtests.cmd)LogBroken.LogLogFixed.LogThe two failing runtime tests fail on
devas well: they need a .NET 10 runtime path that this machine lacks.🤖 Generated with Claude Code