Browse Source

Fixed function types to provide qualified argument types in the AST.

We just parsed the function type "parameters" which does not even make sense from a type system point of view but it's useful in some instances in the generator when function types are "mappable" to function declarations.
pull/124/head
triton 12 years ago
parent
commit
70122b0568
  1. 4
      src/AST/ASTVisitor.cs
  2. 4
      src/AST/Function.cs
  3. 3
      src/AST/Type.cs
  4. 4
      src/CppParser/AST.h
  5. 36
      src/CppParser/Bindings/CLI/AST.cpp
  6. 9
      src/CppParser/Bindings/CLI/AST.h
  7. 43
      src/CppParser/Bindings/CSharp/AST.cs
  8. 13
      src/CppParser/Parser.cpp
  9. 2
      src/Generator/Generators/CLI/CLITypePrinter.cs
  10. 2
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  11. 13
      src/Parser/Parser.cpp

4
src/AST/ASTVisitor.cs

@ -95,8 +95,8 @@ namespace CppSharp.AST @@ -95,8 +95,8 @@ namespace CppSharp.AST
function.ReturnType.Visit(this);
if (Options.VisitFunctionParameters)
foreach (var param in function.Parameters)
param.Visit(this);
foreach (var arg in function.Arguments)
arg.Visit(this);
return true;
}

4
src/AST/Function.cs

@ -187,8 +187,8 @@ namespace CppSharp.AST @@ -187,8 +187,8 @@ namespace CppSharp.AST
CallingConvention = this.CallingConvention,
ReturnType = this.ReturnType
};
functionType.Parameters.AddRange(Parameters);
ReplaceIndirectReturnParamWithRegular(functionType);
var argTypes = Parameters.Select(parameter => parameter.QualifiedType);
functionType.Arguments.AddRange(argTypes);
var pointerType = new PointerType { QualifiedPointee = new QualifiedType(functionType) };
return new QualifiedType(pointerType);
}

3
src/AST/Type.cs

@ -317,12 +317,15 @@ namespace CppSharp.AST @@ -317,12 +317,15 @@ namespace CppSharp.AST
public QualifiedType ReturnType;
// Argument types.
public List<QualifiedType> Arguments;
public List<Parameter> Parameters;
public CallingConvention CallingConvention { get; set; }
public FunctionType()
{
Arguments = new List<QualifiedType>();
Parameters = new List<Parameter>();
}

4
src/CppParser/AST.h

