Browse Source

Exposed constant expressions, friendships and exception specifications of functions in our AST.

pull/736/head
Dimitar Dobrev 8 years ago
parent
commit
cef847825a
  1. 40
      src/AST/Function.cs
  2. 15
      src/AST/Type.cs
  3. 15
      src/CppParser/AST.cpp
  4. 28
      src/CppParser/AST.h
  5. 44
      src/CppParser/Bindings/CLI/AST.cpp
  6. 46
      src/CppParser/Bindings/CLI/AST.h
  7. 3745
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs
  8. 2
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std.cs
  9. 3745
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs
  10. 2
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std.cs
  11. 3719
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs
  12. 2
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std.cs
  13. 3719
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs
  14. 2
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/Std.cs
  15. 3719
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs
  16. 2
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/Std.cs
  17. 2681
      src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs
  18. 2
      src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std.cs
  19. 123
      src/CppParser/Parser.cpp
  20. 4
      src/CppParser/Parser.h
  21. 20
      src/CppParser/ParserGen/ParserGen.cs
  22. 18
      src/Generator.Tests/AST/TestAST.cs
  23. 2
      src/Generator.Tests/Passes/TestPasses.cs
  24. 49
      src/Parser/ASTConverter.cs
  25. 2
      tests/Native/AST.h

40
src/AST/Function.cs

@ -116,14 +116,19 @@ namespace CppSharp.AST @@ -116,14 +116,19 @@ namespace CppSharp.AST
AdjustedMethod
}
public enum FriendKind
{
None,
Declared,
Undeclared
}
public class Function : Declaration, ITypedDecl, IMangledDecl
{
public Function()
{
Parameters = new List<Parameter>();
CallingConvention = CallingConvention.Default;
IsVariadic = false;
IsInline = false;
Signature = string.Empty;
Index = null;
}
@ -158,14 +163,15 @@ namespace CppSharp.AST @@ -158,14 +163,15 @@ namespace CppSharp.AST
public bool HasThisReturn { get; set; }
public List<Parameter> Parameters { get; set; }
public bool IsConstExpr { get; set; }
public bool IsVariadic { get; set; }
public bool IsInline { get; set; }
public bool IsPure { get; set; }
public bool IsDeleted { get; set; }
public bool IsAmbiguous { get; set; }
public FriendKind FriendKind { get; set; }
public CXXOperatorKind OperatorKind { get; set; }
public bool IsOperator { get { return OperatorKind != CXXOperatorKind.None; } }
public bool IsOperator => OperatorKind != CXXOperatorKind.None;
public CallingConvention CallingConvention { get; set; }
@ -173,25 +179,15 @@ namespace CppSharp.AST @@ -173,25 +179,15 @@ namespace CppSharp.AST
public Function InstantiatedFrom { get; set; }
public bool IsThisCall
{
get { return CallingConvention == CallingConvention.ThisCall; }
}
public QualifiedType FunctionType { get; set; }
public bool IsStdCall
{
get { return CallingConvention == CallingConvention.StdCall; }
}
public bool IsThisCall => CallingConvention == CallingConvention.ThisCall;
public bool IsFastCall
{
get { return CallingConvention == CallingConvention.FastCall; }
}
public bool IsStdCall => CallingConvention == CallingConvention.StdCall;
public bool IsCCall
{
get { return CallingConvention == CallingConvention.C; }
}
public bool IsFastCall => CallingConvention == CallingConvention.FastCall;
public bool IsCCall => CallingConvention == CallingConvention.C;
public bool HasIndirectReturnTypeParameter
{
@ -224,7 +220,7 @@ namespace CppSharp.AST @@ -224,7 +220,7 @@ namespace CppSharp.AST
}
public FunctionSynthKind SynthKind { get; set; }
public bool IsSynthetized { get { return SynthKind != FunctionSynthKind.None; } }
public bool IsSynthetized => SynthKind != FunctionSynthKind.None;
public bool IsNonMemberOperator { get; set; }
public Function OriginalFunction { get; set; }
@ -243,7 +239,7 @@ namespace CppSharp.AST @@ -243,7 +239,7 @@ namespace CppSharp.AST
return visitor.VisitFunctionDecl(this);
}
public Type Type { get { return ReturnType.Type; } }
public Type Type => ReturnType.Type;
public QualifiedType QualifiedType { get { return ReturnType; } }
public FunctionType GetFunctionType()

15
src/AST/Type.cs

