diff --git a/src/Bridge/ASTVisitor.cs b/src/Bridge/ASTVisitor.cs
index 67f36e3b..7b3f844d 100644
--- a/src/Bridge/ASTVisitor.cs
+++ b/src/Bridge/ASTVisitor.cs
@@ -120,7 +120,7 @@ namespace Cxxi
public virtual bool VisitFieldDecl(Field field)
{
- return field.Type.Visit(this);
+ return field.Type.Visit(this, field.QualifiedType.Qualifiers);
}
public virtual bool VisitFunctionDecl(Function function)
@@ -141,14 +141,14 @@ namespace Cxxi
public virtual bool VisitParameterDecl(Parameter parameter)
{
- return parameter.Type.Visit(this);
+ return parameter.Type.Visit(this, parameter.QualifiedType.Qualifiers);
}
public virtual bool VisitTypedefDecl(TypedefDecl typedef)
{
if (typedef.Type == null)
return false;
- return typedef.Type.Visit(this);
+ return typedef.Type.Visit(this, typedef.QualifiedType.Qualifiers);
}
public virtual bool VisitEnumDecl(Enumeration @enum)
diff --git a/src/Bridge/Declaration.cs b/src/Bridge/Declaration.cs
index 8dc0192a..6c8e1c9a 100644
--- a/src/Bridge/Declaration.cs
+++ b/src/Bridge/Declaration.cs
@@ -11,6 +11,7 @@ namespace Cxxi
public interface ITypedDecl
{
Type Type { get; }
+ QualifiedType QualifiedType { get; }
}
///
@@ -96,8 +97,8 @@ namespace Cxxi
///
public class TypedefDecl : Declaration, ITypedDecl
{
- /// Type defined.
- public Type Type { get; set; }
+ public Type Type { get { return QualifiedType.Type; } }
+ public QualifiedType QualifiedType { get; set; }
public override T Visit(IDeclVisitor visitor)
{
diff --git a/src/Bridge/Field.cs b/src/Bridge/Field.cs
index 493abbb6..99244dcd 100644
--- a/src/Bridge/Field.cs
+++ b/src/Bridge/Field.cs
@@ -5,7 +5,9 @@ namespace Cxxi
///
public class Field : Declaration, ITypedDecl
{
- public Type Type { get; set; }
+ public Type Type { get { return QualifiedType.Type; } }
+ public QualifiedType QualifiedType { get; set; }
+
public AccessSpecifier Access { get; set; }
public uint Offset { get; set; }
@@ -14,10 +16,10 @@ namespace Cxxi
Offset = 0;
}
- public Field(string name, Type type, AccessSpecifier access)
+ public Field(string name, QualifiedType type, AccessSpecifier access)
{
Name = name;
- Type = type;
+ QualifiedType = type;
Access = access;
Offset = 0;
}
diff --git a/src/Bridge/Function.cs b/src/Bridge/Function.cs
index 862419f7..bcfe720b 100644
--- a/src/Bridge/Function.cs
+++ b/src/Bridge/Function.cs
@@ -26,14 +26,13 @@ namespace Cxxi
{
Usage = ParameterUsage.Unknown;
HasDefaultValue = false;
- IsConst = false;
Conversion = TypeConversionKind.None;
}
- public Type Type { get; set; }
+ public Type Type { get { return QualifiedType.Type; } }
+ public QualifiedType QualifiedType { get; set; }
public ParameterUsage Usage { get; set; }
public bool HasDefaultValue { get; set; }
- public bool IsConst { get; set; }
public TypeConversionKind Conversion { get; set; }
diff --git a/src/Bridge/Type.cs b/src/Bridge/Type.cs
index 210c0604..dfee86d5 100644
--- a/src/Bridge/Type.cs
+++ b/src/Bridge/Type.cs
@@ -3,7 +3,7 @@
namespace Cxxi
{
///
- /// Represents a C++ type reference.
+ /// Represents a C++ type.
///
public abstract class Type
{
@@ -115,6 +115,9 @@ namespace Cxxi
}
}
+ ///
+ /// Represents C++ type qualifiers.
+ ///
public struct TypeQualifiers
{
public bool IsConst;
@@ -123,7 +126,21 @@ namespace Cxxi
}
///
- /// Represents a C++ tag type reference.
+ /// Represents a qualified C++ type.
+ ///
+ public struct QualifiedType
+ {
+ public Type Type { get; set; }
+ public TypeQualifiers Qualifiers { get; set; }
+
+ public override string ToString()
+ {
+ return Type.ToString();
+ }
+ }
+
+ ///
+ /// Represents a C++ tag type.
///
public class TagType : Type
{
@@ -236,13 +253,14 @@ namespace Cxxi
}
}
- public Type Pointee;
+ public QualifiedType QualifiedPointee;
+ public Type Pointee { get { return QualifiedPointee.Type; } }
public TypeModifier Modifier;
public override T Visit(ITypeVisitor visitor, TypeQualifiers quals)
{
- return visitor.VisitPointerType(this, quals);
+ return visitor.VisitPointerType(this, QualifiedPointee.Qualifiers);
}
}
@@ -322,7 +340,7 @@ namespace Cxxi
}
public ArgumentKind Kind;
- public Type Type;
+ public QualifiedType Type;
public Declaration Declaration;
public long Integral;
}
@@ -363,8 +381,7 @@ namespace Cxxi
public override T Visit(ITypeVisitor visitor,
TypeQualifiers quals = new TypeQualifiers())
{
- //return visitor.VisitTemplateParameterType(this, quals);
- return default(T);
+ return visitor.VisitTemplateParameterType(this, quals);
}
}
diff --git a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs
index c9e31e9a..90d4b0b6 100644
--- a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs
+++ b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs
@@ -356,9 +356,7 @@ namespace Cxxi.Generators.CLI
public void GenerateFieldProperty(Field field)
{
- field.Type.Visit(Type.TypePrinter);
-
- var type = field.Type.Visit(Type.TypePrinter);
+ var type = field.Type.Visit(Type.TypePrinter, field.QualifiedType.Qualifiers);
WriteLine("property {0} {1};", type, field.Name);
}
diff --git a/src/Generator/Generators/CLI/CLIMarshal.cs b/src/Generator/Generators/CLI/CLIMarshal.cs
index 37fda9a7..52816468 100644
--- a/src/Generator/Generators/CLI/CLIMarshal.cs
+++ b/src/Generator/Generators/CLI/CLIMarshal.cs
@@ -180,7 +180,7 @@ namespace Cxxi.Generators.CLI
public bool VisitParameterDecl(Parameter parameter)
{
- throw new NotImplementedException();
+ return parameter.Type.Visit(this, parameter.QualifiedType.Qualifiers);
}
public bool VisitTypedefDecl(TypedefDecl typedef)
@@ -489,7 +489,8 @@ namespace Cxxi.Generators.CLI
{
Context.Parameter = new Parameter
{
- Name = Context.ArgName, Type = field.Type
+ Name = Context.ArgName,
+ QualifiedType = field.QualifiedType
};
return field.Type.Visit(this);
diff --git a/src/Generator/Generators/CLI/CLITypePrinter.cs b/src/Generator/Generators/CLI/CLITypePrinter.cs
index 115b4c2c..a21d1902 100644
--- a/src/Generator/Generators/CLI/CLITypePrinter.cs
+++ b/src/Generator/Generators/CLI/CLITypePrinter.cs
@@ -66,12 +66,10 @@ namespace Cxxi.Generators.CLI
return s;
}
- public string GetArgumentString(Parameter arg, bool hasName = true)
+ public string GetArgumentString(Parameter param, bool hasName = true)
{
- var quals = new TypeQualifiers { IsConst = arg.IsConst };
-
- var type = arg.Type.Visit(this, quals);
- var name = arg.Name;
+ var type = param.Type.Visit(this, param.QualifiedType.Qualifiers);
+ var name = param.Name;
if (hasName && !string.IsNullOrEmpty(name))
return string.Format("{0} {1}", type, name);
diff --git a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs
index bc6e60b6..b18e9d54 100644
--- a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs
+++ b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs
@@ -217,9 +217,7 @@ namespace Cxxi.Generators.CSharp
public string GetArgumentString(Parameter arg, bool hasName)
{
- var quals = new TypeQualifiers { IsConst = arg.IsConst };
-
- var type = arg.Type.Visit(this, quals);
+ var type = arg.Type.Visit(this, arg.QualifiedType.Qualifiers);
var name = arg.Name;
if (hasName && !string.IsNullOrEmpty(name))
diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp
index b28efec3..cb88094f 100644
--- a/src/Parser/Parser.cpp
+++ b/src/Parser/Parser.cpp
@@ -264,6 +264,23 @@ std::string Parser::GetTypeName(const clang::Type* Type)
return TypeName;
}
+Cxxi::TypeQualifiers GetTypeQualifiers(clang::QualType Type)
+{
+ Cxxi::TypeQualifiers quals;
+ quals.IsConst = Type.isLocalConstQualified();
+ quals.IsRestrict = Type.isLocalRestrictQualified();
+ quals.IsVolatile = Type.isVolatileQualified();
+ return quals;
+}
+
+Cxxi::QualifiedType GetQualifiedType(clang::QualType qual, Cxxi::Type^ type)
+{
+ Cxxi::QualifiedType qualType;
+ qualType.Type = type;
+ qualType.Qualifiers = GetTypeQualifiers(qual);
+ return qualType;
+}
+
//-----------------------------------//
static Cxxi::AccessSpecifier ConvertToAccess(clang::AccessSpecifier AS)
@@ -509,7 +526,7 @@ Cxxi::Field^ Parser::WalkFieldCXX(clang::FieldDecl* FD)
F->Name = marshalString(FD->getName());
auto TL = FD->getTypeSourceInfo()->getTypeLoc();
- F->Type = WalkType(FD->getType(), &TL);
+ F->QualifiedType = GetQualifiedType(FD->getType(), WalkType(FD->getType(), &TL));
F->Access = ConvertToAccess(FD->getAccess());
HandleComments(FD, F);
@@ -678,7 +695,9 @@ Cxxi::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
P->Modifier = Cxxi::PointerType::TypeModifier::Pointer;
auto Next = TL->getNextTypeLoc();
- P->Pointee = WalkType(Pointer->getPointeeType(), &Next);
+
+ auto Pointee = Pointer->getPointeeType();
+ P->QualifiedPointee = GetQualifiedType(Pointee, WalkType(Pointee, &Next));
return P;
}
@@ -748,7 +767,7 @@ Cxxi::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
auto PTL = PVD->getTypeSourceInfo()->getTypeLoc();
FA->Name = marshalString(PVD->getNameAsString());
- FA->Type = WalkType(PVD->getType(), &PTL);
+ FA->QualifiedType = GetQualifiedType(PVD->getType(), WalkType(PVD->getType(), &PTL));
F->Arguments->Add(FA);
}
@@ -816,7 +835,7 @@ Cxxi::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
Arg.Kind = Cxxi::TemplateArgument::ArgumentKind::Type;
TypeLoc ArgTL;
ArgTL = ArgLoc.getTypeSourceInfo()->getTypeLoc();
- Arg.Type = WalkType(TA.getAsType(), &ArgTL);
+ Arg.Type = GetQualifiedType(TA.getAsType(), WalkType(TA.getAsType(), &ArgTL));
break;
}
case TemplateArgument::Declaration:
@@ -878,8 +897,10 @@ Cxxi::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
TypeLoc Next;
if (!TL->isNull())
Next = TL->getNextTypeLoc();
- P->Pointee = WalkType(LR->getPointeeType(), &Next);
-
+
+ auto Pointee = LR->getPointeeType();
+ P->QualifiedPointee = GetQualifiedType(Pointee, WalkType(Pointee, &Next));
+
return P;
}
case Type::RValueReference:
@@ -892,8 +913,10 @@ Cxxi::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
TypeLoc Next;
if (!TL->isNull())
Next = TL->getNextTypeLoc();
- P->Pointee = WalkType(LR->getPointeeType(), &Next);
-
+
+ auto Pointee = LR->getPointeeType();
+ P->QualifiedPointee = GetQualifiedType(Pointee, WalkType(Pointee, &Next));
+
return P;
}
default:
@@ -1006,7 +1029,7 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Cxxi::Function^ F,
if (auto TSI = FD->getTypeSourceInfo())
{
TypeLoc TL = TSI->getTypeLoc();
- RTL = ((FunctionTypeLoc*) &TL)->getResultLoc();
+ RTL = TL.getAs().getResultLoc();
}
F->ReturnType = WalkType(FD->getResultType(), &RTL);
@@ -1019,12 +1042,11 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Cxxi::Function^ F,
auto P = gcnew Cxxi::Parameter();
P->Name = marshalString(VD->getNameAsString());
- P->IsConst = VD->getType().isConstQualified();
TypeLoc PTL;
if (auto TSI = VD->getTypeSourceInfo())
PTL = VD->getTypeSourceInfo()->getTypeLoc();
- P->Type = WalkType(VD->getType(), &PTL);
+ P->QualifiedType = GetQualifiedType(VD->getType(), WalkType(VD->getType(), &PTL));
P->HasDefaultValue = VD->hasDefaultArg();
@@ -1391,7 +1413,8 @@ Cxxi::Declaration^ Parser::WalkDeclaration(clang::Decl* D, clang::TypeLoc* TL,
Typedef = NS->FindTypedef(Name, /*Create=*/true);
auto TTL = TD->getTypeSourceInfo()->getTypeLoc();
- Typedef->Type = WalkType(TD->getUnderlyingType(), &TTL);
+ Typedef->QualifiedType = GetQualifiedType(TD->getUnderlyingType(),
+ WalkType(TD->getUnderlyingType(), &TTL));
Decl = Typedef;