Browse Source

Made all lists of parameters read-only.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/921/head
Dimitar Dobrev 8 years ago
parent
commit
649df6e5e7
  1. 4
      src/AST/Function.cs
  2. 5
      src/AST/Type.cs
  3. 11
      src/Generator/Passes/CheckOperatorsOverloads.cs
  4. 19
      src/Generator/Passes/DelegatesPass.cs
  5. 8
      src/Generator/Passes/FunctionToInstanceMethodPass.cs
  6. 7
      src/Generator/Passes/FunctionToStaticMethodPass.cs
  7. 5
      src/Generator/Passes/ObjectOverridesPass.cs

4
src/AST/Function.cs

@ -142,7 +142,6 @@ namespace CppSharp.AST
{ {
public Function() public Function()
{ {
Parameters = new List<Parameter>();
CallingConvention = CallingConvention.Default; CallingConvention = CallingConvention.Default;
Signature = string.Empty; Signature = string.Empty;
} }
@ -150,7 +149,6 @@ namespace CppSharp.AST
public Function(Function function) public Function(Function function)
: base(function) : base(function)
{ {
Parameters = new List<Parameter>();
ReturnType = function.ReturnType; ReturnType = function.ReturnType;
IsReturnIndirect = function.IsReturnIndirect; IsReturnIndirect = function.IsReturnIndirect;
HasThisReturn = function.HasThisReturn; HasThisReturn = function.HasThisReturn;
@ -180,7 +178,7 @@ namespace CppSharp.AST
public bool IsReturnIndirect { get; set; } public bool IsReturnIndirect { get; set; }
public bool HasThisReturn { get; set; } public bool HasThisReturn { get; set; }
public List<Parameter> Parameters { get; set; } public List<Parameter> Parameters { get; } = new List<Parameter>();
public bool IsConstExpr { get; set; } public bool IsConstExpr { get; set; }
public bool IsVariadic { get; set; } public bool IsVariadic { get; set; }
public bool IsInline { get; set; } public bool IsInline { get; set; }

5
src/AST/Type.cs

@ -244,7 +244,7 @@ namespace CppSharp.AST
public QualifiedType ReturnType; public QualifiedType ReturnType;
// Argument types. // Argument types.
public List<Parameter> Parameters; public List<Parameter> Parameters { get; } = new List<Parameter>();
public CallingConvention CallingConvention { get; set; } public CallingConvention CallingConvention { get; set; }
@ -252,14 +252,13 @@ namespace CppSharp.AST
public FunctionType() public FunctionType()
{ {
Parameters = new List<Parameter>();
} }
public FunctionType(FunctionType type) public FunctionType(FunctionType type)
: base(type) : base(type)
{ {
ReturnType = new QualifiedType((Type) type.ReturnType.Type.Clone(), type.ReturnType.Qualifiers); ReturnType = new QualifiedType((Type) type.ReturnType.Type.Clone(), type.ReturnType.Qualifiers);
Parameters = type.Parameters.Select(p => new Parameter(p)).ToList(); Parameters.AddRange(type.Parameters.Select(p => new Parameter(p)).ToList());
CallingConvention = type.CallingConvention; CallingConvention = type.CallingConvention;
} }

11
src/Generator/Passes/CheckOperatorsOverloads.cs

@ -70,7 +70,7 @@ namespace CppSharp.Passes
private static void CreateOperator(Class @class, Method @operator) private static void CreateOperator(Class @class, Method @operator)
{ {
if (@operator.IsStatic) if (@operator.IsStatic)
@operator.Parameters = @operator.Parameters.Skip(1).ToList(); @operator.Parameters.RemoveAt(0);
if (@operator.ConversionType.Type == null || @operator.Parameters.Count == 0) if (@operator.ConversionType.Type == null || @operator.Parameters.Count == 0)
{ {
@ -148,10 +148,15 @@ namespace CppSharp.Passes
SynthKind = FunctionSynthKind.ComplementOperator, SynthKind = FunctionSynthKind.ComplementOperator,
Kind = CXXMethodKind.Operator, Kind = CXXMethodKind.Operator,
OperatorKind = missingKind, OperatorKind = missingKind,
ReturnType = op.ReturnType, ReturnType = op.ReturnType
Parameters = op.Parameters
}; };
foreach (var parameter in op.Parameters)
{
var newParameter = new Parameter(parameter) { Namespace = method };
method.Parameters.Add(newParameter);
}
@class.Methods.Insert(index, method); @class.Methods.Insert(index, method);
} }
} }

19
src/Generator/Passes/DelegatesPass.cs

@ -104,19 +104,18 @@ namespace CppSharp.Passes
namespacesDelegates.Add(module, namespaceDelegates); namespacesDelegates.Add(module, namespaceDelegates);
} }
var @delegate = new TypedefDecl var functionType = new FunctionType
{ {
CallingConvention = callingConvention,
IsDependent = isDependent,
ReturnType = returnType
};
functionType.Parameters.AddRange(@params);
var @delegate = new TypedefDecl
{
Name = delegateName, Name = delegateName,
QualifiedType = new QualifiedType( QualifiedType = new QualifiedType(
new PointerType( new PointerType(new QualifiedType(functionType))),
new QualifiedType(
new FunctionType
{
CallingConvention = callingConvention,
IsDependent = isDependent,
Parameters = @params,
ReturnType = returnType
}))),
Namespace = namespaceDelegates, Namespace = namespaceDelegates,
IsSynthetized = true, IsSynthetized = true,
Access = decl is Method ? AccessSpecifier.Private : AccessSpecifier.Public Access = decl is Method ? AccessSpecifier.Private : AccessSpecifier.Public

8
src/Generator/Passes/FunctionToInstanceMethodPass.cs

@ -52,7 +52,6 @@ namespace CppSharp.Passes
Access = AccessSpecifier.Public, Access = AccessSpecifier.Public,
Kind = CXXMethodKind.Normal, Kind = CXXMethodKind.Normal,
ReturnType = function.ReturnType, ReturnType = function.ReturnType,
Parameters = function.Parameters,
CallingConvention = function.CallingConvention, CallingConvention = function.CallingConvention,
IsVariadic = function.IsVariadic, IsVariadic = function.IsVariadic,
IsInline = function.IsInline, IsInline = function.IsInline,
@ -60,8 +59,13 @@ namespace CppSharp.Passes
FunctionType = function.FunctionType FunctionType = function.FunctionType
}; };
foreach (var parameter in function.Parameters)
{
var newParameter = new Parameter(parameter) { Namespace = method };
method.Parameters.Add(newParameter);
}
if (Options.GeneratorKind == GeneratorKind.CSharp) if (Options.GeneratorKind == GeneratorKind.CSharp)
method.Parameters = method.Parameters.Skip(1).ToList(); method.Parameters.RemoveAt(0);
@class.Methods.Add(method); @class.Methods.Add(method);

