Browse Source

Move helper methods in Type out from class and into extension class TypeExtensions

pull/209/head
Øystein Krog 11 years ago
parent
commit
d3e963ff19
  1. 1
      src/AST/Class.cs
  2. 2
      src/AST/Method.cs
  3. 1
      src/AST/Property.cs
  4. 154
      src/AST/Type.cs
  5. 159
      src/AST/TypeExtensions.cs
  6. 1
      src/Generator/AST/ASTRecord.cs
  7. 1
      src/Generator/Generators/CLI/CLIHeadersTemplate.cs
  8. 1
      src/Generator/Generators/CLI/CLIMarshal.cs
  9. 1
      src/Generator/Generators/CLI/CLISourcesTemplate.cs
  10. 1
      src/Generator/Generators/CLI/CLITypePrinter.cs
  11. 1
      src/Generator/Generators/CLI/CLITypeReferences.cs
  12. 1
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  13. 3
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  14. 1
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  15. 1
      src/Generator/Passes/CheckIgnoredDecls.cs
  16. 1
      src/Generator/Passes/CheckOperatorsOverloads.cs
  17. 1
      src/Generator/Passes/CheckStaticClass.cs
  18. 1
      src/Generator/Passes/CheckVirtualOverrideReturnCovariance.cs
  19. 1
      src/Generator/Passes/FunctionToInstanceMethodPass.cs
  20. 1
      src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs
  21. 1
      src/Generator/Passes/GetterSetterToPropertyPass.cs
  22. 1
      src/Generator/Passes/RenamePass.cs
  23. 1
      src/Generator/Types/ITypePrinter.cs
  24. 1
      src/Generator/Types/TypeMap.cs
  25. 1
      src/Generator/Types/Types.cs

