Skip to content

Commit 1f7f8f2

Browse files
committed
.
1 parent acacc33 commit 1f7f8f2

File tree

79 files changed

+108
-90
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+108
-90
lines changed

src/ApiBuilderTests/FrameworkSplitterTest.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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() =>

src/Split/net461/Polyfill_Memory_SpanSplitEnumerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// <auto-generated />
22
#pragma warning disable
3-
#if FeatureMemory && FeatureValueTuple
3+
#if FeatureMemory && !NET9_0_OR_GREATER && FeatureValueTuple
44

55
namespace Polyfills;
66

src/Split/net461/Polyfill_Stream_Read.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Polyfills;
99

1010
static partial class Polyfill
1111
{
12-
#if (!NETCOREAPP2_1_OR_GREATER) && FeatureMemory
12+
#if (!NETCOREAPP2_1_OR_GREATER && !NETSTANDARD2_1) && FeatureMemory
1313
/// <summary>
1414
/// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
1515
/// </summary>

src/Split/net461/Polyfill_StringBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// <auto-generated />
22
#pragma warning disable
3-
#if FeatureMemory && (!NETSTANDARD2_1_OR_GREATER)
3+
#if FeatureMemory && (!NETSTANDARD2_1_OR_GREATER && !NETCOREAPP2_1_OR_GREATER)
44

55
namespace Polyfills;
66

src/Split/net461/Polyfill_StringBuilder_Append.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static StringBuilder Append(this StringBuilder target, StringBuilder? val
3434
}
3535

3636

37-
#if FeatureMemory && (!NETSTANDARD2_1_OR_GREATER)
37+
#if FeatureMemory && (!NETSTANDARD2_1_OR_GREATER && !NETCOREAPP2_1_OR_GREATER)
3838

3939
/// <summary>
4040
/// Appends the string representation of a specified read-only character span to this instance.

src/Split/net461/Polyfill_StringBuilder_CopyTo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// <auto-generated />
22
#pragma warning disable
3-
#if FeatureMemory && (!NETSTANDARD2_1_OR_GREATER)
3+
#if FeatureMemory && (!NETSTANDARD2_1_OR_GREATER && !NETCOREAPP2_1_OR_GREATER)
44

55
namespace Polyfills;
66

src/Split/net461/Polyfill_TextReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Polyfills;
1010

1111
static partial class Polyfill
1212
{
13-
#if FeatureValueTask && FeatureMemory
13+
#if FeatureValueTask && FeatureMemory && !NETCOREAPP3_0_OR_GREATER
1414
/// <summary>
1515
/// Asynchronously reads the characters from the current stream into a memory block.
1616
/// </summary>

src/Split/net461/ZipArchiveEntryPolyfill.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// <auto-generated />
22
#pragma warning disable
3-
#if FeatureCompression && ((!NET472_OR_GREATER) || NETSTANDARD2_0)
3+
#if FeatureCompression && ((NETFRAMEWORK && !NET472_OR_GREATER) || NETSTANDARD2_0)
44
namespace Polyfills;
55

66
using System.IO.Compression;

src/Split/net462/Polyfill_Memory_SpanSplitEnumerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// <auto-generated />
22
#pragma warning disable
3-
#if FeatureMemory && FeatureValueTuple
3+
#if FeatureMemory && !NET9_0_OR_GREATER && FeatureValueTuple
44

55
namespace Polyfills;
66

src/Split/net462/Polyfill_Stream_Read.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Polyfills;
99

1010
static partial class Polyfill
1111
{
12-
#if (!NETCOREAPP2_1_OR_GREATER) && FeatureMemory
12+
#if (!NETCOREAPP2_1_OR_GREATER && !NETSTANDARD2_1) && FeatureMemory
1313
/// <summary>
1414
/// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
1515
/// </summary>

0 commit comments

Comments
 (0)