@ -22,8 +22,8 @@ @@ -22,8 +22,8 @@
#define VECTOR(type, name) \
std::vector<type> name; \
type get##name(unsigned i) { return name[i]; } \
unsigned get##name##Count() { return name.size(); }
type get##name (unsigned i) { return name[i]; } \
unsigned get##name##Count () { return name.size(); }
namespace CppSharp { namespace CppParser { namespace AST {

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

@ -226,6 +226,19 @@ CppSharp::Parser::AST::FunctionType::FunctionType(System::IntPtr native) @@ -226,6 +226,19 @@ CppSharp::Parser::AST::FunctionType::FunctionType(System::IntPtr native)
auto __native = (::CppSharp::CppParser::AST::FunctionType*)native.ToPointer();
}
CppSharp::Parser::AST::QualifiedType^ CppSharp::Parser::AST::FunctionType::getArguments(unsigned int i)
{
auto __ret = ((::CppSharp::CppParser::AST::FunctionType*)NativePtr)->getArguments(i);
auto ____ret = new ::CppSharp::CppParser::AST::QualifiedType(__ret);
return gcnew CppSharp::Parser::AST::QualifiedType((::CppSharp::CppParser::AST::QualifiedType*)____ret);
}
unsigned int CppSharp::Parser::AST::FunctionType::getArgumentsCount()
{
auto __ret = ((::CppSharp::CppParser::AST::FunctionType*)NativePtr)->getArgumentsCount();
return __ret;
}
CppSharp::Parser::AST::Parameter^ CppSharp::Parser::AST::FunctionType::getParameters(unsigned int i)
{
auto __ret = ((::CppSharp::CppParser::AST::FunctionType*)NativePtr)->getParameters(i);
@ -265,6 +278,29 @@ void CppSharp::Parser::AST::FunctionType::CallingConvention::set(CppSharp::Parse @@ -265,6 +278,29 @@ void CppSharp::Parser::AST::FunctionType::CallingConvention::set(CppSharp::Parse
((::CppSharp::CppParser::AST::FunctionType*)NativePtr)->CallingConvention = (::CppSharp::CppParser::AST::CallingConvention)value;
}
System::Collections::Generic::List<CppSharp::Parser::AST::QualifiedType^>^ CppSharp::Parser::AST::FunctionType::Arguments::get()
{
auto _tmpArguments = gcnew System::Collections::Generic::List<CppSharp::Parser::AST::QualifiedType^>();
for(auto _element : ((::CppSharp::CppParser::AST::FunctionType*)NativePtr)->Arguments)
{
auto ___element = new ::CppSharp::CppParser::AST::QualifiedType(_element);
auto _marshalElement = gcnew CppSharp::Parser::AST::QualifiedType((::CppSharp::CppParser::AST::QualifiedType*)___element);
_tmpArguments->Add(_marshalElement);
}
return _tmpArguments;
}
void CppSharp::Parser::AST::FunctionType::Arguments::set(System::Collections::Generic::List<CppSharp::Parser::AST::QualifiedType^>^ value)
{
auto _tmpvalue = std::vector<::CppSharp::CppParser::AST::QualifiedType>();
for each(CppSharp::Parser::AST::QualifiedType^ _element in value)
{
auto _marshalElement = *(::CppSharp::CppParser::AST::QualifiedType*)_element->NativePtr;
_tmpvalue.push_back(_marshalElement);
}
((::CppSharp::CppParser::AST::FunctionType*)NativePtr)->Arguments = _tmpvalue;
}
System::Collections::Generic::List<CppSharp::Parser::AST::Parameter^>^ CppSharp::Parser::AST::FunctionType::Parameters::get()
{
auto _tmpParameters = gcnew System::Collections::Generic::List<CppSharp::Parser::AST::Parameter^>();

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

@ -359,11 +359,20 @@ namespace CppSharp @@ -359,11 +359,20 @@ namespace CppSharp
CppSharp::Parser::AST::CallingConvention get();
void set(CppSharp::Parser::AST::CallingConvention);
}
property System::Collections::Generic::List<CppSharp::Parser::AST::QualifiedType^>^ Arguments
{
System::Collections::Generic::List<CppSharp::Parser::AST::QualifiedType^>^ get();
void set(System::Collections::Generic::List<CppSharp::Parser::AST::QualifiedType^>^);
}
property System::Collections::Generic::List<CppSharp::Parser::AST::Parameter^>^ Parameters
{
System::Collections::Generic::List<CppSharp::Parser::AST::Parameter^>^ get();
void set(System::Collections::Generic::List<CppSharp::Parser::AST::Parameter^>^);
}
CppSharp::Parser::AST::QualifiedType^ getArguments(unsigned int i);
unsigned int getArgumentsCount();
CppSharp::Parser::AST::Parameter^ getParameters(unsigned int i);
unsigned int getParametersCount();

43
src/CppParser/Bindings/CSharp/AST.cs

@ -632,6 +632,9 @@ namespace CppSharp @@ -632,6 +632,9 @@ namespace CppSharp
[FieldOffset(12)]
public CppSharp.Parser.AST.CallingConvention CallingConvention;
[FieldOffset(16)]
public Std.Vector Arguments;
[FieldOffset(28)]
public Std.Vector Parameters;
@ -645,6 +648,16 @@ namespace CppSharp @@ -645,6 +648,16 @@ namespace CppSharp
EntryPoint="??0FunctionType@AST@CppParser@CppSharp@@QAE@ABU0123@@Z")]
internal static extern global::System.IntPtr FunctionType_2(global::System.IntPtr instance, global::System.IntPtr _0);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="?getArguments@FunctionType@AST@CppParser@CppSharp@@QAE?AUQualifiedType@234@I@Z")]
internal static extern void getArguments_0(global::System.IntPtr instance, global::System.IntPtr __return, uint i);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="?getArgumentsCount@FunctionType@AST@CppParser@CppSharp@@QAEIXZ")]
internal static extern uint getArgumentsCount_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="?getParameters@FunctionType@AST@CppParser@CppSharp@@QAEPAUParameter@234@I@Z")]
@ -696,6 +709,21 @@ namespace CppSharp @@ -696,6 +709,21 @@ namespace CppSharp
base.Dispose(disposing);
}
public CppSharp.Parser.AST.QualifiedType getArguments(uint i)
{
var __ret = new CppSharp.Parser.AST.QualifiedType.Internal();
Internal.getArguments_0(__Instance, new IntPtr(&__ret), i);
var __instance = Marshal.AllocHGlobal(8);
CppSharp.Runtime.Helpers.memcpy(__instance, new IntPtr(&__ret), new UIntPtr(8));
return new CppSharp.Parser.AST.QualifiedType(__instance);
}
public uint getArgumentsCount()
{
var __ret = Internal.getArgumentsCount_0(__Instance);
return __ret;
}
public CppSharp.Parser.AST.Parameter getParameters(uint i)
{
var __ret = Internal.getParameters_0(__Instance, i);
@ -742,6 +770,21 @@ namespace CppSharp @@ -742,6 +770,21 @@ namespace CppSharp
}
}
public Std.Vector<CppSharp.Parser.AST.QualifiedType> Arguments
{
get
{
var __ptr = (Internal*)__Instance.ToPointer();
return new Std.Vector<CppSharp.Parser.AST.QualifiedType>(__ptr->Arguments);
}
set
{
var __ptr = (Internal*)__Instance.ToPointer();
__ptr->Arguments = value.Internal;
}
}
public Std.Vector<CppSharp.Parser.AST.Parameter> Parameters
{
get

13
src/CppParser/Parser.cpp

@ -1270,6 +1270,17 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1270,6 +1270,17 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
WalkType(FP->getResultType(), &RL));
F->CallingConvention = ConvertCallConv(FP->getCallConv());
for (auto I = FP->arg_type_begin(), E = FP->arg_type_end(); I != E;
++I)
{
auto Arg = *I;
auto Ty = GetQualifiedType(Arg, WalkType(Arg));
F->Arguments.push_back(Ty);
}
if (!FTL)
goto SkipParameters;
for (unsigned i = 0; i < FP->getNumArgs(); ++i)
{
auto PVD = FTL.getArg(i);
@ -1286,7 +1297,7 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1286,7 +1297,7 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
F->Parameters.push_back(FA);
}
return F;
SkipParameters:
Ty = F;
break;

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

