diff --git a/src/AST/Type.cs b/src/AST/Type.cs index 18b5b2f9..bcf2b258 100644 --- a/src/AST/Type.cs +++ b/src/AST/Type.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; namespace CppSharp.AST { @@ -162,6 +163,14 @@ namespace CppSharp.AST { 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); + } } /// @@ -184,6 +193,14 @@ namespace CppSharp.AST { 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); + } } /// @@ -216,6 +233,18 @@ namespace CppSharp.AST { 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; + } } /// @@ -238,6 +267,14 @@ namespace CppSharp.AST { 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); + } } /// @@ -281,6 +318,15 @@ namespace CppSharp.AST { 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; + } } /// @@ -299,6 +345,14 @@ namespace CppSharp.AST { 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); + } } /// @@ -317,6 +371,15 @@ namespace CppSharp.AST { 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; + } } /// @@ -337,6 +400,14 @@ namespace CppSharp.AST { 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); + } } /// @@ -382,6 +453,28 @@ namespace CppSharp.AST public QualifiedType Type; public Declaration Declaration; 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"); + } + } } /// @@ -405,6 +498,15 @@ namespace CppSharp.AST { 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); + } } /// @@ -412,18 +514,21 @@ namespace CppSharp.AST /// public class TemplateParameterType : Type { - public TemplateParameterType() - { - } - public TemplateParameter Parameter; - public Template Template; public override T Visit(ITypeVisitor visitor, TypeQualifiers quals = new TypeQualifiers()) { 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); + } } /// @@ -431,11 +536,6 @@ namespace CppSharp.AST /// public class TemplateParameterSubstitutionType : Type { - public TemplateParameterSubstitutionType() - { - - } - public QualifiedType Replacement; public override T Visit(ITypeVisitor visitor, @@ -443,6 +543,14 @@ namespace CppSharp.AST { 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); + } } /// @@ -451,11 +559,6 @@ namespace CppSharp.AST /// public class InjectedClassNameType : Type { - public InjectedClassNameType() - { - - } - public TemplateSpecializationType TemplateSpecialization; public Class Class; @@ -464,6 +567,15 @@ namespace CppSharp.AST { 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); + } } /// @@ -471,11 +583,6 @@ namespace CppSharp.AST /// public class DependentNameType : Type { - public DependentNameType() - { - - } - public override T Visit(ITypeVisitor visitor, TypeQualifiers quals = new TypeQualifiers()) { @@ -500,6 +607,14 @@ namespace CppSharp.AST { 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 @@ -567,6 +682,14 @@ namespace CppSharp.AST { 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