Skip to content

Commit

Permalink
Merge pull request #97 from kzrnm/release/atcoder2
Browse files Browse the repository at this point in the history
v3.0.0-atcoder2
  • Loading branch information
kzrnm authored Jan 25, 2023
2 parents 4bf949a + e73ffd1 commit 1b2d51f
Show file tree
Hide file tree
Showing 15 changed files with 198 additions and 47 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.0.0-pre2] - 2023-01-25
- AtCoderAnalyzer: Create operator for static abstract
- Rename DynamicModID to DynamicModIntId

## [3.0.0-pre1] - 2023-01-24
- Rename assembly from AtCoderLibrary to ac-library-csharp
- Rename some methods/classes to PascalCase
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<RepositoryUrl>https://github.com/kzrnm/ac-library-csharp</RepositoryUrl>
<PackageReleaseNotes>https://github.com/kzrnm/ac-library-csharp/blob/main/CHANGELOG.md</PackageReleaseNotes>

<Version>3.0.0-atcoder1</Version>
<AssemblyVersion>3.0.0.1</AssemblyVersion>
<Version>3.0.0-atcoder2</Version>
<AssemblyVersion>3.0.0.2</AssemblyVersion>
<RepositoryCommit Condition="'$(GIT_COMMIT)' != ''">$(GIT_COMMIT)</RepositoryCommit>

<SignAssembly>True</SignAssembly>
Expand Down
29 changes: 16 additions & 13 deletions Source/AtCoderAnalyzer/CreateOperators/EnumerateMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,19 @@ protected EnumerateMember(SemanticModel semanticModel, ITypeSymbol typeSymbol, A
if (!member.IsAbstract)
continue;
if (member is IPropertySymbol property)
yield return (CreatePropertySyntax(property), false);
yield return (CreatePropertySyntax(property, member.IsStatic), false);
else if (member is IMethodSymbol method && method.MethodKind == MethodKind.Ordinary)
yield return (CreateMethodSyntax(method), true);
yield return (CreateMethodSyntax(method, member.IsStatic), true);
}
}

protected virtual PropertyDeclarationSyntax CreatePropertySyntax(IPropertySymbol symbol)
private static SyntaxTokenList PublicModifiers(bool isStatic)
=> isStatic ? TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword)) : TokenList(Token(SyntaxKind.PublicKeyword));

protected virtual PropertyDeclarationSyntax CreatePropertySyntax(IPropertySymbol symbol, bool isStatic)
{
var dec = PropertyDeclaration(symbol.Type.ToTypeSyntax(SemanticModel, SemanticModel.SyntaxTree.Length - 1), symbol.Name)
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword)));
.WithModifiers(PublicModifiers(isStatic));

if (symbol.SetMethod == null)
return dec
Expand All @@ -77,17 +80,17 @@ protected virtual PropertyDeclarationSyntax CreatePropertySyntax(IPropertySymbol
.WithSemicolonToken(SyntaxHelpers.SemicolonToken)
});
}
protected virtual MethodDeclarationSyntax CreateMethodSyntax(IMethodSymbol symbol)
protected virtual MethodDeclarationSyntax CreateMethodSyntax(IMethodSymbol symbol, bool isStatic)
{
if (symbol.ReturnsVoid)
return CreateMethodSyntax(SemanticModel, SemanticModel.SyntaxTree.Length - 1, symbol, Block());
return CreateMethodSyntax(SemanticModel, SemanticModel.SyntaxTree.Length - 1, symbol, isStatic, Block());
else
return CreateMethodSyntax(SemanticModel, SemanticModel.SyntaxTree.Length - 1, symbol, SyntaxHelpers.ArrowDefault);
return CreateMethodSyntax(SemanticModel, SemanticModel.SyntaxTree.Length - 1, symbol, isStatic, SyntaxHelpers.ArrowDefault);
}

