Browse Source

Added support for logical names to the declarations.

While at it, I also refactored the logic of Qualified name properties. Now instead of recursion it will gather all the used namespaces and filter them.
pull/222/head
triton 11 years ago
parent
commit
440632896f
  1. 95
      src/AST/Declaration.cs
  2. 20
      src/AST/Namespace.cs

95
src/AST/Declaration.cs

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace CppSharp.AST
{
@ -64,14 +65,11 @@ namespace CppSharp.AST @@ -64,14 +65,11 @@ namespace CppSharp.AST
}
}
private string name;
public virtual string OriginalName
{
get { return originalName; }
set { originalName = value; }
}
public virtual string OriginalName { get; set; }
// Name of the declaration.
private string name;
public virtual string Name
{
get { return name; }
@ -83,14 +81,64 @@ namespace CppSharp.AST @@ -83,14 +81,64 @@ namespace CppSharp.AST
}
}
/// <summary>
/// The effective name of a declaration is the logical name
/// for the declaration. We need this to make the distiction between
/// the real and the "effective" name of the declaration to properly
/// support things like inline namespaces when handling type maps.
/// </summary>
public virtual string LogicalName
{
get { return Name; }
}
/// <summary>
/// The effective original name of a declaration is the logical
/// original name for the declaration.
/// </summary>
public virtual string LogicalOriginalName
{
get { return OriginalName; }
}
private string GetQualifiedName(Func<Declaration, string> getName,
Func<Declaration, DeclarationContext> getNamespace)
{
if (Namespace == null)
return getName(this);
if (Namespace.IsRoot)
return getName(this);
var namespaces = GatherNamespaces(getNamespace(this));
namespaces.Reverse();
var names = namespaces.Select(getName).ToList();
names.Add(getName(this));
names = names.Where(s => !string.IsNullOrWhiteSpace(s)).ToList();
return string.Join("::", names);
}
private List<Declaration> GatherNamespaces(DeclarationContext @namespace)
{
var namespaces = new List<Declaration>();
var currentNamespace = @namespace;
while (currentNamespace != null)
{
namespaces.Add(currentNamespace);
currentNamespace = currentNamespace.Namespace;
}
return namespaces;
}
public string QualifiedName
{
get
{
if (Namespace == null)
return Name;
return Namespace.IsRoot ? Name
: string.Format("{0}::{1}", Namespace.QualifiedName, Name);
return GetQualifiedName(decl => decl.Name, decl => decl.Namespace);
}
}
@ -98,10 +146,26 @@ namespace CppSharp.AST @@ -98,10 +146,26 @@ namespace CppSharp.AST
{
get
{
if (OriginalNamespace == null)
return OriginalName;
return OriginalNamespace.IsRoot ? OriginalName
: string.Format("{0}::{1}", OriginalNamespace.QualifiedOriginalName, OriginalName);
return GetQualifiedName(
decl => decl.OriginalName, decl => decl.OriginalNamespace);
}
}
public string QualifiedLogicalName
{
get
{
return GetQualifiedName(
decl => decl.LogicalName, decl => decl.Namespace);
}
}
public string QualifiedLogicalOriginalName
{
get
{
return GetQualifiedName(
decl => decl.LogicalOriginalName, decl => decl.OriginalNamespace);
}
}
@ -194,7 +258,6 @@ namespace CppSharp.AST @@ -194,7 +258,6 @@ namespace CppSharp.AST
// Pointer to the original declaration from Clang.
public IntPtr OriginalPtr;
private string originalName;
public List<Attribute> Attributes { get; private set; }
@ -217,7 +280,7 @@ namespace CppSharp.AST @@ -217,7 +280,7 @@ namespace CppSharp.AST
: this()
{
Namespace = declaration.Namespace;
originalName = declaration.OriginalName;
OriginalName = declaration.OriginalName;
name = declaration.Name;
Comment = declaration.Comment;
IgnoreFlags = declaration.IgnoreFlags;

20
src/AST/Namespace.cs

@ -27,6 +27,16 @@ namespace CppSharp.AST @@ -27,6 +27,16 @@ namespace CppSharp.AST
// 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; }
}
protected DeclarationContext()
{
Namespaces = new List<Namespace>();
@ -312,6 +322,16 @@ namespace CppSharp.AST @@ -312,6 +322,16 @@ namespace CppSharp.AST
/// </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 bool IsInline;
public override T Visit<T>(IDeclVisitor<T> visitor)

Loading…
Cancel
Save