@ -222,6 +222,19 @@ namespace CppSharp.AST @@ -222,6 +222,19 @@ namespace CppSharp.AST
}
}
public enum ExceptionSpecType
{
None,
DynamicNone,
Dynamic,
MSAny,
BasicNoexcept,
ComputedNoexcept,
Unevaluated,
Uninstantiated,
Unparsed
}
/// <summary>
/// Represents an C/C++ function type.
/// </summary>
@ -235,6 +248,8 @@ namespace CppSharp.AST @@ -235,6 +248,8 @@ namespace CppSharp.AST
public CallingConvention CallingConvention { get; set; }
public ExceptionSpecType ExceptionSpecType { get; set; }
public FunctionType()
{
Parameters = new List<Parameter>();

15
src/CppParser/AST.cpp

@ -66,7 +66,12 @@ TagType::TagType() : Type(TypeKind::Tag) {} @@ -66,7 +66,12 @@ TagType::TagType() : Type(TypeKind::Tag) {}
ArrayType::ArrayType() : Type(TypeKind::Array) {}
FunctionType::FunctionType() : Type(TypeKind::Function) {}
FunctionType::FunctionType()
: Type(TypeKind::Function)
, callingConvention(CallingConvention::Default)
, exceptionSpecType(ExceptionSpecType::None)
{
}
FunctionType::~FunctionType() {}
@ -625,6 +630,14 @@ Parameter::~Parameter() @@ -625,6 +630,14 @@ Parameter::~Parameter()
Function::Function()
: Declaration(DeclarationKind::Function)
, isReturnIndirect(false)
, isConstExpr(false)
, isVariadic(false)
, isInline(false)
, isPure(false)
, isDeleted(false)
, friendKind(FriendKind::None)
, operatorKind(CXXOperatorKind::None)
, callingConvention(CallingConvention::Default)
, specializationInfo(0)
, instantiatedFrom(0)
{

28
src/CppParser/AST.h

@ -103,13 +103,27 @@ enum class CallingConvention @@ -103,13 +103,27 @@ enum class CallingConvention
Unknown
};
enum class ExceptionSpecType
{
None,
DynamicNone,
Dynamic,
MSAny,
BasicNoexcept,
ComputedNoexcept,
Unevaluated,
Uninstantiated,
Unparsed
};
class CS_API FunctionType : public Type
{
public:
~FunctionType();
DECLARE_TYPE_KIND(Function)
~FunctionType();
QualifiedType returnType;
CallingConvention callingConvention;
ExceptionSpecType exceptionSpecType;
VECTOR(Parameter*, Parameters)
};
@ -690,6 +704,13 @@ enum class CXXOperatorKind @@ -690,6 +704,13 @@ enum class CXXOperatorKind
class FunctionTemplateSpecialization;
enum class FriendKind
{
None,
Declared,
Undeclared
};
class CS_API Function : public Declaration
{
public:
@ -700,17 +721,20 @@ public: @@ -700,17 +721,20 @@ public:
bool isReturnIndirect;
bool hasThisReturn;
bool isConstExpr;
bool isVariadic;
bool isInline;
bool isPure;
bool isDeleted;
CXXOperatorKind OperatorKind;
FriendKind friendKind;
CXXOperatorKind operatorKind;
STRING(Mangled)
STRING(Signature)
CallingConvention callingConvention;
VECTOR(Parameter*, Parameters)
FunctionTemplateSpecialization* specializationInfo;
Function* instantiatedFrom;
QualifiedType qualifiedType;
};
class AccessSpecifierDecl;

44
src/CppParser/Bindings/CLI/AST.cpp

@ -394,6 +394,16 @@ void CppSharp::Parser::AST::FunctionType::CallingConvention::set(CppSharp::Parse @@ -394,6 +394,16 @@ void CppSharp::Parser::AST::FunctionType::CallingConvention::set(CppSharp::Parse
((::CppSharp::CppParser::AST::FunctionType*)NativePtr)->callingConvention = (::CppSharp::CppParser::AST::CallingConvention)value;
}
CppSharp::Parser::AST::ExceptionSpecType CppSharp::Parser::AST::FunctionType::ExceptionSpecType::get()
{
return (CppSharp::Parser::AST::ExceptionSpecType)((::CppSharp::CppParser::AST::FunctionType*)NativePtr)->exceptionSpecType;
}
void CppSharp::Parser::AST::FunctionType::ExceptionSpecType::set(CppSharp::Parser::AST::ExceptionSpecType value)
{
((::CppSharp::CppParser::AST::FunctionType*)NativePtr)->exceptionSpecType = (::CppSharp::CppParser::AST::ExceptionSpecType)value;
}
unsigned int CppSharp::Parser::AST::FunctionType::ParametersCount::get()
{
auto __ret = ((::CppSharp::CppParser::AST::FunctionType*)NativePtr)->getParametersCount();
@ -3006,6 +3016,16 @@ void CppSharp::Parser::AST::Function::HasThisReturn::set(bool value) @@ -3006,6 +3016,16 @@ void CppSharp::Parser::AST::Function::HasThisReturn::set(bool value)
((::CppSharp::CppParser::AST::Function*)NativePtr)->hasThisReturn = value;
}
bool CppSharp::Parser::AST::Function::IsConstExpr::get()
{
return ((::CppSharp::CppParser::AST::Function*)NativePtr)->isConstExpr;
}
void CppSharp::Parser::AST::Function::IsConstExpr::set(bool value)
{
((::CppSharp::CppParser::AST::Function*)NativePtr)->isConstExpr = value;
}
bool CppSharp::Parser::AST::Function::IsVariadic::get()
{
return ((::CppSharp::CppParser::AST::Function*)NativePtr)->isVariadic;
@ -3046,14 +3066,24 @@ void CppSharp::Parser::AST::Function::IsDeleted::set(bool value) @@ -3046,14 +3066,24 @@ void CppSharp::Parser::AST::Function::IsDeleted::set(bool value)
((::CppSharp::CppParser::AST::Function*)NativePtr)->isDeleted = value;
}
CppSharp::Parser::AST::FriendKind CppSharp::Parser::AST::Function::FriendKind::get()
{
return (CppSharp::Parser::AST::FriendKind)((::CppSharp::CppParser::AST::Function*)NativePtr)->friendKind;
}
void CppSharp::Parser::AST::Function::FriendKind::set(CppSharp::Parser::AST::FriendKind value)
{
((::CppSharp::CppParser::AST::Function*)NativePtr)->friendKind = (::CppSharp::CppParser::AST::FriendKind)value;
}
CppSharp::Parser::AST::CXXOperatorKind CppSharp::Parser::AST::Function::OperatorKind::get()
{
return (CppSharp::Parser::AST::CXXOperatorKind)((::CppSharp::CppParser::AST::Function*)NativePtr)->OperatorKind;
return (CppSharp::Parser::AST::CXXOperatorKind)((::CppSharp::CppParser::AST::Function*)NativePtr)->operatorKind;
}
void CppSharp::Parser::AST::Function::OperatorKind::set(CppSharp::Parser::AST::CXXOperatorKind value)
{
((::CppSharp::CppParser::AST::Function*)NativePtr)->OperatorKind = (::CppSharp::CppParser::AST::CXXOperatorKind)value;
((::CppSharp::CppParser::AST::Function*)NativePtr)->operatorKind = (::CppSharp::CppParser::AST::CXXOperatorKind)value;
}
CppSharp::Parser::AST::CallingConvention CppSharp::Parser::AST::Function::CallingConvention::get()
@ -3086,6 +3116,16 @@ void CppSharp::Parser::AST::Function::InstantiatedFrom::set(CppSharp::Parser::AS @@ -3086,6 +3116,16 @@ void CppSharp::Parser::AST::Function::InstantiatedFrom::set(CppSharp::Parser::AS
((::CppSharp::CppParser::AST::Function*)NativePtr)->instantiatedFrom = (::CppSharp::CppParser::AST::Function*)value->NativePtr;
}
CppSharp::Parser::AST::QualifiedType^ CppSharp::Parser::AST::Function::QualifiedType::get()
{
return (&((::CppSharp::CppParser::AST::Function*)NativePtr)->qualifiedType == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::QualifiedType((::CppSharp::CppParser::AST::QualifiedType*)&((::CppSharp::CppParser::AST::Function*)NativePtr)->qualifiedType);
}
void CppSharp::Parser::AST::Function::QualifiedType::set(CppSharp::Parser::AST::QualifiedType^ value)
{
((::CppSharp::CppParser::AST::Function*)NativePtr)->qualifiedType = *(::CppSharp::CppParser::AST::QualifiedType*)value->NativePtr;
}
System::String^ CppSharp::Parser::AST::Function::Mangled::get()
{
auto __ret = ((::CppSharp::CppParser::AST::Function*)NativePtr)->getMangled();

46
src/CppParser/Bindings/CLI/AST.h

@ -18,6 +18,8 @@ namespace CppSharp @@ -18,6 +18,8 @@ namespace CppSharp
enum struct CommentKind;
enum struct CppAbi;
enum struct DeclarationKind;
enum struct ExceptionSpecType;
enum struct FriendKind;
enum struct MacroLocation;
enum struct PrimitiveType;
enum struct RawCommentKind;
@ -226,6 +228,13 @@ namespace CppSharp @@ -226,6 +228,13 @@ namespace CppSharp
VerbatimBlockLineComment = 14
};
public enum struct FriendKind
{
None = 0,
Declared = 1,
Undeclared = 2
};
public enum struct CXXOperatorKind
{
None = 0,
@ -372,6 +381,19 @@ namespace CppSharp @@ -372,6 +381,19 @@ namespace CppSharp
IntPtr = 23
};
public enum struct ExceptionSpecType
{
None = 0,
DynamicNone = 1,
Dynamic = 2,
MSAny = 3,
BasicNoexcept = 4,
ComputedNoexcept = 5,
Unevaluated = 6,
Uninstantiated = 7,
Unparsed = 8
};
public enum struct ArchType
{
UnknownArch = 0,
@ -580,6 +602,12 @@ namespace CppSharp @@ -580,6 +602,12 @@ namespace CppSharp
void set(CppSharp::Parser::AST::CallingConvention);
}
property CppSharp::Parser::AST::ExceptionSpecType ExceptionSpecType
{
CppSharp::Parser::AST::ExceptionSpecType get();
void set(CppSharp::Parser::AST::ExceptionSpecType);
}
property unsigned int ParametersCount
{
unsigned int get();
@ -1854,6 +1882,12 @@ namespace CppSharp @@ -1854,6 +1882,12 @@ namespace CppSharp
void set(bool);
}
property bool IsConstExpr
{
bool get();
void set(bool);
}
property bool IsVariadic
{
bool get();
@ -1878,6 +1912,12 @@ namespace CppSharp @@ -1878,6 +1912,12 @@ namespace CppSharp
void set(bool);
}
property CppSharp::Parser::AST::FriendKind FriendKind
{
CppSharp::Parser::AST::FriendKind get();
void set(CppSharp::Parser::AST::FriendKind);
}
property CppSharp::Parser::AST::CXXOperatorKind OperatorKind
{
CppSharp::Parser::AST::CXXOperatorKind get();
@ -1902,6 +1942,12 @@ namespace CppSharp @@ -1902,6 +1942,12 @@ namespace CppSharp
void set(CppSharp::Parser::AST::Function^);
}
property CppSharp::Parser::AST::QualifiedType^ QualifiedType
{
CppSharp::Parser::AST::QualifiedType^ get();
void set(CppSharp::Parser::AST::QualifiedType^);
}
property System::String^ Mangled
{
System::String^ get();

3745
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

2
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std.cs

@ -11,6 +11,8 @@ using System.Runtime.CompilerServices; @@ -11,6 +11,8 @@ using System.Runtime.CompilerServices;
[assembly:InternalsVisibleTo("CppSharp.Parser.CSharp")]
[assembly:InternalsVisibleTo("CppSharp.CppParser")]
namespace Std
{
}

3745
src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

2
src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std.cs

@ -11,6 +11,8 @@ using System.Runtime.CompilerServices; @@ -11,6 +11,8 @@ using System.Runtime.CompilerServices;
[assembly:InternalsVisibleTo("CppSharp.Parser.CSharp")]
[assembly:InternalsVisibleTo("CppSharp.CppParser")]
namespace Std
{
public unsafe partial class Lockit

3719
src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

2
src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std.cs

@ -11,6 +11,8 @@ using System.Runtime.CompilerServices; @@ -11,6 +11,8 @@ using System.Runtime.CompilerServices;
[assembly:InternalsVisibleTo("CppSharp.Parser.CSharp")]
[assembly:InternalsVisibleTo("CppSharp.CppParser")]
namespace Std
{
}

3719
src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

2
src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/Std.cs

@ -11,6 +11,8 @@ using System.Runtime.CompilerServices; @@ -11,6 +11,8 @@ using System.Runtime.CompilerServices;
[assembly:InternalsVisibleTo("CppSharp.Parser.CSharp")]
[assembly:InternalsVisibleTo("CppSharp.CppParser")]
namespace Std
{
}

3719
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

2
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/Std.cs

@ -11,6 +11,8 @@ using System.Runtime.CompilerServices; @@ -11,6 +11,8 @@ using System.Runtime.CompilerServices;
[assembly:InternalsVisibleTo("CppSharp.Parser.CSharp")]
[assembly:InternalsVisibleTo("CppSharp.CppParser")]
namespace Std
{
}

2681
src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

2
src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std.cs

@ -11,6 +11,8 @@ using System.Runtime.CompilerServices; @@ -11,6 +11,8 @@ using System.Runtime.CompilerServices;
[assembly:InternalsVisibleTo("CppSharp.Parser.CSharp")]
[assembly:InternalsVisibleTo("CppSharp.CppParser")]
namespace Std
{
public unsafe partial class Lockit

123
src/CppParser/Parser.cpp

@ -1949,6 +1949,21 @@ clang::TypeLoc ResolveTypeLoc(clang::TypeLoc TL, clang::TypeLoc::TypeLocClass Cl @@ -1949,6 +1949,21 @@ clang::TypeLoc ResolveTypeLoc(clang::TypeLoc TL, clang::TypeLoc::TypeLocClass Cl
return TL;
}
static FriendKind ConvertFriendKind(clang::Decl::FriendObjectKind FK)
{
using namespace clang;
switch (FK)
{
case Decl::FriendObjectKind::FOK_Declared:
return FriendKind::Declared;
case Decl::FriendObjectKind::FOK_Undeclared:
return FriendKind::Undeclared;
default:
return FriendKind::None;
}
}
static CallingConvention ConvertCallConv(clang::CallingConv CC)
{
using namespace clang;
@ -1968,6 +1983,33 @@ static CallingConvention ConvertCallConv(clang::CallingConv CC) @@ -1968,6 +1983,33 @@ static CallingConvention ConvertCallConv(clang::CallingConv CC)
}
}
static ExceptionSpecType ConvertExceptionType(clang::ExceptionSpecificationType EST)
{
using namespace clang;
switch (EST)
{
case ExceptionSpecificationType::EST_BasicNoexcept:
return ExceptionSpecType::BasicNoexcept;
case ExceptionSpecificationType::EST_ComputedNoexcept:
return ExceptionSpecType::ComputedNoexcept;
case ExceptionSpecificationType::EST_Dynamic:
return ExceptionSpecType::Dynamic;
case ExceptionSpecificationType::EST_DynamicNone:
return ExceptionSpecType::DynamicNone;
case ExceptionSpecificationType::EST_MSAny:
return ExceptionSpecType::MSAny;
case ExceptionSpecificationType::EST_Unevaluated:
return ExceptionSpecType::Unevaluated;
case ExceptionSpecificationType::EST_Uninstantiated:
return ExceptionSpecType::Uninstantiated;
case ExceptionSpecificationType::EST_Unparsed:
return ExceptionSpecType::Unparsed;
default:
return ExceptionSpecType::None;
}
}
static ParserIntType ConvertIntType(clang::TargetInfo::IntType IT)
{
switch (IT)
@ -2287,6 +2329,7 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -2287,6 +2329,7 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
FunctionProtoTypeLoc FTL;
TypeLoc RL;
TypeLoc Next;
clang::SourceLocation ParamStartLoc;
if (LocValid)
{
while (!TL->isNull() && TL->getTypeLocClass() != TypeLoc::FunctionProto)
@ -2299,28 +2342,26 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -2299,28 +2342,26 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
{
FTL = TL->getAs<FunctionProtoTypeLoc>();
RL = FTL.getReturnLoc();
ParamStartLoc = FTL.getLParenLoc();
}
}
auto F = new FunctionType();
F->returnType = GetQualifiedType(FP->getReturnType(), &RL);
F->callingConvention = ConvertCallConv(FP->getCallConv());
F->exceptionSpecType = ConvertExceptionType(FP->getExceptionSpecType());
for (unsigned i = 0; i < FP->getNumParams(); ++i)
{
auto FA = new Parameter();
if (FTL && FTL.getParam(i))
{
auto PVD = FTL.getParam(i);
HandleDeclaration(PVD, FA);
auto PTL = PVD->getTypeSourceInfo()->getTypeLoc();
FA->Name = PVD->getNameAsString();
FA->qualifiedType = GetQualifiedType(PVD->getOriginalType(), &PTL);
auto FA = WalkParameter(PVD, ParamStartLoc);
F->Parameters.push_back(FA);
}
else
{
auto FA = new Parameter();
auto Arg = FP->getParamType(i);
FA->Name = "";
FA->qualifiedType = GetQualifiedType(Arg);
@ -2329,8 +2370,8 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -2329,8 +2370,8 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
// use a special value known to the managed side to make sure
// it gets ignored.
FA->originalPtr = IgnorePtr;
F->Parameters.push_back(FA);
}
F->Parameters.push_back(FA);
}
Ty = F;
@ -2766,6 +2807,36 @@ static clang::TypeLoc DesugarTypeLoc(const clang::TypeLoc& Loc) @@ -2766,6 +2807,36 @@ static clang::TypeLoc DesugarTypeLoc(const clang::TypeLoc& Loc)
return Loc;
}
Parameter* Parser::WalkParameter(const clang::ParmVarDecl* PVD,
const clang::SourceLocation& ParamStartLoc)
{
auto P = new Parameter();
P->Name = PVD->getNameAsString();
clang::TypeLoc PTL;
if (auto TSI = PVD->getTypeSourceInfo())
PTL = PVD->getTypeSourceInfo()->getTypeLoc();
auto paramRange = PVD->getSourceRange();
paramRange.setBegin(ParamStartLoc);
HandlePreprocessedEntities(P, paramRange, MacroLocation::FunctionParameters);
P->qualifiedType = GetQualifiedType(PVD->getOriginalType(), &PTL);
P->hasDefaultValue = PVD->hasDefaultArg();
P->index = PVD->getFunctionScopeIndex();
if (PVD->hasDefaultArg() && !PVD->hasUnparsedDefaultArg())
{
if (PVD->hasUninstantiatedDefaultArg())
P->defaultArgument = WalkExpression(PVD->getUninstantiatedDefaultArg());
else
P->defaultArgument = WalkExpression(PVD->getDefaultArg());
}
HandleDeclaration(PVD, P);
return P;
}
void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F,
bool IsDependent)
{
@ -2779,6 +2850,7 @@ void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F, @@ -2779,6 +2850,7 @@ void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F,
F->Name = FD->getNameAsString();
F->_namespace = NS;
F->isConstExpr = FD->isConstexpr();
F->isVariadic = FD->isVariadic();
F->isInline = FD->isInlined();
F->isDependent = FD->isDependentContext();
@ -2787,10 +2859,12 @@ void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F, @@ -2787,10 +2859,12 @@ void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F,
if (auto InstantiatedFrom = FD->getTemplateInstantiationPattern())
F->instantiatedFrom = static_cast<Function*>(WalkDeclaration(InstantiatedFrom));
auto FK = FD->getFriendObjectKind();
F->friendKind = ConvertFriendKind(FK);
auto CC = FT->getCallConv();
F->callingConvention = ConvertCallConv(CC);
F->OperatorKind = GetOperatorKindFromDecl(FD->getDeclName());
F->operatorKind = GetOperatorKindFromDecl(FD->getDeclName());
TypeLoc RTL;
if (auto TSI = FD->getTypeSourceInfo())
@ -2799,6 +2873,8 @@ void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F, @@ -2799,6 +2873,8 @@ void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F,
auto FTL = Loc.getAs<FunctionTypeLoc>();
if (FTL)
{
F->qualifiedType = GetQualifiedType(FD->getType(), &FTL);
RTL = FTL.getReturnLoc();
auto& SM = c->getSourceManager();
@ -2848,31 +2924,8 @@ void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F, @@ -2848,31 +2924,8 @@ void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F,
for (const auto& VD : FD->parameters())
{
auto P = new Parameter();
P->Name = VD->getNameAsString();
TypeLoc PTL;
if (auto TSI = VD->getTypeSourceInfo())
PTL = VD->getTypeSourceInfo()->getTypeLoc();
auto paramRange = VD->getSourceRange();
paramRange.setBegin(ParamStartLoc);
HandlePreprocessedEntities(P, paramRange, MacroLocation::FunctionParameters);
P->qualifiedType = GetQualifiedType(VD->getOriginalType(), &PTL);
P->hasDefaultValue = VD->hasDefaultArg();
auto P = WalkParameter(VD, ParamStartLoc);
P->_namespace = NS;
P->index = VD->getFunctionScopeIndex();
if (VD->hasDefaultArg() && !VD->hasUnparsedDefaultArg())
{
if (VD->hasUninstantiatedDefaultArg())
P->defaultArgument = WalkExpression(VD->getUninstantiatedDefaultArg());
else
P->defaultArgument = WalkExpression(VD->getDefaultArg());
}
HandleDeclaration(VD, P);
F->Parameters.push_back(P);
ParamStartLoc = VD->getLocEnd();
@ -3190,7 +3243,7 @@ void Parser::HandlePreprocessedEntities(Declaration* Decl) @@ -3190,7 +3243,7 @@ void Parser::HandlePreprocessedEntities(Declaration* Decl)
}
}
AST::Expression* Parser::WalkExpression(clang::Expr* Expr)
AST::Expression* Parser::WalkExpression(const clang::Expr* Expr)
{
using namespace clang;
@ -3253,7 +3306,7 @@ AST::Expression* Parser::WalkExpression(clang::Expr* Expr) @@ -3253,7 +3306,7 @@ AST::Expression* Parser::WalkExpression(clang::Expr* Expr)
}
auto ConstructorExpression = new AST::CXXConstructExpr(GetStringFromStatement(Expr),
WalkDeclaration(ConstructorExpr->getConstructor()));
for (clang::Expr* arg : ConstructorExpr->arguments())
for (auto arg : ConstructorExpr->arguments())
{
ConstructorExpression->Arguments.push_back(WalkExpression(arg));
}

4
src/CppParser/Parser.h

@ -110,7 +110,7 @@ private: @@ -110,7 +110,7 @@ private:
VTableComponent WalkVTableComponent(const clang::VTableComponent& Component);
PreprocessedEntity* WalkPreprocessedEntity(Declaration* Decl,
clang::PreprocessedEntity* PPEntity);
AST::Expression* WalkExpression(clang::Expr* Expression);
AST::Expression* WalkExpression(const clang::Expr* Expression);
std::string GetStringFromStatement(const clang::Stmt* Statement);
// Clang helpers
@ -119,6 +119,8 @@ private: @@ -119,6 +119,8 @@ private:
std::string GetDeclMangledName(const clang::Decl* D);
std::string GetTypeName(const clang::Type* Type);
bool CanCheckCodeGenInfo(clang::Sema & S, const clang::Type * Ty);
Parameter* WalkParameter(const clang::ParmVarDecl* PVD,
const clang::SourceLocation& ParamStartLoc);
void WalkFunction(const clang::FunctionDecl* FD, Function* F,
bool IsDependent = false);
void HandlePreprocessedEntities(Declaration* Decl);

20
src/CppParser/ParserGen/ParserGen.cs

@ -55,9 +55,7 @@ namespace CppSharp @@ -55,9 +55,7 @@ namespace CppSharp
parserOptions.Abi = Abi;
var options = driver.Options;
options.LibraryName = "CppSharp.Parser" +
(driver.Options.IsCSharpGenerator ? ".CSharp" : ".CLI");
options.SharedLibraryName = "CppSharp.CppParser.dll";
options.LibraryName = "CppSharp.CppParser";
options.GeneratorKind = Kind;
options.Headers.AddRange(new[]
{
@ -170,12 +168,18 @@ namespace CppSharp @@ -170,12 +168,18 @@ namespace CppSharp
{
driver.Generator.OnUnitGenerated += o =>
{
if (o.TranslationUnit.Module == driver.Options.SystemModule)
return;
Block firstBlock = o.Templates[0].RootBlock.Blocks[1];
firstBlock.WriteLine("using System.Runtime.CompilerServices;");
firstBlock.NewLine();
firstBlock.WriteLine("[assembly:InternalsVisibleTo(\"CppSharp.Parser\")]");
if (o.TranslationUnit.Module == driver.Options.SystemModule)
{
firstBlock.NewLine();
firstBlock.WriteLine("[assembly:InternalsVisibleTo(\"CppSharp.Parser.CSharp\")]");
}
else
{
firstBlock.WriteLine("using System.Runtime.CompilerServices;");
firstBlock.NewLine();
firstBlock.WriteLine("[assembly:InternalsVisibleTo(\"CppSharp.Parser\")]");
}
};
}
}

18
src/Generator.Tests/AST/TestAST.cs

@ -435,5 +435,21 @@ namespace CppSharp.Generator.Tests.AST @@ -435,5 +435,21 @@ namespace CppSharp.Generator.Tests.AST
var @class = AstContext.FindCompleteClass("TestComments");
Assert.That(@class.Layout.Bases.Count, Is.EqualTo(0));
}
}
[Test]
public void TestFunctionSpecifications()
{
var constExprNoExcept = AstContext.FindFunction("constExprNoExcept").First();
Assert.IsTrue(constExprNoExcept.IsConstExpr);
var functionType = (FunctionType) constExprNoExcept.FunctionType.Type;
Assert.That(functionType.ExceptionSpecType,
Is.EqualTo(ExceptionSpecType.BasicNoexcept));
var regular = AstContext.FindFunction("testSignature").First();
Assert.IsFalse(regular.IsConstExpr);
var regularFunctionType = (FunctionType) regular.FunctionType.Type;
Assert.That(regularFunctionType.ExceptionSpecType,
Is.EqualTo(ExceptionSpecType.None));
}
}
}

2
src/Generator.Tests/Passes/TestPasses.cs

@ -208,7 +208,7 @@ namespace CppSharp.Generator.Tests.Passes @@ -208,7 +208,7 @@ namespace CppSharp.Generator.Tests.Passes
Assert.AreEqual(method.Access, AccessSpecifier.Internal);
}
private string TypePrinterDelegate(CppSharp.AST.Type type)
private string TypePrinterDelegate(Type type)
{
return type.Visit(new CSharpTypePrinter(Driver.Context)).Type;
}

49
src/Parser/ASTConverter.cs

@ -493,6 +493,7 @@ namespace CppSharp @@ -493,6 +493,7 @@ namespace CppSharp
_type.ReturnType = VisitQualified(type.ReturnType);
_type.CallingConvention = DeclConverter.VisitCallingConvention(
type.CallingConvention);
_type.ExceptionSpecType = VisitExceptionSpecType(type.ExceptionSpecType);
for (uint i = 0; i < type.ParametersCount; ++i)
{
@ -530,6 +531,34 @@ namespace CppSharp @@ -530,6 +531,34 @@ namespace CppSharp
}
}
private static AST.ExceptionSpecType VisitExceptionSpecType(
ExceptionSpecType exceptionSpecType)
{
switch (exceptionSpecType)
{
case ExceptionSpecType.None:
return AST.ExceptionSpecType.None;
case ExceptionSpecType.DynamicNone:
return AST.ExceptionSpecType.DynamicNone;
case ExceptionSpecType.Dynamic:
return AST.ExceptionSpecType.Dynamic;
case ExceptionSpecType.MSAny:
return AST.ExceptionSpecType.MSAny;
case ExceptionSpecType.BasicNoexcept:
return AST.ExceptionSpecType.BasicNoexcept;
case ExceptionSpecType.ComputedNoexcept:
return AST.ExceptionSpecType.ComputedNoexcept;
case ExceptionSpecType.Unevaluated:
return AST.ExceptionSpecType.Unevaluated;
case ExceptionSpecType.Uninstantiated:
return AST.ExceptionSpecType.Uninstantiated;
case ExceptionSpecType.Unparsed:
return AST.ExceptionSpecType.Unparsed;
default:
throw new ArgumentOutOfRangeException("exceptionSpecType");
}
}
public override AST.Type VisitMemberPointer(MemberPointerType type)
{
var _type = new AST.MemberPointerType();
@ -1123,16 +1152,19 @@ namespace CppSharp @@ -1123,16 +1152,19 @@ namespace CppSharp
_function.ReturnType = typeConverter.VisitQualified(function.ReturnType);
_function.IsReturnIndirect = function.IsReturnIndirect;
_function.HasThisReturn = function.HasThisReturn;
_function.IsConstExpr = function.IsConstExpr;
_function.IsVariadic = function.IsVariadic;
_function.IsInline = function.IsInline;
_function.IsPure = function.IsPure;
_function.IsDeleted = function.IsDeleted;
_function.FriendKind = VisitFriendKind(function.FriendKind);
_function.OperatorKind = VisitCXXOperatorKind(function.OperatorKind);
_function.Mangled = function.Mangled;
_function.Signature = function.Signature;
_function.CallingConvention = VisitCallingConvention(function.CallingConvention);
if (function.InstantiatedFrom != null)
_function.InstantiatedFrom = (AST.Function) Visit(function.InstantiatedFrom);
_function.FunctionType = typeConverter.VisitQualified(function.QualifiedType);
for (uint i = 0; i < function.ParametersCount; ++i)
{
@ -1306,7 +1338,7 @@ namespace CppSharp @@ -1306,7 +1338,7 @@ namespace CppSharp
}
}
static internal AST.CallingConvention VisitCallingConvention(CallingConvention callingConvention)
internal static AST.CallingConvention VisitCallingConvention(CallingConvention callingConvention)
{
switch (callingConvention)
{
@ -1327,6 +1359,21 @@ namespace CppSharp @@ -1327,6 +1359,21 @@ namespace CppSharp
}
}
private static AST.FriendKind VisitFriendKind(FriendKind friendKind)
{
switch (friendKind)
{
case FriendKind.None:
return AST.FriendKind.None;
case FriendKind.Declared:
return AST.FriendKind.Declared;
case FriendKind.Undeclared:
return AST.FriendKind.Undeclared;
default:
throw new ArgumentOutOfRangeException("friendKind");
}
}
public override AST.Declaration VisitEnumeration(Enumeration decl)
{
var _enum = new AST.Enumeration();

2
tests/Native/AST.h

@ -156,3 +156,5 @@ typedef ForwardedTemplate<int> i; @@ -156,3 +156,5 @@ typedef ForwardedTemplate<int> i;
typedef ForwardedTemplate<long> l;
template class TestSpecializationArguments<const TestASTEnumItemByName>;
constexpr void constExprNoExcept() noexcept;

Loading…
Cancel
Save