Browse Source

Code cleanup.

pull/1581/head
Joao Matos 4 years ago committed by João Matos
parent
commit
50451ac897
  1. 58
      src/AST/Class.cs
  2. 54
      src/AST/Declaration.cs
  3. 70
      src/AST/DeclarationsList.cs
  4. 15
      src/AST/Function.cs
  5. 2
      src/AST/Method.cs
  6. 54
      src/AST/Template.cs
  7. 14
      src/AST/Type.cs
  8. 38
      src/AST/TypeExtensions.cs
  9. 25
      src/Generator/AST/Utils.cs
  10. 13
      src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs
  11. 3
      src/Generator/Passes/CheckAmbiguousFunctions.cs
  12. 20
      src/Generator/Passes/CheckDuplicatedNamesPass.cs
  13. 8
      src/Parser/ASTConverter.cs

58
src/AST/Class.cs

@ -47,19 +47,12 @@ namespace CppSharp.AST @@ -47,19 +47,12 @@ namespace CppSharp.AST
{
get
{
Class @class;
Type.TryGetClass(out @class);
Type.TryGetClass(out var @class);
return @class;
}
}
public bool IsClass
{
get
{
return Type.IsClass();
}
}
public bool IsClass => Type.IsClass();
}
public enum ClassType
@ -69,7 +62,7 @@ namespace CppSharp.AST @@ -69,7 +62,7 @@ namespace CppSharp.AST
Interface
}
// Represents a C++ record Decl.
// Represents a C++ record decl.
public class Class : DeclarationContext
{
public List<BaseClassSpecifier> Bases;
@ -104,10 +97,7 @@ namespace CppSharp.AST @@ -104,10 +97,7 @@ namespace CppSharp.AST
public bool IsOpaque
{
get => isOpaque ?? (IsIncomplete && CompleteDeclaration == null);
set
{
isOpaque = value;
}
set => isOpaque = value;
}
// True if the class is dynamic.
@ -163,39 +153,22 @@ namespace CppSharp.AST @@ -163,39 +153,22 @@ namespace CppSharp.AST
}
}
public bool HasNonIgnoredBase
{
get
{
return HasBaseClass && !IsValueType
&& BaseClass != null
&& !BaseClass.IsValueType
&& BaseClass.IsGenerated;
}
}
public bool HasNonIgnoredBase =>
HasBaseClass && !IsValueType
&& BaseClass != null
&& !BaseClass.IsValueType
&& BaseClass.IsGenerated;
public bool NeedsBase
{
get { return HasNonIgnoredBase && IsGenerated; }
}
public bool NeedsBase => HasNonIgnoredBase && IsGenerated;
// When we have an interface, this is the class mapped to that interface.
public Class OriginalClass { get; set; }
public bool IsValueType
{
get { return Type == ClassType.ValueType || IsUnion; }
}
public bool IsValueType => Type == ClassType.ValueType || IsUnion;
public bool IsRefType
{
get { return Type == ClassType.RefType && !IsUnion; }
}
public bool IsRefType => Type == ClassType.RefType && !IsUnion;
public bool IsInterface
{
get { return Type == ClassType.Interface; }
}
public bool IsInterface => Type == ClassType.Interface;
public bool IsAbstractImpl
{
@ -261,10 +234,7 @@ namespace CppSharp.AST @@ -261,10 +234,7 @@ namespace CppSharp.AST
}
}
public bool IsTemplate
{
get { return IsDependent && TemplateParameters.Count > 0; }
}
public bool IsTemplate => IsDependent && TemplateParameters.Count > 0;
public override IEnumerable<Function> FindOperator(CXXOperatorKind kind)
{

54
src/AST/Declaration.cs

@ -53,24 +53,14 @@ namespace CppSharp.AST @@ -53,24 +53,14 @@ namespace CppSharp.AST
public virtual GenerationKind GenerationKind
{
get
{
if (generationKind.HasValue)
return generationKind.Value;
return GenerationKind.Generate;
}
set
{
generationKind = value;
}
get => generationKind ?? GenerationKind.Generate;
set => generationKind = value;
}
/// <summary>
/// Whether the declaration should be generated.
/// </summary>
public virtual bool IsGenerated => GenerationKind == GenerationKind.Generate;
public bool IsGenerated => GenerationKind == GenerationKind.Generate;
/// <summary>
/// Whether the declaration has an explicit set generation kind.
@ -81,8 +71,7 @@ namespace CppSharp.AST @@ -81,8 +71,7 @@ namespace CppSharp.AST
/// Whether the declaration was explicitly set to be generated via
/// the GenerationKind property as opposed to the default generated state.
/// </summary>
public virtual bool IsExplicitlyGenerated =>
generationKind.HasValue && generationKind.Value == GenerationKind.Generate;
public bool IsExplicitlyGenerated => generationKind == GenerationKind.Generate;
/// <summary>
/// Whether the declaration internal bindings should be generated.
@ -92,9 +81,8 @@ namespace CppSharp.AST @@ -92,9 +81,8 @@ namespace CppSharp.AST
/// <summary>
/// Whether a binded version of this declaration is available.
/// </summary>
public bool IsDeclared =>
GenerationKind == GenerationKind.Generate
|| GenerationKind == GenerationKind.Internal;
public bool IsDeclared => GenerationKind == GenerationKind.Generate
|| GenerationKind == GenerationKind.Internal;
public void ExplicitlyIgnore()
{
@ -104,13 +92,13 @@ namespace CppSharp.AST @@ -104,13 +92,13 @@ namespace CppSharp.AST
[Obsolete("Replace set by ExplicitlyIgnore(). Replace get by GenerationKind == GenerationKind.None.")]
public bool ExplicityIgnored
{
get { return GenerationKind == GenerationKind.None; }
get => GenerationKind == GenerationKind.None;
set { if (value) ExplicitlyIgnore(); }
}
public virtual bool Ignore
{
get { return GenerationKind == GenerationKind.None; }
get => GenerationKind == GenerationKind.None;
set { if (value) ExplicitlyIgnore(); }
}
}
@ -135,12 +123,11 @@ namespace CppSharp.AST @@ -135,12 +123,11 @@ namespace CppSharp.AST
// Namespace the declaration is contained in.
public DeclarationContext Namespace
{
get { return @namespace; }
get => @namespace;
set
{
@namespace = value;
if (OriginalNamespace == null)
OriginalNamespace = @namespace;
OriginalNamespace ??= @namespace;
}
}
@ -177,12 +164,11 @@ namespace CppSharp.AST @@ -177,12 +164,11 @@ namespace CppSharp.AST
public virtual string Name
{
get { return name; }
get => name;
set
{
name = value;
if (OriginalName == null)
OriginalName = name;
OriginalName ??= name;
}
}
@ -192,19 +178,13 @@ namespace CppSharp.AST @@ -192,19 +178,13 @@ namespace CppSharp.AST
/// the real and the "effective" name of the declaration to properly
/// support things like inline namespaces when handling type maps.
/// </summary>
public virtual string LogicalName
{
get { return Name; }
}
public virtual string LogicalName => Name;
/// <summary>
/// The effective original name of a declaration is the logical
/// original name for the declaration.
/// </summary>
public virtual string LogicalOriginalName
{
get { return OriginalName; }
}
public virtual string LogicalOriginalName => OriginalName;
public static string QualifiedNameSeparator = "::";
@ -233,8 +213,7 @@ namespace CppSharp.AST @@ -233,8 +213,7 @@ namespace CppSharp.AST
var currentNamespace = @namespace;
while (currentNamespace != null)
{
var isInlineNamespace = currentNamespace is Namespace &&
((Namespace) currentNamespace).IsInline;
var isInlineNamespace = currentNamespace is Namespace {IsInline: true};
if (!isInlineNamespace)
namespaces.Push(currentNamespace);
currentNamespace = currentNamespace.Namespace;
@ -280,8 +259,7 @@ namespace CppSharp.AST @@ -280,8 +259,7 @@ namespace CppSharp.AST
private static string GetDeclName(Declaration decl, string name)
{
var specialization = decl as ClassTemplateSpecialization;
if (specialization != null)
if (decl is ClassTemplateSpecialization specialization)
return string.Format("{0}<{1}>", name,
string.Join(", ", specialization.Arguments.Select(
a => a.Type.Type == null ? string.Empty : a.Type.ToString())));

70
src/AST/DeclarationsList.cs

@ -23,7 +23,7 @@ namespace CppSharp.AST @@ -23,7 +23,7 @@ namespace CppSharp.AST
public void AddRange(IEnumerable<Declaration> declarations)
{
foreach (Declaration declaration in declarations)
foreach (var declaration in declarations)
{
Add(declaration);
}
@ -31,8 +31,9 @@ namespace CppSharp.AST @@ -31,8 +31,9 @@ namespace CppSharp.AST
protected override void InsertItem(int index, Declaration item)
{
Kind kind = GetKind(item);
int offset = GetOffset(kind);
var kind = GetKind(item);
var offset = GetOffset(kind);
// USR null means an artificial declaration, add at the end
if (item.USR == null)
{
@ -40,10 +41,11 @@ namespace CppSharp.AST @@ -40,10 +41,11 @@ namespace CppSharp.AST
}
else
{
int i = BinarySearch(GetStart(kind), offset, item);
var i = BinarySearch(GetStart(kind), offset, item);
base.InsertItem(i, item);
}
for (Kind i = kind; i <= Kind.Event; i++)
for (var i = kind; i <= Kind.Event; i++)
{
if (offsets.ContainsKey(i))
{
@ -55,7 +57,7 @@ namespace CppSharp.AST @@ -55,7 +57,7 @@ namespace CppSharp.AST
protected override void RemoveItem(int index)
{
base.RemoveItem(index);
for (Kind i = Kind.Namespace; i <= Kind.Event; i++)
for (var i = Kind.Namespace; i <= Kind.Event; i++)
{
if (offsets.ContainsKey(i) && index < offsets[i])
{
@ -64,14 +66,16 @@ namespace CppSharp.AST @@ -64,14 +66,16 @@ namespace CppSharp.AST
}
}
private IEnumerable<T> OfType<T>(Kind kind) where T : Declaration
{
if (!offsets.ContainsKey(kind))
{
yield break;
}
int offset = offsets[kind];
for (int i = GetStart(kind); i < offset; i++)
var offset = offsets[kind];
for (var i = GetStart(kind); i < offset; i++)
{
yield return (T) this[i];
}
@ -79,47 +83,41 @@ namespace CppSharp.AST @@ -79,47 +83,41 @@ namespace CppSharp.AST
private static Kind GetKind(Declaration item)
{
if (item is Namespace)
return Kind.Namespace;
if (item is Enumeration)
return Kind.Enum;
if (item is Function)
return Kind.Function;
if (item is Class)
return Kind.Class;
if (item is Template)
return Kind.Template;
if (item is TypedefNameDecl)
return Kind.Typedef;
if (item is Variable)
return Kind.Variable;
if (item is Friend)
return Kind.Friend;
if (item is Event)
return Kind.Event;
throw new System.ArgumentOutOfRangeException(nameof(item),
"Unsupported type of declaration.");
return item switch
{
Namespace _ => Kind.Namespace,
Enumeration _ => Kind.Enum,
Function _ => Kind.Function,
Class _ => Kind.Class,
Template _ => Kind.Template,
TypedefNameDecl _ => Kind.Typedef,
Variable _ => Kind.Variable,
Friend _ => Kind.Friend,
Event _ => Kind.Event,
_ => throw new System.ArgumentOutOfRangeException(nameof(item), "Unsupported type of declaration.")
};
}
private int GetOffset(Kind kind)
{
if (!offsets.ContainsKey(kind))
if (offsets.ContainsKey(kind))
return offsets[kind];
for (var i = kind - 1; i >= Kind.Namespace; i--)
{
for (Kind i = kind - 1; i >= Kind.Namespace; i--)
if (offsets.ContainsKey(i))
{
if (offsets.ContainsKey(i))
{
return offsets[kind] = offsets[i];
}
return offsets[kind] = offsets[i];
}
offsets[kind] = 0;
}
offsets[kind] = 0;
return offsets[kind];
}
private int GetStart(Kind kind)
{
for (Kind i = kind - 1; i >= Kind.Namespace; i--)
for (var i = kind - 1; i >= Kind.Namespace; i--)
{
if (offsets.ContainsKey(i))
{

15
src/AST/Function.cs

@ -111,10 +111,7 @@ namespace CppSharp.AST @@ -111,10 +111,7 @@ namespace CppSharp.AST
/// It's false in Clang to begin with. I tried fixing it to no avail.
/// I don't have any more time at the moment.
/// </summary>
public bool IsConst
{
get { return DebugText.StartsWith("const ", System.StringComparison.Ordinal); }
}
public bool IsConst => DebugText.StartsWith("const ", System.StringComparison.Ordinal);
ExpressionObsolete defaultArgument;
private Stmt defaultValue;
@ -193,8 +190,10 @@ namespace CppSharp.AST @@ -193,8 +190,10 @@ namespace CppSharp.AST
FunctionType = function.FunctionType;
if (function.SpecializationInfo != null)
{
SpecializationInfo = new FunctionTemplateSpecialization(function.SpecializationInfo);
SpecializationInfo.SpecializedFunction = function;
SpecializationInfo = new FunctionTemplateSpecialization(function.SpecializationInfo)
{
SpecializedFunction = function
};
}
}
@ -279,8 +278,8 @@ namespace CppSharp.AST @@ -279,8 +278,8 @@ namespace CppSharp.AST
public Type Type => ReturnType.Type;
public QualifiedType QualifiedType
{
get { return ReturnType; }
set { ReturnType = value; }
get => ReturnType;
set => ReturnType = value;
}
}
}

2
src/AST/Method.cs

@ -196,7 +196,7 @@ namespace CppSharp.AST @@ -196,7 +196,7 @@ namespace CppSharp.AST
public override string ToString()
{
return DebugText;
return !string.IsNullOrEmpty(DebugText) ? DebugText : Name;
}
}
}

54
src/AST/Template.cs

@ -35,7 +35,7 @@ namespace CppSharp.AST @@ -35,7 +35,7 @@ namespace CppSharp.AST
}
/// <summary>
/// Represents a template parameter
/// Represents a type template parameter.
/// </summary>
public class TypeTemplateParameter : Declaration
{
@ -70,7 +70,7 @@ namespace CppSharp.AST @@ -70,7 +70,7 @@ namespace CppSharp.AST
}
/// <summary>
/// Represents a hard-coded template parameter
/// Represents a non-type template parameter.
/// </summary>
public class NonTypeTemplateParameter : Declaration
{
@ -139,12 +139,7 @@ namespace CppSharp.AST @@ -139,12 +139,7 @@ namespace CppSharp.AST
// Name of the declaration.
public override string Name
{
get
{
if (TemplatedDecl != null)
return TemplatedDecl.Name;
return base.Name;
}
get => TemplatedDecl != null ? TemplatedDecl.Name : base.Name;
set
{
base.Name = value;
@ -166,7 +161,7 @@ namespace CppSharp.AST @@ -166,7 +161,7 @@ namespace CppSharp.AST
public Declaration TemplatedDecl;
public List<Declaration> Parameters;
public readonly List<Declaration> Parameters;
public override string ToString()
{
@ -190,12 +185,9 @@ namespace CppSharp.AST @@ -190,12 +185,9 @@ namespace CppSharp.AST
/// </summary>
public class ClassTemplate : Template
{
public List<ClassTemplateSpecialization> Specializations;
public readonly List<ClassTemplateSpecialization> Specializations;
public Class TemplatedClass
{
get { return TemplatedDecl as Class; }
}
public Class TemplatedClass => TemplatedDecl as Class;
public ClassTemplate()
{
@ -215,12 +207,7 @@ namespace CppSharp.AST @@ -215,12 +207,7 @@ namespace CppSharp.AST
public override string Name
{
get
{
if(TemplatedDecl != null)
return TemplatedClass.Name;
return base.Name;
}
get => TemplatedDecl != null ? TemplatedClass.Name : base.Name;
set
{
if(TemplatedDecl != null)
@ -232,12 +219,7 @@ namespace CppSharp.AST @@ -232,12 +219,7 @@ namespace CppSharp.AST
public override string OriginalName
{
get
{
if(TemplatedDecl != null)
return TemplatedClass.OriginalName;
return base.OriginalName;
}
get => TemplatedDecl != null ? TemplatedClass.OriginalName : base.OriginalName;
set
{
if(TemplatedDecl != null)
@ -293,7 +275,7 @@ namespace CppSharp.AST @@ -293,7 +275,7 @@ namespace CppSharp.AST
{
public ClassTemplate TemplatedDecl;
public List<TemplateArgument> Arguments;
public readonly List<TemplateArgument> Arguments;
public TemplateSpecializationKind SpecializationKind;
@ -327,7 +309,7 @@ namespace CppSharp.AST @@ -327,7 +309,7 @@ namespace CppSharp.AST
/// </summary>
public class FunctionTemplate : Template
{
public List<FunctionTemplateSpecialization> Specializations;
public readonly List<FunctionTemplateSpecialization> Specializations;
public FunctionTemplate()
{
@ -340,10 +322,7 @@ namespace CppSharp.AST @@ -340,10 +322,7 @@ namespace CppSharp.AST
Specializations = new List<FunctionTemplateSpecialization>();
}
public Function TemplatedFunction
{
get { return TemplatedDecl as Function; }
}
public Function TemplatedFunction => TemplatedDecl as Function;
public override T Visit<T>(IDeclVisitor<T> visitor)
{
@ -359,7 +338,7 @@ namespace CppSharp.AST @@ -359,7 +338,7 @@ namespace CppSharp.AST
{
public FunctionTemplate Template;
public List<TemplateArgument> Arguments;
public readonly List<TemplateArgument> Arguments;
public Function SpecializedFunction;
@ -390,12 +369,9 @@ namespace CppSharp.AST @@ -390,12 +369,9 @@ namespace CppSharp.AST
/// </summary>
public class VarTemplate : Template
{
public List<VarTemplateSpecialization> Specializations;
public readonly List<VarTemplateSpecialization> Specializations;
public Variable TemplatedVariable
{
get { return TemplatedDecl as Variable; }
}
public Variable TemplatedVariable => TemplatedDecl as Variable;
public VarTemplate()
{
@ -421,7 +397,7 @@ namespace CppSharp.AST @@ -421,7 +397,7 @@ namespace CppSharp.AST
{
public VarTemplate TemplatedDecl;
public List<TemplateArgument> Arguments;
public readonly List<TemplateArgument> Arguments;
public TemplateSpecializationKind SpecializationKind;

14
src/AST/Type.cs

@ -191,10 +191,7 @@ namespace CppSharp.AST @@ -191,10 +191,7 @@ namespace CppSharp.AST
Size = type.Size;
}
public Type Type
{
get { return QualifiedType.Type; }
}
public Type Type => QualifiedType.Type;
public override T Visit<T>(ITypeVisitor<T> visitor, TypeQualifiers quals = new TypeQualifiers())
{
@ -690,12 +687,10 @@ namespace CppSharp.AST @@ -690,12 +687,10 @@ namespace CppSharp.AST
{
var finalType = Desugared.Type.GetFinalPointee() ?? Desugared.Type;
var tagType = finalType as TagType;
if (tagType != null)
if (finalType is TagType tagType)
return tagType.Declaration;
var injectedClassNameType = finalType as InjectedClassNameType;
if (injectedClassNameType == null)
if (!(finalType is InjectedClassNameType injectedClassNameType))
return null;
var injectedSpecializationType = (TemplateSpecializationType)
@ -801,11 +796,14 @@ namespace CppSharp.AST @@ -801,11 +796,14 @@ namespace CppSharp.AST
: base(type)
{
if (type.Parameter != null)
{
Parameter = new TypeTemplateParameter
{
Constraint = type.Parameter.Constraint,
Name = type.Parameter.Name
};
}
Depth = type.Depth;
Index = type.Index;
IsParameterPack = type.IsParameterPack;

38
src/AST/TypeExtensions.cs

@ -121,37 +121,33 @@ @@ -121,37 +121,33 @@
t = t.Desugar();
TagType tagType = null;
var type = t as TemplateSpecializationType;
if (type != null)
if (t is TemplateSpecializationType type)
{
if (type.IsDependent)
{
if (type.Template is TypeAliasTemplate)
{
type.Desugared.Type.TryGetDeclaration(out decl, value);
decl = decl as T;
return decl != null;
}
var classTemplate = type.Template as ClassTemplate;
if (classTemplate != null)
switch (type.Template)
{
var templatedClass = classTemplate.TemplatedClass;
decl = templatedClass.CompleteDeclaration == null
? templatedClass as T
: (T) templatedClass.CompleteDeclaration;
if (decl != null)
case TypeAliasTemplate _:
type.Desugared.Type.TryGetDeclaration(out decl, value);
return decl != null;
case ClassTemplate classTemplate:
{
var templatedClass = classTemplate.TemplatedClass;
decl = templatedClass.CompleteDeclaration == null
? templatedClass as T
: (T) templatedClass.CompleteDeclaration;
if (decl == null)
return false;
if (value != null)
type.Template = new ClassTemplate { TemplatedDecl = value };
return true;
}
return false;
case TemplateTemplateParameter templateTemplateParameter:
return (decl = templateTemplateParameter.TemplatedDecl as T) != null;
}
var templateTemplateParameter = type.Template as TemplateTemplateParameter;
if (templateTemplateParameter != null)
return (decl = templateTemplateParameter.TemplatedDecl as T) != null;
}
tagType = (type.Desugared.Type.GetFinalPointee() ?? type.Desugared.Type) as TagType;
}

25
src/Generator/AST/Utils.cs

@ -11,8 +11,8 @@ namespace CppSharp.AST @@ -11,8 +11,8 @@ namespace CppSharp.AST
{
if (!function.IsGenerated) return true;
if (function is Method)
return CheckIgnoreMethod(function as Method);
if (function is Method method)
return CheckIgnoreMethod(method);
return false;
}
@ -127,9 +127,8 @@ namespace CppSharp.AST @@ -127,9 +127,8 @@ namespace CppSharp.AST
private static bool UsesAdditionalTypeParam(Method method)
{
var specialization = method.Namespace as ClassTemplateSpecialization;
Class template;
if (specialization != null)
if (method.Namespace is ClassTemplateSpecialization specialization)
template = specialization.TemplatedDecl.TemplatedClass;
else
{
@ -143,8 +142,7 @@ namespace CppSharp.AST @@ -143,8 +142,7 @@ namespace CppSharp.AST
if (!p.IsDependent)
return false;
var desugared = p.Type.Desugar();
var finalType = (desugared.GetFinalPointee() ?? desugared).Desugar()
as TemplateParameterType;
var finalType = (desugared.GetFinalPointee() ?? desugared).Desugar() as TemplateParameterType;
return finalType != null && !typeParams.Contains(finalType.Parameter.Name);
});
}
@ -165,8 +163,7 @@ namespace CppSharp.AST @@ -165,8 +163,7 @@ namespace CppSharp.AST
ITypeMapDatabase typeMaps, bool internalOnly, Type type,
ClassTemplateSpecialization specialization)
{
TypeMap typeMap;
typeMaps.FindTypeMap(type, out typeMap);
typeMaps.FindTypeMap(type, out var typeMap);
return (!internalOnly && (((specialization.Ignore ||
specialization.TemplatedDecl.TemplatedClass.Ignore) && typeMap == null) ||
@ -179,8 +176,7 @@ namespace CppSharp.AST @@ -179,8 +176,7 @@ namespace CppSharp.AST
private static ClassTemplateSpecialization GetParentSpecialization(Type type)
{
Declaration declaration;
if (type.TryGetDeclaration(out declaration))
if (type.TryGetDeclaration(out Declaration declaration))
{
ClassTemplateSpecialization specialization = null;
do
@ -207,8 +203,7 @@ namespace CppSharp.AST @@ -207,8 +203,7 @@ namespace CppSharp.AST
public static bool IsMappedToPrimitive(ITypeMapDatabase typeMaps, Type type)
{
TypeMap typeMap;
if (!typeMaps.FindTypeMap(type, out typeMap))
if (!typeMaps.FindTypeMap(type, out var typeMap))
return false;
var typePrinterContext = new TypePrinterContext { Type = type };
@ -258,16 +253,14 @@ namespace CppSharp.AST @@ -258,16 +253,14 @@ namespace CppSharp.AST
public static bool IsBuiltinOperator(CXXOperatorKind kind)
{
bool isBuiltin;
GetOperatorIdentifier(kind, out isBuiltin);
GetOperatorIdentifier(kind, out var isBuiltin);
return isBuiltin;
}
public static string GetOperatorIdentifier(CXXOperatorKind kind)
{
bool isBuiltin;
return GetOperatorIdentifier(kind, out isBuiltin);
return GetOperatorIdentifier(kind, out _);
}
public static string GetOperatorIdentifier(CXXOperatorKind kind,

13
src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs

@ -30,8 +30,7 @@ namespace CppSharp.Generators.CSharp @@ -30,8 +30,7 @@ namespace CppSharp.Generators.CSharp
parameter.DefaultArgument.Class == StatementClass.BinaryOperator))
return $"({desugared.Visit(typePrinter)}) {expression}";
var finalType = (desugared.GetFinalPointee() ?? desugared).Desugar();
Class @class;
if (finalType.TryGetClass(out @class) && @class.IsInterface)
if (finalType.TryGetClass(out var @class) && @class.IsInterface)
return $@"({@class.Visit(typePrinter)}) ({
@class.OriginalClass.Visit(typePrinter)}) {expression}";
return expression;
@ -46,17 +45,13 @@ namespace CppSharp.Generators.CSharp @@ -46,17 +45,13 @@ namespace CppSharp.Generators.CSharp
switch (callExpr.Declaration.GenerationKind)
{
case GenerationKind.Generate:
return string.Format("{0}.{1}({2})",
typePrinter.VisitDeclaration(callExpr.Declaration.Namespace),
callExpr.Declaration.Name,
string.Join(", ", callExpr.Arguments.Select(VisitExpression)));
var args = string.Join(", ", callExpr.Arguments.Select(VisitExpression));
return $"{typePrinter.VisitDeclaration(callExpr.Declaration.Namespace)}.{callExpr.Declaration.Name}({args})";
case GenerationKind.Internal:
// a non-ctor can only be internal if it's been converted to a property
var property = ((Class) callExpr.Declaration.Namespace).Properties.First(
p => p.GetMethod == callExpr.Declaration);
return string.Format("{0}.{1}",
typePrinter.VisitDeclaration(callExpr.Declaration.Namespace),
property.Name);
return $"{typePrinter.VisitDeclaration(callExpr.Declaration.Namespace)}.{property.Name}";
default:
return expr.String;
}

3
src/Generator/Passes/CheckAmbiguousFunctions.cs

@ -62,8 +62,7 @@ namespace CppSharp.Passes @@ -62,8 +62,7 @@ namespace CppSharp.Passes
}
if (function.IsAmbiguous)
Diagnostics.Debug("Found ambiguous overload: {0}",
function.QualifiedOriginalName);
Diagnostics.Message($"Found ambiguous overload: {function.QualifiedOriginalName}");
return true;
}

20
src/Generator/Passes/CheckDuplicatedNamesPass.cs

@ -23,14 +23,12 @@ namespace CppSharp.Passes @@ -23,14 +23,12 @@ namespace CppSharp.Passes
public bool UpdateName(Declaration decl)
{
var function = decl as Function;
if (function != null)
if (decl is Function function)
{
return UpdateName(function);
}
var property = decl as Property;
var isIndexer = property != null && property.Parameters.Count > 0;
var isIndexer = decl is Property property && property.Parameters.Count > 0;
if (isIndexer)
{
return false;
@ -131,10 +129,8 @@ namespace CppSharp.Passes @@ -131,10 +129,8 @@ namespace CppSharp.Passes
private static bool CheckForSpecializations(Type leftPointee, Type rightPointee)
{
Class leftClass;
Class rightClass;
if (!leftPointee.TryGetDeclaration(out leftClass) ||
!rightPointee.TryGetDeclaration(out rightClass))
if (!leftPointee.TryGetDeclaration(out Class leftClass) ||
!rightPointee.TryGetDeclaration(out Class rightClass))
return false;
var leftSpecialization = leftClass as ClassTemplateSpecialization ??
@ -206,10 +202,7 @@ namespace CppSharp.Passes @@ -206,10 +202,7 @@ namespace CppSharp.Passes
switch (kind)
{
case GeneratorKind.C:
typePrinter = new CppTypePrinter(Context)
{
PrintFlavorKind = CppTypePrintFlavorKind.C
};
typePrinter = new CppTypePrinter(Context) { PrintFlavorKind = CppTypePrintFlavorKind.C };
break;
case GeneratorKind.CPlusPlus:
case GeneratorKind.QuickJS:
@ -310,8 +303,7 @@ namespace CppSharp.Passes @@ -310,8 +303,7 @@ namespace CppSharp.Passes
return;
var fullName = decl.QualifiedName;
var function = decl as Function;
if (function != null)
if (decl is Function function)
fullName = DeclarationName.FixSignatureForConversions(function, fullName);
// If the name is not yet on the map, then add it.

8
src/Parser/ASTConverter.cs

@ -2185,9 +2185,11 @@ namespace CppSharp @@ -2185,9 +2185,11 @@ namespace CppSharp
protected override AST.Comment VisitInlineCommandComment(InlineCommandComment comment)
{
var inlineCommandComment = new AST.InlineCommandComment();
inlineCommandComment.HasTrailingNewline = comment.HasTrailingNewline;
inlineCommandComment.CommandId = comment.CommandId;
var inlineCommandComment = new AST.InlineCommandComment
{
HasTrailingNewline = comment.HasTrailingNewline,
CommandId = comment.CommandId
};
switch (comment.CommentRenderKind)
{
case InlineCommandComment.RenderKind.RenderNormal:

Loading…
Cancel
Save