Browse Source

Added new property Parameter.Index.

Also added test which checks whether both parsers assign the AST parameter properties properly.
pull/237/head
Elias Holzer 11 years ago
parent
commit
749e5a399e
  1. 1
      src/AST/Function.cs
  2. 1
      src/Core/Parser/ASTConverter.cs
  3. 1
      src/CppParser/AST.h
  4. 10
      src/CppParser/Bindings/CLI/AST.cpp
  5. 6
      src/CppParser/Bindings/CLI/AST.h
  6. 22
      src/CppParser/Bindings/CSharp/AST.cs
  7. 1
      src/CppParser/Parser.cpp
  8. 61
      src/Generator.Tests/AST/TestAST.cs
  9. 1
      src/Parser/Parser.cpp
  10. 2
      tests/Native/AST.h

1
src/AST/Function.cs

@ -40,6 +40,7 @@ namespace CppSharp.AST @@ -40,6 +40,7 @@ namespace CppSharp.AST
public Type Type { get { return QualifiedType.Type; } }
public QualifiedType QualifiedType { get; set; }
public bool IsIndirect { get; set; }
public uint Index { get; set; }
public ParameterKind Kind { get; set; }
public ParameterUsage Usage { get; set; }

1
src/Core/Parser/ASTConverter.cs

@ -803,6 +803,7 @@ namespace CppSharp @@ -803,6 +803,7 @@ namespace CppSharp
_param.QualifiedType = typeConverter.VisitQualified(decl.QualifiedType);
_param.IsIndirect = decl.IsIndirect;
_param.HasDefaultValue = decl.HasDefaultValue;
_param.Index = decl.Index;
return _param;
}

1
src/CppParser/AST.h

@ -433,6 +433,7 @@ struct CS_API Parameter : public Declaration @@ -433,6 +433,7 @@ struct CS_API Parameter : public Declaration
CppSharp::CppParser::AST::QualifiedType QualifiedType;
bool IsIndirect;
bool HasDefaultValue;
unsigned int Index;
};
enum struct CXXMethodKind

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

@ -1459,6 +1459,16 @@ void CppSharp::Parser::AST::Parameter::HasDefaultValue::set(bool value) @@ -1459,6 +1459,16 @@ void CppSharp::Parser::AST::Parameter::HasDefaultValue::set(bool value)
((::CppSharp::CppParser::AST::Parameter*)NativePtr)->HasDefaultValue = value;
}
unsigned int CppSharp::Parser::AST::Parameter::Index::get()
{
return ((::CppSharp::CppParser::AST::Parameter*)NativePtr)->Index;
}
void CppSharp::Parser::AST::Parameter::Index::set(unsigned int value)
{
((::CppSharp::CppParser::AST::Parameter*)NativePtr)->Index = value;
}
CppSharp::Parser::AST::Function::Function(::CppSharp::CppParser::AST::Function* native)
: CppSharp::Parser::AST::Declaration((::CppSharp::CppParser::AST::Declaration*)native)
{

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

@ -1120,6 +1120,12 @@ namespace CppSharp @@ -1120,6 +1120,12 @@ namespace CppSharp
bool get();
void set(bool);
}
property unsigned int Index
{
unsigned int get();
void set(unsigned int);
}
};
public ref class Function : CppSharp::Parser::AST::Declaration

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

