Browse Source

Merge pull request #271 from ddobrev/def_vals

Some refactoring in preparation for the default values of parameters
pull/272/head
João Matos 11 years ago
parent
commit
6310ce6ecc
  1. 2
      src/AST/Enumeration.cs
  2. 7
      src/AST/Function.cs
  3. 4
      src/AST/Method.cs
  4. 2
      src/CppParser/AST.cpp
  5. 2
      src/CppParser/AST.h
  6. 6
      src/CppParser/Bindings/CLI/AST.cpp
  7. 2
      src/CppParser/Bindings/CLI/AST.h
  8. 15
      src/CppParser/Bindings/CSharp/i686-pc-win32/AST.cs
  9. 48
      src/CppParser/Parser.cpp
  10. 1
      src/CppParser/Parser.h
  11. 27
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  12. 2
      src/Generator/Passes/CheckOperatorsOverloads.cs
  13. 3
      src/Generator/Passes/ConstructorToConversionOperatorPass.cs
  14. 2
      src/Generator/Passes/GenerateAbstractImplementationsPass.cs
  15. 6
      src/Generator/Passes/ObjectOverridesPass.cs

2
src/AST/Enumeration.cs

@ -6,7 +6,7 @@ namespace CppSharp.AST @@ -6,7 +6,7 @@ namespace CppSharp.AST
/// <summary>
/// Represents a C/C++ enumeration declaration.
/// </summary>
public class Enumeration : Declaration
public class Enumeration : DeclarationContext
{
[Flags]
public enum EnumModifiers

7
src/AST/Function.cs

@ -88,7 +88,10 @@ namespace CppSharp.AST @@ -88,7 +88,10 @@ namespace CppSharp.AST
public enum FunctionSynthKind
{
None,
NonMemberOperator
NonMemberOperator,
ComplementOperator,
AbstractImplCall,
DefaultValueOverload
}
public class Function : Declaration, ITypedDecl, IMangledDecl
@ -109,7 +112,7 @@ namespace CppSharp.AST @@ -109,7 +112,7 @@ namespace CppSharp.AST
Parameters = new List<Parameter>();
ReturnType = function.ReturnType;
IsReturnIndirect = function.IsReturnIndirect;
Parameters.AddRange(function.Parameters);
Parameters.AddRange(function.Parameters.Select(p => new Parameter(p)));
IsVariadic = function.IsVariadic;
IsInline = function.IsInline;
IsPure = function.IsPure;

4
src/AST/Method.cs

@ -86,7 +86,6 @@ namespace CppSharp.AST @@ -86,7 +86,6 @@ namespace CppSharp.AST
IsVirtual = method.IsVirtual;
IsConst = method.IsConst;
IsImplicit = method.IsImplicit;
IsSynthetized = method.IsSynthetized;
IsOverride = method.IsOverride;
IsProxy = method.IsProxy;
Kind = method.Kind;
@ -94,6 +93,7 @@ namespace CppSharp.AST @@ -94,6 +93,7 @@ namespace CppSharp.AST
IsCopyConstructor = method.IsCopyConstructor;
IsMoveConstructor = method.IsMoveConstructor;
Conversion = method.Conversion;
SynthKind = method.SynthKind;
}
public Method(Function function)
@ -109,7 +109,7 @@ namespace CppSharp.AST @@ -109,7 +109,7 @@ namespace CppSharp.AST
public bool IsConst { get; set; }
public bool IsImplicit { get; set; }
public bool IsExplicit { get; set; }
public bool IsSynthetized { get; set; }
public bool IsSynthetized { get { return SynthKind != FunctionSynthKind.None; } }
public bool IsOverride { get; set; }
public bool IsProxy { get; set; }

2
src/CppParser/AST.cpp

@ -450,7 +450,7 @@ Method::Method() @@ -450,7 +450,7 @@ Method::Method()
// Enumeration
Enumeration::Enumeration() : Declaration(DeclarationKind::Enumeration),
Enumeration::Enumeration() : DeclarationContext(DeclarationKind::Enumeration),
Modifiers((EnumModifiers)0), Type(0), BuiltinType(0) {}
DEF_VECTOR(Enumeration, Enumeration::Item, Items)

2
src/CppParser/AST.h

