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

39
src/Generator/Passes/CheckIgnoredDecls.cs

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

23
src/Generator/Types/Types.cs

@ -4,29 +4,6 @@ using CppSharp.Types;
namespace CppSharp 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> /// <summary>
/// This type checker is used to check if a type is ignored. /// This type checker is used to check if a type is ignored.
/// </summary> /// </summary>

Loading…
Cancel
Save