|
|
|
@ -25,16 +25,16 @@ namespace CppSharp.AST
@@ -25,16 +25,16 @@ namespace CppSharp.AST
|
|
|
|
|
public Dictionary<ulong, Declaration> Anonymous; |
|
|
|
|
|
|
|
|
|
// True if the context is inside an extern "C" context.
|
|
|
|
|
public bool IsExternCContext; |
|
|
|
|
|
|
|
|
|
public override string LogicalName |
|
|
|
|
{ |
|
|
|
|
get { return IsAnonymous ? "<anonymous>" : base.Name; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override string LogicalOriginalName |
|
|
|
|
{ |
|
|
|
|
get { return IsAnonymous ? "<anonymous>" : base.OriginalName; } |
|
|
|
|
public bool IsExternCContext; |
|
|
|
|
|
|
|
|
|
public override string LogicalName |
|
|
|
|
{ |
|
|
|
|
get { return IsAnonymous ? "<anonymous>" : base.Name; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override string LogicalOriginalName |
|
|
|
|
{ |
|
|
|
|
get { return IsAnonymous ? "<anonymous>" : base.OriginalName; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected DeclarationContext() |
|
|
|
@ -71,25 +71,25 @@ namespace CppSharp.AST
@@ -71,25 +71,25 @@ namespace CppSharp.AST
|
|
|
|
|
public Declaration FindAnonymous(ulong key) |
|
|
|
|
{ |
|
|
|
|
return Anonymous.ContainsKey(key) ? Anonymous[key] : null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public DeclarationContext FindDeclaration(IEnumerable<string> declarations) |
|
|
|
|
{ |
|
|
|
|
DeclarationContext currentDeclaration = this; |
|
|
|
|
|
|
|
|
|
foreach (var declaration in declarations) |
|
|
|
|
{ |
|
|
|
|
var subDeclaration = currentDeclaration.Namespaces |
|
|
|
|
.Concat<DeclarationContext>(currentDeclaration.Classes) |
|
|
|
|
.FirstOrDefault(e => e.Name.Equals(declaration)); |
|
|
|
|
|
|
|
|
|
if (subDeclaration == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
currentDeclaration = subDeclaration; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return currentDeclaration as DeclarationContext; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public DeclarationContext FindDeclaration(IEnumerable<string> declarations) |
|
|
|
|
{ |
|
|
|
|
DeclarationContext currentDeclaration = this; |
|
|
|
|
|
|
|
|
|
foreach (var declaration in declarations) |
|
|
|
|
{ |
|
|
|
|
var subDeclaration = currentDeclaration.Namespaces |
|
|
|
|
.Concat<DeclarationContext>(currentDeclaration.Classes) |
|
|
|
|
.FirstOrDefault(e => e.Name.Equals(declaration)); |
|
|
|
|
|
|
|
|
|
if (subDeclaration == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
currentDeclaration = subDeclaration; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return currentDeclaration as DeclarationContext; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Namespace FindNamespace(string name) |
|
|
|
@ -165,34 +165,34 @@ namespace CppSharp.AST
@@ -165,34 +165,34 @@ namespace CppSharp.AST
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Function FindFunction(string name, bool createDecl = false) |
|
|
|
|
{ |
|
|
|
|
if (string.IsNullOrEmpty(name)) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
var entries = name.Split(new string[] { "::" }, |
|
|
|
|
StringSplitOptions.RemoveEmptyEntries).ToList(); |
|
|
|
|
|
|
|
|
|
if (entries.Count <= 1) |
|
|
|
|
{ |
|
|
|
|
var function = Functions.Find(e => e.Name.Equals(name)); |
|
|
|
|
|
|
|
|
|
if (function == null && createDecl) |
|
|
|
|
{ |
|
|
|
|
function = new Function() { Name = name, Namespace = this }; |
|
|
|
|
Functions.Add(function); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return function; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var funcName = entries[entries.Count - 1]; |
|
|
|
|
var namespaces = entries.Take(entries.Count - 1); |
|
|
|
|
|
|
|
|
|
var @namespace = FindNamespace(namespaces); |
|
|
|
|
if (@namespace == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
return @namespace.FindFunction(funcName, createDecl); |
|
|
|
|
{ |
|
|
|
|
if (string.IsNullOrEmpty(name)) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
var entries = name.Split(new string[] { "::" }, |
|
|
|
|
StringSplitOptions.RemoveEmptyEntries).ToList(); |
|
|
|
|
|
|
|
|
|
if (entries.Count <= 1) |
|
|
|
|
{ |
|
|
|
|
var function = Functions.Find(e => e.Name.Equals(name)); |
|
|
|
|
|
|
|
|
|
if (function == null && createDecl) |
|
|
|
|
{ |
|
|
|
|
function = new Function() { Name = name, Namespace = this }; |
|
|
|
|
Functions.Add(function); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return function; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var funcName = entries[entries.Count - 1]; |
|
|
|
|
var namespaces = entries.Take(entries.Count - 1); |
|
|
|
|
|
|
|
|
|
var @namespace = FindNamespace(namespaces); |
|
|
|
|
if (@namespace == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
return @namespace.FindFunction(funcName, createDecl); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Class CreateClass(string name, bool isComplete) |
|
|
|
@ -229,7 +229,7 @@ namespace CppSharp.AST
@@ -229,7 +229,7 @@ namespace CppSharp.AST
|
|
|
|
|
|
|
|
|
|
DeclarationContext declContext = FindDeclaration(namespaces); |
|
|
|
|
if (declContext == null) |
|
|
|
|
{ |
|
|
|
|
{ |
|
|
|
|
declContext = FindClass(entries[0]); |
|
|
|
|
if (declContext == null) |
|
|
|
|
return null; |
|
|
|
@ -320,13 +320,13 @@ namespace CppSharp.AST
@@ -320,13 +320,13 @@ namespace CppSharp.AST
|
|
|
|
|
return Enums.Find(e => e.ItemsByName.ContainsKey(name)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public IEnumerable<Function> FindOperator(CXXOperatorKind kind) |
|
|
|
|
public virtual IEnumerable<Function> FindOperator(CXXOperatorKind kind) |
|
|
|
|
{ |
|
|
|
|
return Functions.Where(fn => fn.OperatorKind == kind); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public virtual IEnumerable<Function> GetOverloads(Function function) |
|
|
|
|
{ |
|
|
|
|
public virtual IEnumerable<Function> GetOverloads(Function function) |
|
|
|
|
{ |
|
|
|
|
if (function.IsOperator) |
|
|
|
|
return FindOperator(function.OperatorKind); |
|
|
|
|
return Functions.Where(fn => fn.Name == function.Name); |
|
|
|
@ -335,17 +335,17 @@ namespace CppSharp.AST
@@ -335,17 +335,17 @@ namespace CppSharp.AST
|
|
|
|
|
public bool HasDeclarations |
|
|
|
|
{ |
|
|
|
|
get |
|
|
|
|
{ |
|
|
|
|
{ |
|
|
|
|
Predicate<Declaration> pred = (t => t.IsGenerated); |
|
|
|
|
return Enums.Exists(pred) || HasFunctions || Typedefs.Exists(pred) |
|
|
|
|
|| Classes.Any() || Namespaces.Exists(n => n.HasDeclarations); |
|
|
|
|
|| Classes.Any() || Namespaces.Exists(n => n.HasDeclarations); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool HasFunctions |
|
|
|
|
{ |
|
|
|
|
get |
|
|
|
|
{ |
|
|
|
|
{ |
|
|
|
|
Predicate<Declaration> pred = (t => t.IsGenerated); |
|
|
|
|
return Functions.Exists(pred) || Namespaces.Exists(n => n.HasFunctions); |
|
|
|
|
} |
|
|
|
@ -357,18 +357,18 @@ namespace CppSharp.AST
@@ -357,18 +357,18 @@ namespace CppSharp.AST
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents a C++ namespace.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Namespace : DeclarationContext |
|
|
|
|
{ |
|
|
|
|
public override string LogicalName |
|
|
|
|
{ |
|
|
|
|
get { return IsInline ? string.Empty : base.Name; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override string LogicalOriginalName |
|
|
|
|
{ |
|
|
|
|
get { return IsInline ? string.Empty : base.OriginalName; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public class Namespace : DeclarationContext |
|
|
|
|
{ |
|
|
|
|
public override string LogicalName |
|
|
|
|
{ |
|
|
|
|
get { return IsInline ? string.Empty : base.Name; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override string LogicalOriginalName |
|
|
|
|
{ |
|
|
|
|
get { return IsInline ? string.Empty : base.OriginalName; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool IsInline; |
|
|
|
|
|
|
|
|
|
public override T Visit<T>(IDeclVisitor<T> visitor) |
|
|
|
|