@ -548,7 +548,7 @@ struct CS_API Method : public Function @@ -548,7 +548,7 @@ struct CS_API Method : public Function
QualifiedType ConversionType;
};
struct CS_API Enumeration : public Declaration
struct CS_API Enumeration : public DeclarationContext
{
DECLARE_DECL_KIND(Enumeration, Enumeration)

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

@ -1855,18 +1855,18 @@ void CppSharp::Parser::AST::Enumeration::Item::Value::set(unsigned long long val @@ -1855,18 +1855,18 @@ void CppSharp::Parser::AST::Enumeration::Item::Value::set(unsigned long long val
}
CppSharp::Parser::AST::Enumeration::Enumeration(::CppSharp::CppParser::AST::Enumeration* native)
: CppSharp::Parser::AST::Declaration((::CppSharp::CppParser::AST::Declaration*)native)
: CppSharp::Parser::AST::DeclarationContext((::CppSharp::CppParser::AST::DeclarationContext*)native)
{
}
CppSharp::Parser::AST::Enumeration::Enumeration(System::IntPtr native)
: CppSharp::Parser::AST::Declaration(native)
: CppSharp::Parser::AST::DeclarationContext(native)
{
auto __native = (::CppSharp::CppParser::AST::Enumeration*)native.ToPointer();
}
CppSharp::Parser::AST::Enumeration::Enumeration()
: CppSharp::Parser::AST::Declaration((::CppSharp::CppParser::AST::Declaration*)nullptr)
: CppSharp::Parser::AST::DeclarationContext((::CppSharp::CppParser::AST::DeclarationContext*)nullptr)
{
NativePtr = new ::CppSharp::CppParser::AST::Enumeration();
}

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

@ -1325,7 +1325,7 @@ namespace CppSharp @@ -1325,7 +1325,7 @@ namespace CppSharp
}
};
public ref class Enumeration : CppSharp::Parser::AST::Declaration
public ref class Enumeration : CppSharp::Parser::AST::DeclarationContext
{
public:

15
src/CppParser/Bindings/CSharp/i686-pc-win32/AST.cs

@ -4222,9 +4222,9 @@ namespace CppSharp @@ -4222,9 +4222,9 @@ namespace CppSharp
}
}
public unsafe partial class Enumeration : CppSharp.Parser.AST.Declaration, IDisposable
public unsafe partial class Enumeration : CppSharp.Parser.AST.DeclarationContext, IDisposable
{
[StructLayout(LayoutKind.Explicit, Size = 144)]
[StructLayout(LayoutKind.Explicit, Size = 240)]
public new struct Internal
{
[FieldOffset(0)]
@ -4257,13 +4257,16 @@ namespace CppSharp @@ -4257,13 +4257,16 @@ namespace CppSharp
[FieldOffset(92)]
public void* OriginalPtr;
[FieldOffset(120)]
[FieldOffset(212)]
public bool IsAnonymous;
[FieldOffset(216)]
public CppSharp.Parser.AST.Enumeration.EnumModifiers Modifiers;
[FieldOffset(124)]
[FieldOffset(220)]
public global::System.IntPtr Type;
[FieldOffset(128)]
[FieldOffset(224)]
public global::System.IntPtr BuiltinType;
[SuppressUnmanagedCodeSecurity]
@ -4447,7 +4450,7 @@ namespace CppSharp @@ -4447,7 +4450,7 @@ namespace CppSharp
public Enumeration()
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(144);
__Instance = Marshal.AllocHGlobal(240);
Internal.ctor_0(__Instance);
}

48
src/CppParser/Parser.cpp

@ -1349,6 +1349,12 @@ DeclarationContext* Parser::GetNamespace(clang::Decl* D, @@ -1349,6 +1349,12 @@ DeclarationContext* Parser::GetNamespace(clang::Decl* D,
DC = WalkClassTemplatePartialSpecialization(CTPSpec);
continue;
}
case Decl::Enum:
{
auto CTPSpec = cast<EnumDecl>(Ctx);
DC = WalkEnum(CTPSpec);
continue;
}
default:
{
StringRef Kind = Ctx->getDeclKindName();
@ -2006,24 +2012,28 @@ Enumeration* Parser::WalkEnum(clang::EnumDecl* ED) @@ -2006,24 +2012,28 @@ Enumeration* Parser::WalkEnum(clang::EnumDecl* ED)
E->IsIncomplete = false;
for(auto it = ED->enumerator_begin(); it != ED->enumerator_end(); ++it)
{
clang::EnumConstantDecl* ECD = (*it);
E->Items.push_back(*WalkEnumItem(*it));
}
return E;
}
auto EnumItem = Enumeration::Item();
HandleDeclaration(ECD, &EnumItem);
Enumeration::Item* Parser::WalkEnumItem(clang::EnumConstantDecl* ECD)
{
auto EnumItem = new Enumeration::Item();
HandleDeclaration(ECD, EnumItem);
EnumItem.Name = ECD->getNameAsString();
EnumItem->Name = ECD->getNameAsString();
auto Value = ECD->getInitVal();
EnumItem.Value = Value.isSigned() ? Value.getSExtValue()
EnumItem->Value = Value.isSigned() ? Value.getSExtValue()
: Value.getZExtValue();
EnumItem->_Namespace = GetNamespace(ECD);
std::string Text;
if (GetDeclText(ECD->getSourceRange(), Text))
EnumItem.Expression = Text;
EnumItem->Expression = Text;
E->Items.push_back(EnumItem);
}
return E;
return EnumItem;
}
//-----------------------------------//
@ -2615,10 +2625,16 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D, @@ -2615,10 +2625,16 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D,
}
case Decl::Enum:
{
EnumDecl* ED = cast<EnumDecl>(D);
auto ED = cast<EnumDecl>(D);
Decl = WalkEnum(ED);
break;
}
case Decl::EnumConstant:
{
auto ED = cast<EnumConstantDecl>(D);
Decl = WalkEnumItem(ED);
break;
}
case Decl::Function:
{
FunctionDecl* FD = cast<FunctionDecl>(D);
@ -2685,9 +2701,17 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D, @@ -2685,9 +2701,17 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D,
NS->Variables.push_back(static_cast<Variable*>(Decl));
break;
}
case Decl::CXXConstructor:
{
auto MD = cast<CXXMethodDecl>(D);
Decl = WalkMethodCXX(MD);
auto NS = GetNamespace(MD);
Decl->_Namespace = NS;
break;
}
// Ignore these declarations since they must have been declared in
// a class already.
case Decl::CXXConstructor:
case Decl::CXXDestructor:
case Decl::CXXConversion:
case Decl::CXXMethod:

1
src/CppParser/Parser.h

@ -63,6 +63,7 @@ protected: @@ -63,6 +63,7 @@ protected:
bool IgnoreSystemDecls = true, bool CanBeDefinition = false);
Declaration* WalkDeclarationDef(clang::Decl* D);
Enumeration* WalkEnum(clang::EnumDecl* ED);
Enumeration::Item* WalkEnumItem(clang::EnumConstantDecl* ECD);
Function* WalkFunction(clang::FunctionDecl* FD, bool IsDependent = false,
bool AddToNamespace = true);
Class* GetRecord(clang::RecordDecl* Record, bool& IsComplete);

27
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -471,13 +471,14 @@ namespace CppSharp.Generators.CSharp @@ -471,13 +471,14 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.BeforeNextBlock);
}
private ISet<Function> GatherClassInternalFunctions(Class @class)
private IEnumerable<Function> GatherClassInternalFunctions(Class @class)
{
var functions = new HashSet<Function>();
Action<Method> tryAddOverload = method =>
{
if (method.IsSynthetized)
if (method.SynthKind != FunctionSynthKind.NonMemberOperator &&
method.SynthKind != FunctionSynthKind.None)
return;
if (method.IsProxy)
@ -884,9 +885,9 @@ namespace CppSharp.Generators.CSharp @@ -884,9 +885,9 @@ namespace CppSharp.Generators.CSharp
var method = function as Method;
if (method != null && method.OperatorKind == CXXOperatorKind.Subscript)
{
if (method.IsOverride && method.IsSynthetized)
if (method.SynthKind == FunctionSynthKind.AbstractImplCall)
{
GenerateVirtualTableFunctionCall(method, @class);
GenerateAbstractImplCall(method, @class);
}
else
{
@ -1010,8 +1011,8 @@ namespace CppSharp.Generators.CSharp @@ -1010,8 +1011,8 @@ namespace CppSharp.Generators.CSharp
NewLine();
WriteStartBraceIndent();
var method = function as Method;
if (method != null && method.IsOverride && method.IsSynthetized)
GenerateVirtualTableFunctionCall(method, @class);
if (method != null && method.SynthKind == FunctionSynthKind.AbstractImplCall)
GenerateAbstractImplCall(method, @class);
else
GenerateInternalFunctionCall(function, function.Parameters, returnType.Type);
}
@ -1886,7 +1887,7 @@ namespace CppSharp.Generators.CSharp @@ -1886,7 +1887,7 @@ namespace CppSharp.Generators.CSharp
var hasBaseClass = @class.HasBaseClass && @class.BaseClass.IsRefType;
if (hasBaseClass)
WriteLineIndent(": base(native{0})",
@class.Methods.Any(m => !m.IsPure && m.IsOverride && m.IsSynthetized) ?
@class.Methods.Any(m => m.SynthKind == FunctionSynthKind.AbstractImplCall) ?
", true" : string.Empty);
WriteStartBraceIndent();
@ -2043,9 +2044,9 @@ namespace CppSharp.Generators.CSharp @@ -2043,9 +2044,9 @@ namespace CppSharp.Generators.CSharp
{
GenerateOperator(method, @class);
}
else if (method.IsOverride && method.IsSynthetized)
else if (method.SynthKind == FunctionSynthKind.AbstractImplCall)
{
GenerateVirtualTableFunctionCall(method, @class);
GenerateAbstractImplCall(method, @class);
}
else
{
@ -2101,14 +2102,14 @@ namespace CppSharp.Generators.CSharp @@ -2101,14 +2102,14 @@ namespace CppSharp.Generators.CSharp
}
}
private void GenerateVirtualTableFunctionCall(Method method, Class @class)
private void GenerateAbstractImplCall(Method method, Class @class)
{
string delegateId;
Write(GetVirtualCallDelegate(method, @class, out delegateId));
Write(GetAbstractCallDelegate(method, @class, out delegateId));
GenerateFunctionCall(delegateId, method.Parameters, method);
}
public string GetVirtualCallDelegate(Method method, Class @class,
public string GetAbstractCallDelegate(Method method, Class @class,
out string delegateId)
{
var virtualCallBuilder = new StringBuilder();
@ -2129,7 +2130,7 @@ namespace CppSharp.Generators.CSharp @@ -2129,7 +2130,7 @@ namespace CppSharp.Generators.CSharp
private void GenerateOperator(Method method, Class @class)
{
if (method.IsSynthetized)
if (method.SynthKind == FunctionSynthKind.ComplementOperator)
{
if (method.Kind == CXXMethodKind.Conversion)
{

2
src/Generator/Passes/CheckOperatorsOverloads.cs

@ -140,7 +140,7 @@ namespace CppSharp.Passes @@ -140,7 +140,7 @@ namespace CppSharp.Passes
{
Name = Operators.GetOperatorIdentifier(missingKind),
Namespace = @class,
IsSynthetized = true,
SynthKind = FunctionSynthKind.ComplementOperator,
Kind = CXXMethodKind.Operator,
OperatorKind = missingKind,
ReturnType = op.ReturnType,

3
src/Generator/Passes/ConstructorToConversionOperatorPass.cs

@ -1,7 +1,6 @@ @@ -1,7 +1,6 @@
using System.Linq;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators;
namespace CppSharp.Passes
{
@ -45,7 +44,7 @@ namespace CppSharp.Passes @@ -45,7 +44,7 @@ namespace CppSharp.Passes
Name = Operators.GetOperatorIdentifier(operatorKind),
Namespace = castFromClass,
Kind = CXXMethodKind.Conversion,
IsSynthetized = true,
SynthKind = FunctionSynthKind.ComplementOperator,
ConversionType = qualifiedCastToType,
ReturnType = qualifiedCastToType
};

2
src/Generator/Passes/GenerateAbstractImplementationsPass.cs

@ -70,7 +70,7 @@ namespace CppSharp.Passes @@ -70,7 +70,7 @@ namespace CppSharp.Passes
OriginalFunction = method,
IsPure = false,
IsOverride = true,
IsSynthetized = true
SynthKind = FunctionSynthKind.AbstractImplCall
});
internalImpl.Layout = new ClassLayout(@class.Layout);

6
src/Generator/Passes/ObjectOverridesPass.cs

@ -119,7 +119,7 @@ namespace CppSharp @@ -119,7 +119,7 @@ namespace CppSharp
Name = "ToString",
Namespace = @class,
ReturnType = new QualifiedType(stringType),
IsSynthetized = true,
SynthKind = FunctionSynthKind.NonMemberOperator,
IsOverride = true,
IsProxy = true
};
@ -144,7 +144,7 @@ namespace CppSharp @@ -144,7 +144,7 @@ namespace CppSharp
Namespace = @class,
ReturnType = new QualifiedType(new BuiltinType(PrimitiveType.Bool)),
Parameters = new List<Parameter> { methodEqualsParam },
IsSynthetized = true,
SynthKind = FunctionSynthKind.ComplementOperator,
IsOverride = true,
IsProxy = true
};
@ -155,7 +155,7 @@ namespace CppSharp @@ -155,7 +155,7 @@ namespace CppSharp
Name = "GetHashCode",
Namespace = @class,
ReturnType = new QualifiedType(new BuiltinType(PrimitiveType.Int)),
IsSynthetized = true,
SynthKind = FunctionSynthKind.ComplementOperator,
IsOverride = true,
IsProxy = true
};

Loading…
Cancel
Save