@ -3389,7 +3389,7 @@ namespace CppSharp @@ -3389,7 +3389,7 @@ namespace CppSharp
public unsafe partial class Parameter : CppSharp.Parser.AST.Declaration, IDisposable
{
[StructLayout(LayoutKind.Explicit, Size = 104)]
[StructLayout(LayoutKind.Explicit, Size = 108)]
public new struct Internal
{
[FieldOffset(0)]
@ -3437,6 +3437,9 @@ namespace CppSharp @@ -3437,6 +3437,9 @@ namespace CppSharp
[FieldOffset(101)]
internal bool HasDefaultValue;
[FieldOffset(104)]
internal uint Index;
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="??0Parameter@AST@CppParser@CppSharp@@QAE@XZ")]
@ -3471,7 +3474,7 @@ namespace CppSharp @@ -3471,7 +3474,7 @@ namespace CppSharp
public Parameter()
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(104);
__Instance = Marshal.AllocHGlobal(108);
Internal.ctor_0(__Instance);
}
@ -3526,6 +3529,21 @@ namespace CppSharp @@ -3526,6 +3529,21 @@ namespace CppSharp
__ptr->HasDefaultValue = value;
}
}
public uint Index
{
get
{
var __ptr = (Internal*)__Instance.ToPointer();
return __ptr->Index;
}
set
{
var __ptr = (Internal*)__Instance.ToPointer();
__ptr->Index = value;
}
}
}
public unsafe partial class Function : CppSharp.Parser.AST.Declaration, IDisposable

1
src/CppParser/Parser.cpp

@ -1885,6 +1885,7 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Function* F, @@ -1885,6 +1885,7 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Function* F,
P->QualifiedType = GetQualifiedType(VD->getType(), WalkType(VD->getType(), &PTL));
P->HasDefaultValue = VD->hasDefaultArg();
P->_Namespace = NS;
P->Index = VD->getFunctionScopeIndex();
HandleDeclaration(VD, P);
F->Parameters.push_back(P);

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

@ -0,0 +1,61 @@ @@ -0,0 +1,61 @@
using System.Linq;
using CppSharp.Passes;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using NUnit.Framework;
namespace CppSharp.Generator.Tests.AST
{
[TestFixture]
public class TestAST : ASTTestFixture
{
private PassBuilder<TranslationUnitPass> passBuilder;
[TestFixtureSetUp]
public void Init()
{
}
[SetUp]
public void Setup()
{
ParseLibrary("AST.h");
passBuilder = new PassBuilder<TranslationUnitPass>(Driver);
}
[Test]
public void TestASTParameter()
{
var func = AstContext.FindFunction("TestParameterProperties").FirstOrDefault();
Assert.IsNotNull(func);
var paramNames = new [] { "a", "b", "c" };
var paramTypes = new []
{
new QualifiedType(new BuiltinType(PrimitiveType.Bool)),
new QualifiedType(
new PointerType()
{
Modifier = PointerType.TypeModifier.LVReference,
QualifiedPointee = new QualifiedType(
new BuiltinType(PrimitiveType.Int16),
new TypeQualifiers() { IsConst = true })
}),
new QualifiedType(
new PointerType()
{
Modifier = PointerType.TypeModifier.Pointer,
QualifiedPointee = new QualifiedType(new BuiltinType(PrimitiveType.Int32))
})
};
for (int i = 0; i < func.Parameters.Count; i++)
{
var param = func.Parameters[i];
Assert.AreEqual(paramNames[i], param.Name, "Parameter.Name");
Assert.AreEqual(paramTypes[i], param.QualifiedType, "Parameter.QualifiedType");
Assert.AreEqual(i, param.Index, "Parameter.Index");
}
Assert.IsTrue(func.Parameters[2].HasDefaultValue, "Parameter.HasDefaultValue");
}
}
}

1
src/Parser/Parser.cpp

@ -1900,6 +1900,7 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, CppSharp::AST::Function^ F, @@ -1900,6 +1900,7 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, CppSharp::AST::Function^ F,
P->QualifiedType = GetQualifiedType(VD->getType(), WalkType(VD->getType(), &PTL));
P->HasDefaultValue = VD->hasDefaultArg();
P->Namespace = NS;
P->Index = VD->getFunctionScopeIndex();
HandleDeclaration(VD, P);
F->Parameters->Add(P);

2
tests/Native/AST.h

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
// Tests assignment of AST.Parameter properties
void TestParameterProperties(bool a, const short& b, int* c = nullptr) {};
Loading…
Cancel
Save