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

5
src/AST/Type.cs

@ -244,7 +244,7 @@ namespace CppSharp.AST @@ -244,7 +244,7 @@ namespace CppSharp.AST
public QualifiedType ReturnType;
// Argument types.
public List<Parameter> Parameters;
public List<Parameter> Parameters { get; } = new List<Parameter>();
public CallingConvention CallingConvention { get; set; }
@ -252,14 +252,13 @@ namespace CppSharp.AST @@ -252,14 +252,13 @@ namespace CppSharp.AST
public FunctionType()
{
Parameters = new List<Parameter>();
}
public FunctionType(FunctionType type)
: base(type)
{
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;
}

11
src/Generator/Passes/CheckOperatorsOverloads.cs

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

19
src/Generator/Passes/DelegatesPass.cs

@ -104,19 +104,18 @@ namespace CppSharp.Passes @@ -104,19 +104,18 @@ namespace CppSharp.Passes
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,
QualifiedType = new QualifiedType(
new PointerType(
new QualifiedType(
new FunctionType
{
CallingConvention = callingConvention,
IsDependent = isDependent,
Parameters = @params,
ReturnType = returnType
}))),
new PointerType(new QualifiedType(functionType))),
Namespace = namespaceDelegates,
IsSynthetized = true,
Access = decl is Method ? AccessSpecifier.Private : AccessSpecifier.Public

8
src/Generator/Passes/FunctionToInstanceMethodPass.cs

@ -52,7 +52,6 @@ namespace CppSharp.Passes @@ -52,7 +52,6 @@ namespace CppSharp.Passes
Access = AccessSpecifier.Public,
Kind = CXXMethodKind.Normal,
ReturnType = function.ReturnType,
Parameters = function.Parameters,
CallingConvention = function.CallingConvention,
IsVariadic = function.IsVariadic,
IsInline = function.IsInline,
@ -60,8 +59,13 @@ namespace CppSharp.Passes @@ -60,8 +59,13 @@ namespace CppSharp.Passes
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)
method.Parameters = method.Parameters.Skip(1).ToList();
method.Parameters.RemoveAt(0);
@class.Methods.Add(method);

7
src/Generator/Passes/FunctionToStaticMethodPass.cs

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

5
src/Generator/Passes/ObjectOverridesPass.cs

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

Loading…
Cancel
Save