7
src/Generator/Passes/FunctionToStaticMethodPass.cs

@ -46,7 +46,6 @@ namespace CppSharp.Passes
Access = AccessSpecifier.Public, Access = AccessSpecifier.Public,
Kind = CXXMethodKind.Normal, Kind = CXXMethodKind.Normal,
ReturnType = function.ReturnType, ReturnType = function.ReturnType,
Parameters = function.Parameters,
CallingConvention = function.CallingConvention, CallingConvention = function.CallingConvention,
IsVariadic = function.IsVariadic, IsVariadic = function.IsVariadic,
IsInline = function.IsInline, IsInline = function.IsInline,
@ -54,6 +53,12 @@ namespace CppSharp.Passes
Conversion = MethodConversionKind.FunctionToStaticMethod Conversion = MethodConversionKind.FunctionToStaticMethod
}; };
foreach (var parameter in function.Parameters)
{
var newParameter = new Parameter(parameter) { Namespace = method };
method.Parameters.Add(newParameter);
}
@class.Methods.Add(method); @class.Methods.Add(method);
Diagnostics.Debug("Function converted to static method: {0}::{1}", Diagnostics.Debug("Function converted to static method: {0}::{1}",

5
src/Generator/Passes/ObjectOverridesPass.cs

@ -149,10 +149,13 @@ namespace CppSharp
Name = "Equals", Name = "Equals",
Namespace = @class, Namespace = @class,
ReturnType = new QualifiedType(new BuiltinType(PrimitiveType.Bool)), ReturnType = new QualifiedType(new BuiltinType(PrimitiveType.Bool)),
Parameters = new List<Parameter> { methodEqualsParam },
SynthKind = FunctionSynthKind.ComplementOperator, SynthKind = FunctionSynthKind.ComplementOperator,
IsProxy = true IsProxy = true
}; };
methodEqualsParam.Namespace = methodEquals;
methodEquals.Parameters.Add(methodEqualsParam);
methodEquals.OverriddenMethods.Add(new Method { Name = "Equals" }); methodEquals.OverriddenMethods.Add(new Method { Name = "Equals" });
@class.Methods.Add(methodEquals); @class.Methods.Add(methodEquals);

Loading…
Cancel
Save