Browse Source

Added Equality operator to AST Types. This was needed because GetterSetterToPropertyPass has to match a getter return type with a setter parameter type.

pull/16/head
marcos henrich 12 years ago
parent
commit
9ba1707616
  1. 163
      src/AST/Type.cs

163
src/AST/Type.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace CppSharp.AST namespace CppSharp.AST
{ {
@ -162,6 +163,14 @@ namespace CppSharp.AST
{ {
return Type.ToString(); return Type.ToString();
} }
public override bool Equals(object obj)
{
if (!(obj is QualifiedType)) return false;
var type = (QualifiedType) obj;
return Type.Equals(type.Type) && Qualifiers.Equals(type.Qualifiers);
}
} }
/// <summary> /// <summary>
@ -184,6 +193,14 @@ namespace CppSharp.AST
{ {
return visitor.VisitTagType(this, quals); return visitor.VisitTagType(this, quals);
} }
public override bool Equals(object obj)
{
var type = obj as TagType;
if (type == null) return false;
return Declaration.Equals(type.Declaration);
}
} }
/// <summary> /// <summary>
@ -216,6 +233,18 @@ namespace CppSharp.AST
{ {
return visitor.VisitArrayType(this, quals); return visitor.VisitArrayType(this, quals);
} }
public override bool Equals(object obj)
{
var type = obj as ArrayType;
if (type == null) return false;
var equals = Type.Equals(type.Type) && SizeType.Equals(type.SizeType);
if (SizeType == ArraySize.Constant)
equals &= Size.Equals(type.Size);
return equals;
}
} }
/// <summary> /// <summary>
@ -238,6 +267,14 @@ namespace CppSharp.AST
{ {
return visitor.VisitFunctionType(this, quals); return visitor.VisitFunctionType(this, quals);
} }
public override bool Equals(object obj)
{
var type = obj as FunctionType;
if (type == null) return false;
return ReturnType.Equals(type.ReturnType) && Parameters.SequenceEqual(type.Parameters);
}
} }
/// <summary> /// <summary>
@ -281,6 +318,15 @@ namespace CppSharp.AST
{ {
return visitor.VisitPointerType(this, QualifiedPointee.Qualifiers); return visitor.VisitPointerType(this, QualifiedPointee.Qualifiers);
} }
public override bool Equals(object obj)
{
var type = obj as PointerType;
if (type == null) return false;
return QualifiedPointee.Equals(type.QualifiedPointee)
&& Modifier == type.Modifier;
}
} }
/// <summary> /// <summary>
@ -299,6 +345,14 @@ namespace CppSharp.AST
{ {
return visitor.VisitMemberPointerType(this, quals); return visitor.VisitMemberPointerType(this, quals);
} }
public override bool Equals(object obj)
{
var pointer = obj as MemberPointerType;
if (pointer == null) return false;
return Pointee.Equals(pointer.Pointee);
}
} }
/// <summary> /// <summary>
@ -317,6 +371,15 @@ namespace CppSharp.AST
{ {
return visitor.VisitTypedefType(this, quals); return visitor.VisitTypedefType(this, quals);
} }
public override bool Equals(object obj)
{
var typedef = obj as TypedefType;
if (typedef == null) return false;
var t = Declaration.Equals(typedef.Declaration);
return t;
}
} }
/// <summary> /// <summary>
@ -337,6 +400,14 @@ namespace CppSharp.AST
{ {
return visitor.VisitDecayedType(this, quals); return visitor.VisitDecayedType(this, quals);
} }
public override bool Equals(object obj)
{
var decay = obj as DecayedType;
if (decay == null) return false;
return Original.Equals(decay.Original);
}
} }
/// <summary> /// <summary>
@ -382,6 +453,28 @@ namespace CppSharp.AST
public QualifiedType Type; public QualifiedType Type;
public Declaration Declaration; public Declaration Declaration;
public long Integral; public long Integral;
public override bool Equals(object obj)
{
if (!(obj is TemplateArgument)) return false;
var arg = (TemplateArgument) obj;
if (Kind != arg.Kind) return false;
switch (Kind)
{
case ArgumentKind.Type:
return Type.Equals(arg.Type);
case ArgumentKind.Declaration:
return Declaration.Equals(arg.Declaration);
case ArgumentKind.Integral:
return Integral.Equals(arg.Integral);
case ArgumentKind.Expression:
return true;
default:
throw new Exception("Unknowed TemplateArgument Kind");
}
}
} }
/// <summary> /// <summary>
@ -405,6 +498,15 @@ namespace CppSharp.AST
{ {
return visitor.VisitTemplateSpecializationType(this, quals); return visitor.VisitTemplateSpecializationType(this, quals);
} }
public override bool Equals(object obj)
{
var type = obj as TemplateSpecializationType;
if (type == null) return false;
return Arguments.SequenceEqual(type.Arguments)
&& Template.Equals(type.Template);
}
} }
/// <summary> /// <summary>
@ -412,18 +514,21 @@ namespace CppSharp.AST
/// </summary> /// </summary>
public class TemplateParameterType : Type public class TemplateParameterType : Type
{ {
public TemplateParameterType()
{
}
public TemplateParameter Parameter; public TemplateParameter Parameter;
public Template Template;
public override T Visit<T>(ITypeVisitor<T> visitor, public override T Visit<T>(ITypeVisitor<T> visitor,
TypeQualifiers quals = new TypeQualifiers()) TypeQualifiers quals = new TypeQualifiers())
{ {
return visitor.VisitTemplateParameterType(this, quals); return visitor.VisitTemplateParameterType(this, quals);
} }
public override bool Equals(object obj)
{
var type = obj as TemplateParameterType;
if (type == null) return false;
return Parameter.Equals(type.Parameter);
}
} }
/// <summary> /// <summary>
@ -431,11 +536,6 @@ namespace CppSharp.AST
/// </summary> /// </summary>
public class TemplateParameterSubstitutionType : Type public class TemplateParameterSubstitutionType : Type
{ {
public TemplateParameterSubstitutionType()
{
}
public QualifiedType Replacement; public QualifiedType Replacement;
public override T Visit<T>(ITypeVisitor<T> visitor, public override T Visit<T>(ITypeVisitor<T> visitor,
@ -443,6 +543,14 @@ namespace CppSharp.AST
{ {
return visitor.VisitTemplateParameterSubstitutionType(this, quals); return visitor.VisitTemplateParameterSubstitutionType(this, quals);
} }
public override bool Equals(object obj)
{
var type = obj as TemplateParameterSubstitutionType;
if (type == null) return false;
return Replacement.Equals(type.Replacement);
}
} }
/// <summary> /// <summary>
@ -451,11 +559,6 @@ namespace CppSharp.AST
/// </summary> /// </summary>
public class InjectedClassNameType : Type public class InjectedClassNameType : Type
{ {
public InjectedClassNameType()
{
}
public TemplateSpecializationType TemplateSpecialization; public TemplateSpecializationType TemplateSpecialization;
public Class Class; public Class Class;
@ -464,6 +567,15 @@ namespace CppSharp.AST
{ {
return visitor.VisitInjectedClassNameType(this, quals); return visitor.VisitInjectedClassNameType(this, quals);
} }
public override bool Equals(object obj)
{
var type = obj as InjectedClassNameType;
if (type == null) return false;
return TemplateSpecialization.Equals(type.TemplateSpecialization)
&& Class.Equals(type.Class);
}
} }
/// <summary> /// <summary>
@ -471,11 +583,6 @@ namespace CppSharp.AST
/// </summary> /// </summary>
public class DependentNameType : Type public class DependentNameType : Type
{ {
public DependentNameType()
{
}
public override T Visit<T>(ITypeVisitor<T> visitor, public override T Visit<T>(ITypeVisitor<T> visitor,
TypeQualifiers quals = new TypeQualifiers()) TypeQualifiers quals = new TypeQualifiers())
{ {
@ -500,6 +607,14 @@ namespace CppSharp.AST
{ {
return visitor.VisitCILType(this, quals); return visitor.VisitCILType(this, quals);
} }
public override bool Equals(object obj)
{
var type = obj as CILType;
if (type == null) return false;
return Type == type.Type;
}
} }
#region Primitives #region Primitives
@ -567,6 +682,14 @@ namespace CppSharp.AST
{ {
return visitor.VisitBuiltinType(this, quals); return visitor.VisitBuiltinType(this, quals);
} }
public override bool Equals(object obj)
{
var type = obj as BuiltinType;
if (type == null) return false;
return Type == type.Type;
}
} }
#endregion #endregion

Loading…
Cancel
Save