private MethodDeclarationSyntax CommonMethodDeclaration(IMethodSymbol symbol, SemanticModel semanticModel, int position)
private MethodDeclarationSyntax CommonMethodDeclaration(IMethodSymbol symbol, SemanticModel semanticModel, int position, bool isStatic)
=> MethodDeclaration(symbol.ReturnType.ToTypeSyntax(semanticModel, semanticModel.SyntaxTree.Length), symbol.Name)
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword)))
.WithModifiers(PublicModifiers(isStatic))
.WithAttributeLists(SingletonList(
AttributeList(
SingletonSeparatedList(
Expand All @@ -96,14 +99,14 @@ private MethodDeclarationSyntax CommonMethodDeclaration(IMethodSymbol symbol, Se
methodImplOptions.ToMinimalDisplayString(semanticModel, position),
config.UseMethodImplNumeric)))))
.WithParameterList(symbol.ToParameterListSyntax(semanticModel, semanticModel.SyntaxTree.Length));
protected MethodDeclarationSyntax CreateMethodSyntax(SemanticModel semanticModel, int position, IMethodSymbol symbol, BlockSyntax block)
protected MethodDeclarationSyntax CreateMethodSyntax(SemanticModel semanticModel, int position, IMethodSymbol symbol, bool isStatic, BlockSyntax block)
{
return CommonMethodDeclaration(symbol, semanticModel, position)
return CommonMethodDeclaration(symbol, semanticModel, position, isStatic)
.WithBody(block);
}
protected MethodDeclarationSyntax CreateMethodSyntax(SemanticModel semanticModel, int position, IMethodSymbol symbol, ArrowExpressionClauseSyntax arrowExpressionClause)
protected MethodDeclarationSyntax CreateMethodSyntax(SemanticModel semanticModel, int position, IMethodSymbol symbol, bool isStatic, ArrowExpressionClauseSyntax arrowExpressionClause)
{
return CommonMethodDeclaration(symbol, semanticModel, position)
return CommonMethodDeclaration(symbol, semanticModel, position, isStatic)
.WithExpressionBody(arrowExpressionClause)
.WithSemicolonToken(SyntaxHelpers.SemicolonToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal abstract class OperatorEnumerateMember : EnumerateMember
protected OperatorEnumerateMember(SemanticModel semanticModel, ITypeSymbol typeSymbol, AtCoderAnalyzerConfig config) : base(semanticModel, typeSymbol, config) { }
protected abstract SyntaxKind? GetSyntaxKind(IMethodSymbol symbol);

protected override MethodDeclarationSyntax CreateMethodSyntax(IMethodSymbol symbol)
protected override MethodDeclarationSyntax CreateMethodSyntax(IMethodSymbol symbol, bool isStatic)
{
if (GetSyntaxKind(symbol) is SyntaxKind kind)
{
Expand All @@ -20,9 +20,9 @@ protected override MethodDeclarationSyntax CreateMethodSyntax(IMethodSymbol symb
IdentifierName(symbol.Parameters[1].Name));
return CreateMethodSyntax(
SemanticModel, SemanticModel.SyntaxTree.Length - 1,
symbol, ArrowExpressionClause(operatorCall));
symbol, false, ArrowExpressionClause(operatorCall));
}
return base.CreateMethodSyntax(symbol);
return base.CreateMethodSyntax(symbol, isStatic);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AtCoderAnalyzer.CreateOperators.Specified
internal class CastEnumerateMember : EnumerateMember
{
internal CastEnumerateMember(SemanticModel semanticModel, ITypeSymbol typeSymbol, AtCoderAnalyzerConfig config) : base(semanticModel, typeSymbol, config) { }
protected override MethodDeclarationSyntax CreateMethodSyntax(IMethodSymbol symbol)
protected override MethodDeclarationSyntax CreateMethodSyntax(IMethodSymbol symbol, bool isStatic)
{
if (symbol is
{
Expand All @@ -18,10 +18,10 @@ protected override MethodDeclarationSyntax CreateMethodSyntax(IMethodSymbol symb
{
return CreateMethodSyntax(
SemanticModel, SemanticModel.SyntaxTree.Length - 1,
symbol,
symbol, isStatic,
ArrowExpressionClause(CastExpression(symbol.ReturnType.ToTypeSyntax(SemanticModel, SemanticModel.SyntaxTree.Length - 1), IdentifierName(symbol.Parameters[0].Name))));
}
return base.CreateMethodSyntax(symbol);
return base.CreateMethodSyntax(symbol, isStatic);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace AtCoderAnalyzer.CreateOperators.Specified
internal class ComparerEnumerateMember : EnumerateMember
{
internal ComparerEnumerateMember(SemanticModel semanticModel, ITypeSymbol typeSymbol, AtCoderAnalyzerConfig config) : base(semanticModel, typeSymbol, config) { }
protected override MethodDeclarationSyntax CreateMethodSyntax(IMethodSymbol symbol)
protected override MethodDeclarationSyntax CreateMethodSyntax(IMethodSymbol symbol, bool isStatic)
{
if (symbol is
{
Expand All @@ -25,9 +25,9 @@ protected override MethodDeclarationSyntax CreateMethodSyntax(IMethodSymbol symb
var invocation = InvocationExpression(caller, args);
return CreateMethodSyntax(
SemanticModel, SemanticModel.SyntaxTree.Length - 1,
symbol, ArrowExpressionClause(invocation));
symbol, isStatic, ArrowExpressionClause(invocation));
}
return base.CreateMethodSyntax(symbol);
return base.CreateMethodSyntax(symbol, isStatic);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace AtCoderAnalyzer.CreateOperators.Specified
internal class MinMaxValueEnumerateMember : EnumerateMember
{
internal MinMaxValueEnumerateMember(SemanticModel semanticModel, ITypeSymbol typeSymbol, AtCoderAnalyzerConfig config) : base(semanticModel, typeSymbol, config) { }
protected override PropertyDeclarationSyntax CreatePropertySyntax(IPropertySymbol symbol)
protected override PropertyDeclarationSyntax CreatePropertySyntax(IPropertySymbol symbol, bool isStatic)
{
if (symbol is { Name: "MaxValue" or "MinValue" })
{
Expand All @@ -24,7 +24,7 @@ protected override PropertyDeclarationSyntax CreatePropertySyntax(IPropertySymbo
.WithExpressionBody(ArrowExpressionClause(property))
.WithSemicolonToken(SyntaxHelpers.SemicolonToken);
}
return base.CreatePropertySyntax(symbol);
return base.CreatePropertySyntax(symbol, isStatic);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal MultiplicationEnumerateMember(SemanticModel semanticModel, ITypeSymbol
_ => null,
};

protected override PropertyDeclarationSyntax CreatePropertySyntax(IPropertySymbol symbol)
protected override PropertyDeclarationSyntax CreatePropertySyntax(IPropertySymbol symbol, bool isStatic)
{
if (symbol.Name == "MultiplyIdentity")
return PropertyDeclaration(symbol.Type.ToTypeSyntax(SemanticModel, SemanticModel.SyntaxTree.Length - 1), symbol.Name)
Expand All @@ -27,7 +27,7 @@ protected override PropertyDeclarationSyntax CreatePropertySyntax(IPropertySymbo
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(1)))
)
.WithSemicolonToken(SyntaxHelpers.SemicolonToken);
return base.CreatePropertySyntax(symbol);
return base.CreatePropertySyntax(symbol, isStatic);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal class UnaryNumEnumerateMember : EnumerateMember
{
internal UnaryNumEnumerateMember(SemanticModel semanticModel, ITypeSymbol typeSymbol, AtCoderAnalyzerConfig config) : base(semanticModel, typeSymbol, config) { }

protected override MethodDeclarationSyntax CreateMethodSyntax(IMethodSymbol symbol)
protected override MethodDeclarationSyntax CreateMethodSyntax(IMethodSymbol symbol, bool isStatic)
{
if (symbol switch
{
Expand All @@ -25,9 +25,9 @@ protected override MethodDeclarationSyntax CreateMethodSyntax(IMethodSymbol symb
IdentifierName(symbol.Parameters[0].Name));
return CreateMethodSyntax(
SemanticModel, SemanticModel.SyntaxTree.Length - 1,
symbol, ArrowExpressionClause(operatorCall));
symbol, isStatic, ArrowExpressionClause(operatorCall));
}
return base.CreateMethodSyntax(symbol);
return base.CreateMethodSyntax(symbol, isStatic);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
#if GENERIC_MATH
[System.Obsolete("Use generic math")]
#endif
public class DynamicModIntFenwickTree<T> : FenwickTree<DynamicModInt<T>, DynamicModIntOperator<T>> where T : struct, IDynamicModID { public DynamicModIntFenwickTree(int n) : base(n) { } }
public class DynamicModIntFenwickTree<T> : FenwickTree<DynamicModInt<T>, DynamicModIntOperator<T>> where T : struct { public DynamicModIntFenwickTree(int n) : base(n) { } }
}
16 changes: 8 additions & 8 deletions Source/ac-library-csharp/Math/DynamicModInt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ namespace AtCoder
/// </summary>
/// <example>
/// <code>
/// public readonly struct ModID123 : IDynamicModID { }
/// public readonly struct ModID123 : IDynamicModIntId { }
/// </code>
/// </example>
[IsOperator]
public interface IDynamicModID { }
public static class DynamicModIDExtension
public interface IDynamicModIntId { }
public static class DynamicModIntIdExtension
{
public static void SetMod<T>(this T _, int mod) where T : struct, IDynamicModID => DynamicModInt<T>.Mod = mod;
public static void SetMod<T>(this T _, int mod) where T : struct, IDynamicModIntId => DynamicModInt<T>.Mod = mod;
}
public readonly struct DynamicModID0 : IDynamicModID { }
public readonly struct DynamicModID1 : IDynamicModID { }
public readonly struct DynamicModID2 : IDynamicModID { }
public readonly struct DynamicModIntId0 : IDynamicModIntId { }
public readonly struct DynamicModIntId1 : IDynamicModIntId { }
public readonly struct DynamicModIntId2 : IDynamicModIntId { }

/// <summary>
/// 四則演算時に自動で mod を取る整数型。実行時に mod が決まる場合でも使用可能です。
Expand All @@ -35,7 +35,7 @@ public static class DynamicModIDExtension
/// <typeparam name="T">mod の ID を表す構造体</typeparam>
/// <example>
/// <code>
/// using AtCoder.ModInt = AtCoder.DynamicModInt&lt;AtCoder.DynamicModID0&gt;;
/// using AtCoder.ModInt = AtCoder.DynamicModInt&lt;AtCoder.DynamicModIntId0&gt;;
///
/// void SomeMethod()
/// {
Expand Down
Loading

0 comments on commit 1b2d51f

Please sign in to comment.