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
specializations = new List<ClassTemplateSpecialization>(); specializations = new List<ClassTemplateSpecialization>();
} }
public bool HasBase public bool HasBase => Bases.Count > 0;
{
get { return Bases.Count > 0; }
}
public bool HasBaseClass public bool HasBaseClass => BaseClass != null;
{
get { return BaseClass != null; }
}
public Class BaseClass public Class BaseClass
{ {

2
src/AST/Declaration.cs

@ -79,7 +79,7 @@ namespace CppSharp.AST
/// <summary> /// <summary>
/// Whether the declaration was explicitly set to be generated via /// 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> /// </summary>
public virtual bool IsExplicitlyGenerated => public virtual bool IsExplicitlyGenerated =>
generationKind.HasValue && generationKind.Value == GenerationKind.Generate; generationKind.HasValue && generationKind.Value == GenerationKind.Generate;

5
src/AST/Enumeration.cs

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

2
src/AST/Event.cs

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

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

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

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

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

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

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

3
src/Generator/Passes/CheckIgnoredDecls.cs

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

21
src/Generator/Utils/BlockGenerator.cs

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

Loading…
Cancel
Save