Browse Source

Reworked the declaration ignore system so we can still process declarations as part of type maps even if they do not have mirror classes generated.

pull/1/head
triton 13 years ago
parent
commit
e9129ed27f
  1. 69
      src/Bridge/Declaration.cs
  2. 13
      src/Bridge/Library.cs
  3. 19
      src/Bridge/Namespace.cs
  4. 2
      src/Generator/Driver.cs
  5. 4
      src/Generator/Library.cs
  6. 4
      src/Generator/Passes/CleanInvalidDeclNamesPass.cs

69
src/Bridge/Declaration.cs

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using Cxxi; using Cxxi;
namespace Cxxi namespace Cxxi
@ -14,6 +15,15 @@ namespace Cxxi
QualifiedType QualifiedType { get; } QualifiedType QualifiedType { get; }
} }
[Flags]
public enum IgnoreFlags
{
None = 0,
Generation = 1 << 0,
Processing = 1 << 1,
Explicit = 1 << 2
}
/// <summary> /// <summary>
/// Represents a C++ declaration. /// Represents a C++ declaration.
/// </summary> /// </summary>
@ -51,17 +61,64 @@ namespace Cxxi
// Doxygen-style brief comment. // Doxygen-style brief comment.
public string BriefComment; public string BriefComment;
// Whether the declaration should be ignored. // Keeps flags to know the type of ignore.
public virtual bool Ignore public IgnoreFlags IgnoreFlags { get; set; }
// Whether the declaration should be generated.
public virtual bool IsGenerated
{ {
get get
{ {
return ExplicityIgnored || Namespace.Ignore; return !IgnoreFlags.HasFlag(IgnoreFlags.Generation) ||
Namespace.IsGenerated;
}
set
{
if (value)
IgnoreFlags |= IgnoreFlags.Generation;
else
IgnoreFlags &= ~IgnoreFlags.Generation;
}
}
// Whether the declaration should be processed.
public virtual bool IsProcessed
{
get
{
return !IgnoreFlags.HasFlag(IgnoreFlags.Processing) ||
Namespace.IsProcessed;
}
set
{
if (value)
IgnoreFlags |= IgnoreFlags.Processing;
else
IgnoreFlags &= ~IgnoreFlags.Processing;
} }
} }
// Whether the declaration was explicitly ignored. // Whether the declaration was explicitly ignored.
public bool ExplicityIgnored; public bool ExplicityIgnored
{
get { return IgnoreFlags.HasFlag(IgnoreFlags.Explicit); }
set
{
if (value)
IgnoreFlags |= IgnoreFlags.Explicit;
else
IgnoreFlags &= ~IgnoreFlags.Explicit;
}
}
// Whether the declaration should be ignored.
public bool Ignore
{
get { return IgnoreFlags != IgnoreFlags.None; }
}
// Contains debug text about the declaration. // Contains debug text about the declaration.
public string DebugText; public string DebugText;
@ -77,11 +134,13 @@ namespace Cxxi
protected Declaration() protected Declaration()
{ {
IgnoreFlags = IgnoreFlags.None;
} }
protected Declaration(string name) protected Declaration(string name)
{ {
Name = name; Name = name;
IgnoreFlags = IgnoreFlags.None;
} }
public override string ToString() public override string ToString()

13
src/Bridge/Library.cs

@ -1,7 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
namespace Cxxi namespace Cxxi
{ {
@ -33,10 +32,16 @@ namespace Cxxi
/// Contains the macros present in the unit. /// Contains the macros present in the unit.
public List<MacroDefinition> Macros; public List<MacroDefinition> Macros;
/// If the module should be ignored. // Whether the unit should be generated.
public override bool Ignore public override bool IsGenerated
{ {
get { return ExplicityIgnored; } get { return !IgnoreFlags.HasFlag(IgnoreFlags.Generation); }
}
// Whether the unit should be processed.
public override bool IsProcessed
{
get { return !IgnoreFlags.HasFlag(IgnoreFlags.Processing); }
} }
public bool IsSystemHeader { get; set; } public bool IsSystemHeader { get; set; }

19
src/Bridge/Namespace.cs

@ -19,7 +19,6 @@ namespace Cxxi
public List<Template> Templates; public List<Template> Templates;
public List<TypedefDecl> Typedefs; public List<TypedefDecl> Typedefs;
// Translation unit the declaration is contained in.
public TranslationUnit TranslationUnit public TranslationUnit TranslationUnit
{ {
get get
@ -31,10 +30,22 @@ namespace Cxxi
} }
} }
/// If the namespace should be ignored. public override bool IsGenerated
public override bool Ignore
{ {
get { return ExplicityIgnored || Parent.Ignore; } get
{
return !IgnoreFlags.HasFlag(IgnoreFlags.Generation) ||
Parent.IsGenerated;
}
}
public override bool IsProcessed
{
get
{
return !IgnoreFlags.HasFlag(IgnoreFlags.Processing) ||
Parent.IsProcessed;
}
} }
public Namespace() public Namespace()

2
src/Generator/Driver.cs

@ -127,7 +127,7 @@ namespace Cxxi
// Process everything in the global namespace for now. // Process everything in the global namespace for now.
foreach (var unit in Library.TranslationUnits) foreach (var unit in Library.TranslationUnits)
{ {
if (unit.ExplicityIgnored || !unit.HasDeclarations) if (unit.Ignore || !unit.HasDeclarations)
continue; continue;
if (unit.IsSystemHeader) if (unit.IsSystemHeader)

4
src/Generator/Library.cs

@ -276,7 +276,11 @@ namespace Cxxi
m => Regex.Match(m.FilePath, pattern).Success); m => Regex.Match(m.FilePath, pattern).Success);
foreach (var module in modules) foreach (var module in modules)
{
module.IsGenerated = false;
module.IsProcessed = true;
module.ExplicityIgnored = true; module.ExplicityIgnored = true;
}
} }
#endregion #endregion

4
src/Generator/Passes/CleanInvalidDeclNamesPass.cs

@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using Cxxi.Types;
namespace Cxxi.Passes namespace Cxxi.Passes
{ {
@ -18,7 +16,7 @@ namespace Cxxi.Passes
public override bool ProcessUnit(TranslationUnit unit) public override bool ProcessUnit(TranslationUnit unit)
{ {
if (unit.ExplicityIgnored) if (unit.Ignore)
return false; return false;
if (unit.IsSystemHeader) if (unit.IsSystemHeader)

Loading…
Cancel
Save