@ -58,7 +58,7 @@ namespace CppSharp.Generators.CLI @@ -58,7 +58,7 @@ namespace CppSharp.Generators.CLI
public string VisitFunctionType(FunctionType function, TypeQualifiers quals)
{
var arguments = function.Parameters;
var arguments = function.Arguments;
var returnType = function.ReturnType;
var args = string.Empty;

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

@ -129,7 +129,7 @@ namespace CppSharp.Generators.CSharp @@ -129,7 +129,7 @@ namespace CppSharp.Generators.CSharp
public CSharpTypePrinterResult VisitFunctionType(FunctionType function,
TypeQualifiers quals)
{
var arguments = function.Parameters;
var arguments = function.Arguments;
var returnType = function.ReturnType;
var args = string.Empty;

13
src/Parser/Parser.cpp

@ -1386,6 +1386,17 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1386,6 +1386,17 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
WalkType(FP->getResultType(), &RL));
F->CallingConvention = ConvertCallConv(FP->getCallConv());
for (auto I = FP->arg_type_begin(), E = FP->arg_type_end(); I != E;
++I)
{
auto Arg = *I;
auto Ty = GetQualifiedType(Arg, WalkType(Arg));
F->Arguments->Add(Ty);
}
if (!FTL)
goto SkipParameters;
for (unsigned i = 0; i < FP->getNumArgs(); ++i)
{
auto PVD = FTL.getArg(i);
@ -1401,6 +1412,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1401,6 +1412,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
F->Parameters->Add(FA);
}
SkipParameters:
Ty = F;
break;
}

Loading…
Cancel
Save