@@ -213,6 +213,15 @@ static string SimplifyConditionLine(string line, List<string> definedSymbols)
213213
214214 static string SimplifyCondition ( string condition , List < string > definedSymbols )
215215 {
216+ // Only simplify simple patterns to avoid breaking complex nested expressions
217+ // For complex conditions with nested parentheses or ||, return as-is
218+
219+ // If condition contains || or nested parentheses, don't try to simplify
220+ if ( condition . Contains ( "||" ) || ContainsNestedParentheses ( condition ) )
221+ {
222+ return condition ;
223+ }
224+
216225 var result = condition ;
217226
218227 // Build a set of all framework-related symbols (both defined and potentially undefined)
@@ -237,31 +246,28 @@ static string SimplifyCondition(string condition, List<string> definedSymbols)
237246 var definedSet = definedSymbols . ToHashSet ( ) ;
238247
239248 // For each framework symbol, simplify based on whether it's defined
249+ // Only handle simple "SYMBOL && rest" or "rest && SYMBOL" patterns without parentheses
240250 foreach ( var symbol in allFrameworkSymbols )
241251 {
242252 var isDefined = definedSet . Contains ( symbol ) ;
243253
244254 if ( isDefined )
245255 {
246- // Symbol is defined (true)
247- // !SYMBOL is false - if part of &&, whole thing might be false (but BranchTaken would handle that)
248- // SYMBOL is true - can be removed from && chains
249- // Remove "SYMBOL && " or " && SYMBOL" patterns
250- result = System . Text . RegularExpressions . Regex . Replace ( result , $@ "\b{ symbol } \b\s*&&\s*", "" ) ;
251- result = System . Text . RegularExpressions . Regex . Replace ( result , $@ "\s*&&\s*\b{ symbol } \b", "" ) ;
252- // Handle standalone SYMBOL (entire condition is just the symbol)
256+ // Symbol is defined (true) - can be removed from simple && chains
257+ // Only match if not inside parentheses
258+ result = System . Text . RegularExpressions . Regex . Replace ( result , $@ "^\s*\b{ symbol } \b\s*&&\s*", "" ) ;
259+ result = System . Text . RegularExpressions . Regex . Replace ( result , $@ "\s*&&\s*\b{ symbol } \b\s*$", "" ) ;
260+ // Handle standalone SYMBOL
253261 if ( result . Trim ( ) == symbol )
254262 {
255263 result = "true" ;
256264 }
257265 }
258266 else
259267 {
260- // Symbol is not defined (false)
261- // !SYMBOL is true - can be removed from && chains
262- // Remove "!SYMBOL && " or " && !SYMBOL" patterns
263- result = System . Text . RegularExpressions . Regex . Replace ( result , $@ "!\s*{ symbol } \s*&&\s*", "" ) ;
264- result = System . Text . RegularExpressions . Regex . Replace ( result , $@ "\s*&&\s*!\s*{ symbol } \b", "" ) ;
268+ // Symbol is not defined (false) - !SYMBOL is true, can be removed from simple && chains
269+ result = System . Text . RegularExpressions . Regex . Replace ( result , $@ "^\s*!\s*\b{ symbol } \b\s*&&\s*", "" ) ;
270+ result = System . Text . RegularExpressions . Regex . Replace ( result , $@ "\s*&&\s*!\s*\b{ symbol } \b\s*$", "" ) ;
265271 // Handle standalone !SYMBOL
266272 if ( System . Text . RegularExpressions . Regex . IsMatch ( result . Trim ( ) , $@ "^!\s*{ symbol } $") )
267273 {
@@ -273,6 +279,18 @@ static string SimplifyCondition(string condition, List<string> definedSymbols)
273279 return result . Trim ( ) ;
274280 }
275281
282+ static bool ContainsNestedParentheses ( string condition )
283+ {
284+ var depth = 0 ;
285+ foreach ( var c in condition )
286+ {
287+ if ( c == '(' ) depth ++ ;
288+ else if ( c == ')' ) depth -- ;
289+ if ( depth > 1 ) return true ;
290+ }
291+ return false ;
292+ }
293+
276294 // Symbols to define during parsing (makes code active)
277295 // Excludes symbols that typically appear negated (like !RefsBclMemory)
278296 List < string > GetParseSymbols ( ) =>
0 commit comments