Browse Source

Minor code cleanups.

instantiate-types-nested-templates
Joao Matos 5 years ago committed by João Matos
parent
commit
d6dd93d2f8
  1. 10
      src/AST/Class.cs
  2. 2
      src/AST/Declaration.cs
  3. 5
      src/AST/Enumeration.cs
  4. 2
      src/AST/Event.cs
  5. 2
      src/Generator/Generators/C/CppGenerator.cs
  6. 4
      src/Generator/Generators/C/CppHeaders.cs
  7. 5
      src/Generator/Generators/CLI/CLITypeReferences.cs
  8. 3
      src/Generator/Passes/CheckIgnoredDecls.cs
  9. 21
      src/Generator/Utils/BlockGenerator.cs

10
src/AST/Class.cs

@ -145,15 +145,9 @@ namespace CppSharp.AST @@ -145,15 +145,9 @@ namespace CppSharp.AST
specializations = new List<ClassTemplateSpecialization>();
}
public bool HasBase
{
get { return Bases.Count > 0; }
}
public bool HasBase => Bases.Count > 0;
public bool HasBaseClass
{
get { return BaseClass != null; }
}
public bool HasBaseClass => BaseClass != null;
public Class BaseClass
{

2
src/AST/Declaration.cs

@ -79,7 +79,7 @@ namespace CppSharp.AST @@ -79,7 +79,7 @@ namespace CppSharp.AST
/// <summary>
/// Whether the declaration was explicitly set to be generated via
/// the GenerationKind propery as opposed to the default generated state.
/// the GenerationKind property as opposed to the default generated state.
/// </summary>
public virtual bool IsExplicitlyGenerated =>
generationKind.HasValue && generationKind.Value == GenerationKind.Generate;

5
src/AST/Enumeration.cs

@ -29,10 +29,9 @@ namespace CppSharp.AST @@ -29,10 +29,9 @@ namespace CppSharp.AST
{
get
{
if (Expression == null)
{
if (string.IsNullOrEmpty(Expression))
return false;
}
return Expression.Contains("0x") || Expression.Contains("0X");
}
}

2
src/AST/Event.cs

@ -9,7 +9,7 @@ namespace CppSharp.AST @@ -9,7 +9,7 @@ namespace CppSharp.AST
return visitor.VisitEvent(this);
}
public Type Type { get { return QualifiedType.Type; } }
public Type Type => QualifiedType.Type;
public QualifiedType QualifiedType { get; set; }
public List<Parameter> Parameters { get; } = new List<Parameter>();

2
src/Generator/Generators/C/CppGenerator.cs

@ -37,7 +37,7 @@ namespace CppSharp.Generators.Cpp @@ -37,7 +37,7 @@ namespace CppSharp.Generators.Cpp
return true;
}
public static bool ShouldGenerateClassNativeField(Class @class)
public static bool ShouldGenerateClassNativeInstanceField(Class @class)
{
if (@class.IsStatic)
return false;

4
src/Generator/Generators/C/CppHeaders.cs

@ -326,7 +326,7 @@ namespace CppSharp.Generators.Cpp @@ -326,7 +326,7 @@ namespace CppSharp.Generators.Cpp
VisitDeclContext(@class);
Unindent();
if (CppGenerator.ShouldGenerateClassNativeField(@class))
if (CppGenerator.ShouldGenerateClassNativeInstanceField(@class))
GenerateClassNativeField(@class);
GenerateClassConstructors(@class);
@ -339,7 +339,7 @@ namespace CppSharp.Generators.Cpp @@ -339,7 +339,7 @@ namespace CppSharp.Generators.Cpp
GenerateClassVariables(@class);
if (CppGenerator.ShouldGenerateClassNativeField(@class))
if (CppGenerator.ShouldGenerateClassNativeInstanceField(@class))
{
PushBlock(BlockKind.AccessSpecifier);
WriteLine("protected:");

5
src/Generator/Generators/CLI/CLITypeReferences.cs

@ -31,10 +31,7 @@ namespace CppSharp.Generators.CLI @@ -31,10 +31,7 @@ namespace CppSharp.Generators.CLI
private TranslationUnit TranslationUnit;
private Dictionary<Declaration, CLITypeReference> typeReferences;
public IEnumerable<CLITypeReference> TypeReferences
{
get { return typeReferences.Values; }
}
public IEnumerable<CLITypeReference> TypeReferences => typeReferences.Values;
public HashSet<Declaration> GeneratedDeclarations;

3
src/Generator/Passes/CheckIgnoredDecls.cs

@ -568,8 +568,7 @@ namespace CppSharp.Passes @@ -568,8 +568,7 @@ namespace CppSharp.Passes
if (parameter.Type.Desugar().IsPrimitiveType(PrimitiveType.Null))
return true;
TypeMap typeMap;
if (TypeMaps.FindTypeMap(parameter.Type, out typeMap))
if (TypeMaps.FindTypeMap(parameter.Type, out var typeMap))
return typeMap.IsIgnored;
}

21
src/Generator/Utils/BlockGenerator.cs

@ -172,10 +172,7 @@ namespace CppSharp @@ -172,10 +172,7 @@ namespace CppSharp
{
get
{
if (Blocks.Any(block => !block.IsEmpty))
return false;
return string.IsNullOrEmpty(Text.ToString());
return Blocks.All(block => block.IsEmpty) && string.IsNullOrEmpty(Text.ToString());
}
}
@ -275,10 +272,18 @@ namespace CppSharp @@ -275,10 +272,18 @@ namespace CppSharp
public void PushBlock(BlockKind kind = BlockKind.Unknown, object obj = null)
{
var block = new Block { Kind = kind, Object = obj };
block.Text.CurrentIndentation = CurrentIndentation;
block.Text.IsStartOfLine = ActiveBlock.Text.IsStartOfLine;
block.Text.NeedsNewLine = ActiveBlock.Text.NeedsNewLine;
var block = new Block
{
Kind = kind,
Object = obj,
Text =
{
CurrentIndentation = CurrentIndentation,
IsStartOfLine = ActiveBlock.Text.IsStartOfLine,
NeedsNewLine = ActiveBlock.Text.NeedsNewLine
}
};
PushBlock(block);
}

Loading…
Cancel
Save