Skip to content

Commit

Permalink
clean warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
0xF6 committed Aug 9, 2024
1 parent 57ac399 commit d1c8403
Show file tree
Hide file tree
Showing 34 changed files with 156 additions and 158 deletions.
1 change: 1 addition & 0 deletions .nuke/build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<IsPackable>false</IsPackable>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
<InvariantGlobalization>true</InvariantGlobalization>
<WarningLevel>0</WarningLevel>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<NoWarn>CS0162,CS8981,CS8632,CS9113,CS8618,CS9113,CS8321,CS0219,CS1998,IDE0053</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
Expand Down
7 changes: 3 additions & 4 deletions lib/ast/syntax/DocumentDeclaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ public string Name

public NamespaceSymbol Namespace => new(Name);

public IEnumerable<DirectiveSyntax> Directives { get; set; }
public IEnumerable<MemberDeclarationSyntax> Members { get; set; }
public IEnumerable<DirectiveSyntax> Directives { get; init; }
public IEnumerable<MemberDeclarationSyntax> Members { get; init; }
public IEnumerable<AspectDeclarationSyntax> Aspects { get; set; }
public IEnumerable<AliasSyntax> Aliases { get; set; }
public IEnumerable<AliasSyntax> Aliases { get; init; }
public FileInfo FileEntity { get; set; }
public string SourceText { get; set; }
public string[] SourceLines => SourceText.Replace("\r", "").Split("\n");

private List<NamespaceSymbol>? _includes;

public int[]? _line_offsets;

