Skip to content

Commit

Permalink
Fix issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel committed Jan 28, 2024
1 parent 1c64f06 commit eebe2f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 1 addition & 3 deletions src/Buildalyzer/Compiler/CompilerCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#nullable enable

using System.IO;
using System.Security.Cryptography.Xml;

namespace Buildalyzer;

Expand Down Expand Up @@ -37,8 +36,7 @@ public IEnumerable<string> References()
=> Arguments.OfType<Reference>().SelectMany(x => x.Values);

public IEnumerable<string> SourceFiles(string projectFilePath)
=> Arguments.OfType<SourceFile>().Select(x => Path.Combine(Path.GetDirectoryName(projectFilePath), x.Value));

=> Arguments.OfType<SourceFile>().Select(x => Path.Combine(Path.GetDirectoryName(projectFilePath) ?? string.Empty, x.Value));

public static CompilerCommand? Parse(string commandline, CompilerLanguage language)
{
Expand Down
20 changes: 11 additions & 9 deletions src/Buildalyzer/Compiler/CompilerCommandArgument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ public abstract class CompilerCommandArgument

internal static CompilerCommandArgument FromToken(CommandLineToken token) => token.TokenType switch
{
CommandLineTokenType.Switch => new Switch(Trim(token.Span)) { Token = token },
CommandLineTokenType.Switch => new Switch(TrimsStart(token.Span)) { Token = token },
CommandLineTokenType.Argument => new SourceFile(token.Span) { Token = token },
CommandLineTokenType.ArgumentWithValue => FromArgumentWithValue(token),
_ => throw new NotSupportedException($"Token type {token.TokenType} is not supported."),
};

private static CompilerCommandArgument FromArgumentWithValue(CommandLineToken token)
{
string name = Trim(token.Span[..token.Splitter]);
string value = token.Span[(token.Splitter + 1)..];
string name = TrimsStart(token.Span[..token.Splitter]);
string value = token.Span[(token.Splitter + 1) ..];

return token switch
{
Expand All @@ -31,7 +31,9 @@ private static CompilerCommandArgument FromArgumentWithValue(CommandLineToken to
};
}

private static string Trim(string value) => value.TrimStart('-').TrimStart('/');
private static string TrimsStart(string value) => value.TrimStart('-').TrimStart('/');

protected static string TrimQuotes(string? value) => value?.Trim('"') ?? string.Empty;

private static bool Matches(string name, string toMatch) => name.Equals(toMatch, StringComparison.OrdinalIgnoreCase);
}
Expand All @@ -51,35 +53,35 @@ public ArgumentWithValue(string name, string value)

public sealed class Analyzer : CompilerCommandArgument
{
public Analyzer(string value) => Value = value.Trim('"');
public Analyzer(string value) => Value = TrimQuotes(value);
public string Value { get; }
}

public sealed class AdditionalFile : CompilerCommandArgument
{
public AdditionalFile(string value) => Value = value.Trim('"');
public AdditionalFile(string value) => Value = TrimQuotes(value);
public string Value { get; }
}

public sealed class Define : CompilerCommandArgument
{
public Define(string value)
=> Values = value.Split(';');
=> Values = value?.Split(';') ?? Array.Empty<string>();

public IReadOnlyCollection<string> Values { get; }
}

public sealed class Reference : CompilerCommandArgument
{
public Reference(string value)
=> Values = value.Split(',').Select(x => x.Trim('"')).ToArray();
=> Values = value?.Split(',').Select(TrimQuotes).ToArray() ?? Array.Empty<string>();

public IReadOnlyCollection<string> Values { get; }
}

public sealed class SourceFile : CompilerCommandArgument
{
public SourceFile(string value) => Value = value.Trim('"');
public SourceFile(string value) => Value = TrimQuotes(value);
public string Value { get; }
}

Expand Down

0 comments on commit eebe2f7

Please sign in to comment.