Browse Source

Merge pull request #510 from ddobrev/master

Optimised the passes for time
pull/506/merge
João Matos 11 years ago
parent
commit
0af85902be
  1. 20
      src/AST/TranslationUnit.cs
  2. 39
      src/Generator/Passes/CheckIgnoredDecls.cs
  3. 23
      src/Generator/Types/Types.cs

20
src/AST/TranslationUnit.cs

@ -31,28 +31,39 @@ namespace CppSharp.AST @@ -31,28 +31,39 @@ namespace CppSharp.AST
/// Contains the path to the file.
public string FilePath;
private string fileName;
private string fileNameWithoutExtension;
/// Contains the name of the file.
public string FileName
{
get { return Path.GetFileName(FilePath); }
get { return fileName ?? (fileName = Path.GetFileName(FilePath)); }
}
/// Contains the name of the module.
public string FileNameWithoutExtension
{
get { return Path.GetFileNameWithoutExtension(FileName); }
get
{
return fileNameWithoutExtension ??
(fileNameWithoutExtension = Path.GetFileNameWithoutExtension(FileName));
}
}
/// Contains the include path.
public string IncludePath;
private string fileRelativeDirectory;
private string fileRelativePath;
public string FileRelativeDirectory
{
get
{
if (fileRelativeDirectory != null) return fileRelativeDirectory;
var path = IncludePath.Replace('\\', '/');
var index = path.LastIndexOf('/');
return path.Substring(0, index);
return fileRelativeDirectory = path.Substring(0, index);
}
}
@ -60,7 +71,8 @@ namespace CppSharp.AST @@ -60,7 +71,8 @@ namespace CppSharp.AST
{
get
{
return Path.Combine(FileRelativeDirectory, FileName);
return fileRelativePath ??
(fileRelativePath = Path.Combine(FileRelativeDirectory, FileName));
}
}
}

39
src/Generator/Passes/CheckIgnoredDecls.cs

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
using System;
using CppSharp.AST;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Types;
@ -322,7 +321,7 @@ namespace CppSharp.Passes @@ -322,7 +321,7 @@ namespace CppSharp.Passes
/// reasons: incomplete definitions, being explicitly ignored, or also
/// by being a type we do not know how to handle.
/// </remarks>
bool HasInvalidType(AST.Type type, out string msg)
private bool HasInvalidType(Type type, out string msg)
{
if (type == null)
{
@ -356,7 +355,7 @@ namespace CppSharp.Passes @@ -356,7 +355,7 @@ namespace CppSharp.Passes
return false;
}
bool HasInvalidDecl(Declaration decl, out string msg)
private bool HasInvalidDecl(Declaration decl, out string msg)
{
if (decl == null)
{
@ -364,7 +363,7 @@ namespace CppSharp.Passes @@ -364,7 +363,7 @@ namespace CppSharp.Passes
return true;
}
if (!IsDeclComplete(decl))
if (decl.IsIncomplete)
{
msg = "incomplete";
return true;
@ -380,19 +379,21 @@ namespace CppSharp.Passes @@ -380,19 +379,21 @@ namespace CppSharp.Passes
return false;
}
static bool IsTypeComplete(AST.Type type)
private static bool IsTypeComplete(Type type)
{
var checker = new TypeCompletionChecker();
return type.Visit(checker);
}
var desugared = type.Desugar();
var finalType = (desugared.GetFinalPointee() ?? desugared).Desugar();
static bool IsDeclComplete(Declaration decl)
{
var checker = new TypeCompletionChecker();
return decl.Visit(checker);
var templateSpecializationType = finalType as TemplateSpecializationType;
if (templateSpecializationType != null)
finalType = templateSpecializationType.Desugared;
Declaration decl;
if (!finalType.TryGetDeclaration(out decl)) return true;
return !decl.IsIncomplete;
}
bool IsTypeIgnored(AST.Type type)
private bool IsTypeIgnored(Type type)
{
var checker = new TypeIgnoreChecker(Driver.TypeDatabase);
type.Visit(checker);
@ -400,12 +401,14 @@ namespace CppSharp.Passes @@ -400,12 +401,14 @@ namespace CppSharp.Passes
return checker.IsIgnored;
}
bool IsDeclIgnored(Declaration decl)
private bool IsDeclIgnored(Declaration decl)
{
var checker = new TypeIgnoreChecker(Driver.TypeDatabase);
decl.Visit(checker);
var parameter = decl as Parameter;
if (parameter != null && parameter.Type.Desugar().IsPrimitiveType(PrimitiveType.Null))
return true;
return checker.IsIgnored;
TypeMap typeMap;
return Driver.TypeDatabase.FindTypeMap(decl, out typeMap) ? typeMap.IsIgnored : decl.Ignore;
}
#endregion

23
src/Generator/Types/Types.cs

@ -4,29 +4,6 @@ using CppSharp.Types; @@ -4,29 +4,6 @@ using CppSharp.Types;
namespace CppSharp
{
/// <summary>
/// This type checker is used to check if a type is complete.
/// </summary>
public class TypeCompletionChecker : AstVisitor
{
public TypeCompletionChecker()
{
Options.VisitClassBases = false;
Options.VisitTemplateArguments = false;
}
public override bool VisitDeclaration(Declaration decl)
{
if (AlreadyVisited(decl))
return false;
if (decl.CompleteDeclaration != null)
return true;
return !decl.IsIncomplete;
}
}
/// <summary>
/// This type checker is used to check if a type is ignored.
/// </summary>

Loading…
Cancel
Save