public List<NamespaceSymbol> Includes => _includes ??= Directives.OfExactType<UseSyntax>().Select(x =>
{
Expand Down
2 changes: 1 addition & 1 deletion lib/ast/syntax/ast/MemberDeclarationSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class MemberDeclarationSyntax : BaseSyntax, IPositionAware<MemberDeclarat
{
public MemberDeclarationSyntax() { }

public MemberDeclarationSyntax(MemberDeclarationSyntax other = null)
public MemberDeclarationSyntax(MemberDeclarationSyntax? other = null)
=> this.WithProperties(other);
public override SyntaxType Kind => SyntaxType.ClassMember;

Expand Down
19 changes: 14 additions & 5 deletions lib/ast/syntax/ast/PropertyDeclarationSyntax.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace vein.syntax;

using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

public class PropertyDeclarationSyntax(MemberDeclarationSyntax? heading = null) : MemberDeclarationSyntax(heading)
Expand All @@ -11,14 +12,22 @@ public PropertyDeclarationSyntax(IEnumerable<AccessorDeclarationSyntax> accessor

public override SyntaxType Kind => SyntaxType.Property;

public override IEnumerable<BaseSyntax> ChildNodes =>
base.ChildNodes.Concat(GetNodes(Type, Getter, Setter, Expression));
public override IEnumerable<BaseSyntax> ChildNodes
{
get
{
Debug.Assert(Getter != null, nameof(Getter) + " != null");
Debug.Assert(Setter != null, nameof(Setter) + " != null");
Debug.Assert(Expression != null, nameof(Expression) + " != null");
return base.ChildNodes.Concat(GetNodes(Type, Getter, Setter, Expression));
}
}

public TypeSyntax Type { get; set; }

public IdentifierExpression Identifier { get; set; }

public List<AccessorDeclarationSyntax> Accessors { get; set; } = new();
public List<AccessorDeclarationSyntax> Accessors { get; init; } = new();

public AccessorDeclarationSyntax? Getter => Accessors.FirstOrDefault(a => a.IsGetter);

Expand All @@ -27,10 +36,10 @@ public PropertyDeclarationSyntax(IEnumerable<AccessorDeclarationSyntax> accessor
public override MemberDeclarationSyntax WithTypeAndName(ParameterSyntax typeAndName)
{
Type = typeAndName.Type;
Identifier = typeAndName.Identifier ?? typeAndName.Type.Identifier;
Identifier = typeAndName.Identifier;
return this;
}
public ExpressionSyntax? Expression { get; set; }
public ExpressionSyntax? Expression { get; init; }

public bool IsShortform() => Getter is null && Setter is null && Expression is not null;

Expand Down
85 changes: 42 additions & 43 deletions lib/ast/syntax/ast/expressions/IdentifierExpression.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
namespace vein.syntax
namespace vein.syntax;

using System;
using runtime;
using Sprache;

public sealed class IdentifierExpression : ExpressionSyntax, IPositionAware<IdentifierExpression>, IEquatable<IdentifierExpression>
{
using System;
using runtime;
using Sprache;
public IdentifierExpression(string name) : base(name)
=> this.ExpressionString = name;

public class IdentifierExpression : ExpressionSyntax, IPositionAware<IdentifierExpression>, IEquatable<IdentifierExpression>
public new IdentifierExpression SetPos(Position startPos, int length)
{
public IdentifierExpression(string name) : base(name)
=> this.ExpressionString = name;

public new IdentifierExpression SetPos(Position startPos, int length)
{
base.SetPos(startPos, length);
return this;
}

public bool Equals(IdentifierExpression other)
{
if (other is null)
return false;
return this.ExpressionString == other.ExpressionString;
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((IdentifierExpression)obj);
}

public override int GetHashCode()
=> this.ExpressionString.GetHashCode();

public static bool operator ==(IdentifierExpression left, IdentifierExpression right)
=> Equals(left, right);

public static bool operator !=(IdentifierExpression left, IdentifierExpression right)
=> !Equals(left, right);

public override string ToString() =>
ExpressionString;

public static implicit operator string(IdentifierExpression i) => i.ToString();
public static implicit operator IdentifierExpression(NameSymbol s) => new(s.name);
base.SetPos(startPos, length);
return this;
}

public bool Equals(IdentifierExpression? other)
{
if (other is null)
return false;
return this.ExpressionString == other.ExpressionString;
}

public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((IdentifierExpression)obj);
}

public override int GetHashCode()
=> this.ExpressionString!.GetHashCode();

public static bool operator ==(IdentifierExpression left, IdentifierExpression right)
=> Equals(left, right);

public static bool operator !=(IdentifierExpression left, IdentifierExpression right)
=> !Equals(left, right);

public override string ToString() =>
ExpressionString;

public static implicit operator string(IdentifierExpression i) => i.ToString();
public static implicit operator IdentifierExpression(NameSymbol s) => new(s.name);
}
18 changes: 9 additions & 9 deletions lib/ast/syntax/ast/expressions/SyntaxExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,50 @@ namespace vein.syntax

public static class SyntaxExtensions
{
public static T WithLeadingComments<T>(this T syntax, IEnumerable<string> comments)
public static T? WithLeadingComments<T>(this T syntax, IEnumerable<string>? comments)
where T : BaseSyntax
{
if (comments != null)
syntax?.LeadingComments.AddRange(comments);
return syntax;
}

public static T WithLeadingComment<T>(this T syntax, string comment)
public static T? WithLeadingComment<T>(this T syntax, string? comment)
where T : BaseSyntax
{
if (comment != null)
syntax?.LeadingComments.Add(comment);
return syntax;
}

public static T WithTrailingComments<T>(this T syntax, IEnumerable<string> comments)
public static T? WithTrailingComments<T>(this T syntax, IEnumerable<string>? comments)
where T : BaseSyntax
{
if (comments != null)
syntax?.TrailingComments.AddRange(comments);
return syntax;
}

public static T WithTrailingComment<T>(this T syntax, string comment)
public static T? WithTrailingComment<T>(this T syntax, string? comment)
where T : BaseSyntax
{
if (comment != null)
syntax?.TrailingComments.Add(comment);
return syntax;
}

public static BlockSyntax WithInnerComments(this BlockSyntax syntax, IEnumerable<string> comments)
public static BlockSyntax WithInnerComments(this BlockSyntax syntax, IEnumerable<string>? comments)
{
if (comments != null)
syntax?.InnerComments.AddRange(comments);
syntax.InnerComments.AddRange(comments);

return syntax;
}

public static BlockSyntax WithInnerComment(this BlockSyntax syntax, params string[] comments) =>
syntax.WithInnerComments(comments);

public static ClassDeclarationSyntax WithInnerComments(this ClassDeclarationSyntax syntax, IEnumerable<string> comments)
public static ClassDeclarationSyntax? WithInnerComments(this ClassDeclarationSyntax? syntax, IEnumerable<string>? comments)
{
var s = new List<int>();

Expand All @@ -64,10 +64,10 @@ public static ClassDeclarationSyntax WithInnerComments(this ClassDeclarationSynt
return syntax;
}

public static ClassDeclarationSyntax WithInnerComment(this ClassDeclarationSyntax syntax, params string[] comments) =>
public static ClassDeclarationSyntax? WithInnerComment(this ClassDeclarationSyntax syntax, params string[] comments) =>
syntax.WithInnerComments(comments);

public static T WithProperties<T>(this T syntax, MemberDeclarationSyntax other = null)
public static T? WithProperties<T>(this T? syntax, MemberDeclarationSyntax? other = null)
where T : MemberDeclarationSyntax
{
if (other == null || syntax == null)
Expand Down
4 changes: 2 additions & 2 deletions lib/projectsystem/VeinProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal VeinProject(FileInfo file, YAML.Project project)
public string Name { get; }
public DirectoryInfo WorkDir { get; }
public FileInfo ProjectFile { get; }
public DirectoryInfo CacheDir => new DirectoryInfo(Path.Combine(WorkDir.FullName, "obj"));
public DirectoryInfo CacheDir => new(Path.Combine(WorkDir.FullName, "obj"));

public bool Packable => _project.Packable ?? false;
public bool IsWorkload => _project.HasWorkload ?? false;
Expand All @@ -43,7 +43,7 @@ internal VeinProject(FileInfo file, YAML.Project project)
public string License => _project.License;
public PackageUrls Urls => _project.Urls;

public NuGetVersion Version => new NuGetVersion(_project.Version);
public NuGetVersion Version => new(_project.Version);

public IReadOnlyCollection<FileInfo> Sources => WorkDir
.EnumerateFiles("*.vein", SearchOption.AllDirectories)
Expand Down
2 changes: 1 addition & 1 deletion lib/projectsystem/Workload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public record WorkloadManifest


public static async Task<WorkloadManifest> OpenAsync(FileInfo bin)
=> JsonConvert.DeserializeObject<WorkloadManifest>(await bin.ReadToEndAsync());
=> JsonConvert.DeserializeObject<WorkloadManifest>(await bin.ReadToEndAsync())!;

public string SaveAsString() =>
JsonConvert.SerializeObject(this, new JsonSerializerSettings()
Expand Down
4 changes: 2 additions & 2 deletions lib/vein.cli.core/SecurityStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void AddKey<T>(string key, T value)
{
var store = ReadStorage();

store[key] = JToken.FromObject(value);
store[key] = JToken.FromObject(value!);

Save(store);
}
Expand All @@ -64,7 +64,7 @@ private static Dictionary<string, JToken> ReadStorage()
if (!ConfigFile.Exists)
return new Dictionary<string, JToken>();
var content = ConfigFile.ReadToEnd();
return JsonConvert.DeserializeObject<Dictionary<string, JToken>>(BlowfishDecrypt(content));
return JsonConvert.DeserializeObject<Dictionary<string, JToken>>(BlowfishDecrypt(content))!;
}
catch
{
Expand Down
3 changes: 1 addition & 2 deletions runtime/common/reflection/VeinClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ public VeinClass ResolveGenericType(VeinComplexType type)
}

public virtual bool Equals(VeinClass other) => FullName.Equals(other?.FullName);


public override int GetHashCode() => FullName!.GetHashCode();


public VeinClass CreateAmorphousVersion(List<VeinClass> generics)
Expand Down
18 changes: 10 additions & 8 deletions runtime/ishtar.base/emit/ClassBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace ishtar.emit

public record ClassBuilder : VeinClass, IBaker
{
internal VeinModuleBuilder moduleBuilder;
internal readonly VeinModuleBuilder moduleBuilder;

public List<NamespaceSymbol> Includes { get; set; } = new();
public List<NamespaceSymbol> Includes { get; set; } = [];

internal ClassBuilder WithIncludes(List<NamespaceSymbol> includes)
{
Expand Down Expand Up @@ -57,7 +57,7 @@ internal ClassBuilder(VeinModuleBuilder module, QualityTypeName name, VeinClass
/// Method name will be interned.
/// </remarks>
public MethodBuilder DefineMethod(string name, VeinComplexType returnType, params VeinArgumentRef[] args)
=> DefineMethod(name, returnType, new List<VeinTypeArg>(), args);
=> DefineMethod(name, returnType, [], args);

/// <summary>
/// Define method in current class.
Expand All @@ -84,7 +84,7 @@ public MethodBuilder DefineMethod(string name, VeinComplexType returnType, List<
/// </remarks>
public MethodBuilder DefineMethod(string name, MethodFlags flags, VeinComplexType returnType,
params VeinArgumentRef[] args) =>
DefineMethod(name, flags, returnType, new List<VeinTypeArg>(), args);
DefineMethod(name, flags, returnType, [], args);

/// <summary>
/// Define method in current class.
Expand Down Expand Up @@ -139,7 +139,7 @@ public VeinProperty DefineAutoProperty(string name, FieldFlags flags, VeinClass
];

var getter =
DefineMethod(VeinProperty.GetterFnName(name), VeinProperty.ConvertShadowFlags(flags), propType, new List<VeinTypeArg>(), args);
DefineMethod(VeinProperty.GetterFnName(name), VeinProperty.ConvertShadowFlags(flags), propType, [], args);
if (!IsAbstract)
{
if (flags.HasFlag(FieldFlags.Static))
Expand Down Expand Up @@ -196,7 +196,7 @@ public VeinProperty DefineEmptyProperty(string name, FieldFlags flags, VeinClass
byte[] IBaker.BakeByteArray()
{
if (Methods.Count == 0 && Fields.Count == 0)
return Array.Empty<byte>();
return [];
using var mem = new MemoryStream();
using var binary = new BinaryWriter(mem);

Expand Down Expand Up @@ -232,12 +232,12 @@ string IBaker.BakeDebugString()
if (IsInterface) str.Append($".interface ");
else if (IsValueType) str.Append($".struct ");
else str.Append($".class ");
str.Append($"'{FullName.Name}' {Flags.EnumerateFlags(new[] { ClassFlags.None, ClassFlags.Interface }).Join(' ').ToLowerInvariant()}");
str.Append($"'{FullName.Name}' {Flags.EnumerateFlags([ClassFlags.None, ClassFlags.Interface]).Join(' ').ToLowerInvariant()}");
str.AppendLine($" extends {Parents.Select(x => $"'{x.Name}'").Join(", ")}");
str.AppendLine("{");
foreach (var field in Fields)
{
var flags = field.Flags.EnumerateFlags(new [] {FieldFlags.None}).Join(' ').ToLowerInvariant();
var flags = field.Flags.EnumerateFlags([FieldFlags.None]).Join(' ').ToLowerInvariant();
str.AppendLine($"\t.field '{field.Name}' as '{field.FieldType.ToTemplateString()}' {flags}");
}
foreach (var method in Methods.OfType<IBaker>().Select(method => method.BakeDebugString()))
Expand Down Expand Up @@ -274,6 +274,8 @@ protected override VeinMethod GetOrCreateTor(string name, bool isStatic = false)
=> throw new NotImplementedException();

public virtual bool Equals(ClassBuilder other) => FullName.Equals(other?.FullName);
public override int GetHashCode() => FullName!.GetHashCode();

public override string ToString() => base.ToString();
}
}
Loading

0 comments on commit d1c8403

Please sign in to comment.