1
src/AST/Class.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using CppSharp.AST.Extensions;
namespace CppSharp.AST namespace CppSharp.AST
{ {

2
src/AST/Method.cs

@ -1,3 +1,5 @@
using CppSharp.AST.Extensions;
namespace CppSharp.AST namespace CppSharp.AST
{ {
public enum CXXMethodKind public enum CXXMethodKind

1
src/AST/Property.cs

@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using CppSharp.AST.Extensions;
namespace CppSharp.AST namespace CppSharp.AST
{ {

154
src/AST/Type.cs

@ -13,160 +13,6 @@ namespace CppSharp.AST
public bool IsDependent { get; set; } public bool IsDependent { get; set; }
public bool IsPrimitiveType()
{
PrimitiveType type;
return IsPrimitiveType(out type);
}
public bool IsPrimitiveType(out PrimitiveType primitive)
{
var builtin = this as BuiltinType;
if (builtin != null)
{
primitive = builtin.Type;
return true;
}
primitive = PrimitiveType.Null;
return false;
}
public bool IsPrimitiveType(PrimitiveType primitive)
{
PrimitiveType type;
if (!IsPrimitiveType(out type))
return false;
return primitive == type;
}
public bool IsEnumType()
{
var tag = this as TagType;
if (tag == null)
return false;
return tag.Declaration is Enumeration;
}
public bool IsAddress()
{
return IsPointer() || IsReference();
}
public bool IsPointer()
{
var functionPointer = this as MemberPointerType;
if (functionPointer != null)
return true;
var pointer = this as PointerType;
if (pointer == null)
return false;
return pointer.Modifier == PointerType.TypeModifier.Pointer;
}
public bool IsReference()
{
var pointer = this as PointerType;
if (pointer == null)
return false;
return pointer.IsReference;
}
public bool IsPointerToPrimitiveType()
{
var ptr = this as PointerType;
if (ptr == null)
return false;
PrimitiveType primitiveType;
return ptr.Pointee.IsPrimitiveType(out primitiveType);
}
public bool IsPointerToPrimitiveType(out PrimitiveType primitive)
{
var ptr = this as PointerType;
if (ptr == null)
{
primitive = PrimitiveType.Null;
return false;
}
return ptr.Pointee.IsPrimitiveType(out primitive);
}
public bool IsPointerToPrimitiveType(PrimitiveType primitive)
{
var ptr = this as PointerType;
if (ptr == null)
return false;
return ptr.Pointee.IsPrimitiveType(primitive);
}
public bool IsPointerTo<T>(out T type) where T : Type
{
var ptr = this as PointerType;
if (ptr == null)
{
var functionPointer = this as MemberPointerType;
if (functionPointer != null)
{
type = functionPointer.Pointee as T;
return type != null;
}
type = null;
return false;
}
type = ptr.Pointee as T;
return type != null;
}
public bool IsTagDecl<T>(out T decl) where T : Declaration
{
var tag = this as TagType;
if (tag == null)
{
decl = null;
return false;
}
decl = tag.Declaration as T;
return decl != null;
}
public Type Desugar()
{
var type = this as TypedefType;
if (type != null)
{
var decl = type.Declaration.Type;
if (decl != null)
return decl.Desugar();
}
return this;
}
public Type SkipPointerRefs()
{
var type = this as PointerType;
if (type != null)
{
var pointee = type.Pointee;
if (type.IsReference())
return pointee.Desugar().SkipPointerRefs();
}
return this;
}
public abstract T Visit<T>(ITypeVisitor<T> visitor, TypeQualifiers quals public abstract T Visit<T>(ITypeVisitor<T> visitor, TypeQualifiers quals
= new TypeQualifiers()); = new TypeQualifiers());

159
src/AST/TypeExtensions.cs

@ -0,0 +1,159 @@
namespace CppSharp.AST.Extensions
{
public static class TypeExtensions
{
public static bool IsPrimitiveType(this Type t)
{
PrimitiveType type;
return t.IsPrimitiveType(out type);
}
public static bool IsPrimitiveType(this Type t, out PrimitiveType primitive)
{
var builtin = t as BuiltinType;
if (builtin != null)
{
primitive = builtin.Type;
return true;
}
primitive = PrimitiveType.Null;
return false;
}
public static bool IsPrimitiveType(this Type t, PrimitiveType primitive)
{
PrimitiveType type;
if (!t.IsPrimitiveType(out type))
return false;
return primitive == type;
}
public static bool IsEnumType(this Type t)
{
var tag = t as TagType;
if (tag == null)
return false;
return tag.Declaration is Enumeration;
}
public static bool IsAddress(this Type t)
{
return t.IsPointer() || t.IsReference();
}
public static bool IsPointer(this Type t)
{
var functionPointer = t as MemberPointerType;
if (functionPointer != null)
return true;
var pointer = t as PointerType;
if (pointer == null)
return false;
return pointer.Modifier == PointerType.TypeModifier.Pointer;
}
public static bool IsReference(this Type t)
{
var pointer = t as PointerType;
if (pointer == null)
return false;
return pointer.IsReference;
}
public static bool IsPointerToPrimitiveType(this Type t)
{
var ptr = t as PointerType;
if (ptr == null)
return false;
PrimitiveType primitiveType;
return ptr.Pointee.IsPrimitiveType(out primitiveType);
}
public static bool IsPointerToPrimitiveType(this Type t, out PrimitiveType primitive)
{
var ptr = t as PointerType;
if (ptr == null)
{
primitive = PrimitiveType.Null;
return false;
}
return ptr.Pointee.IsPrimitiveType(out primitive);
}
public static bool IsPointerToPrimitiveType(this Type t, PrimitiveType primitive)
{
var ptr = t as PointerType;
if (ptr == null)
return false;
return ptr.Pointee.IsPrimitiveType(primitive);
}
public static bool IsPointerTo<T>(this Type t, out T type) where T : Type
{
var ptr = t as PointerType;
if (ptr == null)
{
var functionPointer = t as MemberPointerType;
if (functionPointer != null)
{
type = functionPointer.Pointee as T;
return type != null;
}
type = null;
return false;
}
type = ptr.Pointee as T;
return type != null;
}
public static bool IsTagDecl<T>(this Type t, out T decl) where T : Declaration
{
var tag = t as TagType;
if (tag == null)
{
decl = null;
return false;
}
decl = tag.Declaration as T;
return decl != null;
}
public static Type Desugar(this Type t)
{
var type = t as TypedefType;
if (type != null)
{
var decl = type.Declaration.Type;
if (decl != null)
return decl.Desugar();
}
return t;
}
public static Type SkipPointerRefs(this Type t)
{
var type = t as PointerType;
if (type != null)
{
var pointee = type.Pointee;
if (type.IsReference())
return pointee.Desugar().SkipPointerRefs();
}
return t;
}
}
}

1
src/Generator/AST/ASTRecord.cs

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
using Type = CppSharp.AST.Type; using Type = CppSharp.AST.Type;
namespace CppSharp.Generators.AST namespace CppSharp.Generators.AST

1
src/Generator/Generators/CLI/CLIHeadersTemplate.cs

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators.CSharp; using CppSharp.Generators.CSharp;
using CppSharp.Types; using CppSharp.Types;

1
src/Generator/Generators/CLI/CLIMarshal.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Text; using System.Text;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Types; using CppSharp.Types;
using Delegate = CppSharp.AST.Delegate; using Delegate = CppSharp.AST.Delegate;
using Type = CppSharp.AST.Type; using Type = CppSharp.AST.Type;

1
src/Generator/Generators/CLI/CLISourcesTemplate.cs

@ -4,6 +4,7 @@ using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators.CSharp; using CppSharp.Generators.CSharp;
using CppSharp.Types; using CppSharp.Types;
using Type = CppSharp.AST.Type; using Type = CppSharp.AST.Type;

1
src/Generator/Generators/CLI/CLITypePrinter.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Types; using CppSharp.Types;
using Type = CppSharp.AST.Type; using Type = CppSharp.AST.Type;

1
src/Generator/Generators/CLI/CLITypeReferences.cs

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators.AST; using CppSharp.Generators.AST;
using CppSharp.Types; using CppSharp.Types;

1
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Types; using CppSharp.Types;
using Type = CppSharp.AST.Type; using Type = CppSharp.AST.Type;

3
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -6,7 +6,8 @@ using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Web.Util; using System.Web.Util;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Types; using CppSharp.Types;
using CppSharp.Utils; using CppSharp.Utils;
using Attribute = CppSharp.AST.Attribute; using Attribute = CppSharp.AST.Attribute;

1
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Types; using CppSharp.Types;
using Type = CppSharp.AST.Type; using Type = CppSharp.AST.Type;

1
src/Generator/Passes/CheckIgnoredDecls.cs

@ -1,4 +1,5 @@
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Types; using CppSharp.Types;
namespace CppSharp.Passes namespace CppSharp.Passes

1
src/Generator/Passes/CheckOperatorsOverloads.cs

@ -1,5 +1,6 @@
using System.Linq; using System.Linq;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators; using CppSharp.Generators;
namespace CppSharp.Passes namespace CppSharp.Passes

1
src/Generator/Passes/CheckStaticClass.cs

@ -1,5 +1,6 @@
using System.Linq; using System.Linq;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
namespace CppSharp.Passes namespace CppSharp.Passes
{ {

1
src/Generator/Passes/CheckVirtualOverrideReturnCovariance.cs

@ -1,4 +1,5 @@
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
namespace CppSharp.Passes namespace CppSharp.Passes
{ {

1
src/Generator/Passes/FunctionToInstanceMethodPass.cs

@ -1,5 +1,6 @@
using System.Linq; using System.Linq;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators; using CppSharp.Generators;
namespace CppSharp.Passes namespace CppSharp.Passes

1
src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs

@ -6,6 +6,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
using Type = CppSharp.AST.Type; using Type = CppSharp.AST.Type;
namespace CppSharp.Passes namespace CppSharp.Passes

1
src/Generator/Passes/GetterSetterToPropertyPass.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Linq; using System.Linq;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
namespace CppSharp.Passes namespace CppSharp.Passes
{ {

1
src/Generator/Passes/RenamePass.cs

@ -4,6 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
namespace CppSharp.Passes namespace CppSharp.Passes
{ {

1
src/Generator/Types/ITypePrinter.cs

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
namespace CppSharp.Types namespace CppSharp.Types
{ {

1
src/Generator/Types/TypeMap.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators; using CppSharp.Generators;
using CppSharp.Generators.AST; using CppSharp.Generators.AST;
using CppSharp.Generators.CLI; using CppSharp.Generators.CLI;

1
src/Generator/Types/Types.cs

@ -1,4 +1,5 @@
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Types; using CppSharp.Types;
namespace CppSharp namespace CppSharp

Loading…
Cancel
Save