Permalink
Browse files

Made all lists of parameters read-only.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Aug 24, 2017
1 parent 7db6104 commit 649df6e5e7167ff4ede1a4c41fe619497ab292f9
@@ -142,15 +142,13 @@ public class Function : DeclarationContext, ITypedDecl, IMangledDecl
{
public Function()
{
Parameters = new List<Parameter>();
CallingConvention = CallingConvention.Default;
Signature = string.Empty;
}
public Function(Function function)
: base(function)
{
Parameters = new List<Parameter>();
ReturnType = function.ReturnType;
IsReturnIndirect = function.IsReturnIndirect;
HasThisReturn = function.HasThisReturn;
@@ -180,7 +178,7 @@ public Function(Function function)
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; }
@@ -244,22 +244,21 @@ public class FunctionType : Type
public QualifiedType ReturnType;
// Argument types.
public List<Parameter> Parameters;
public List<Parameter> Parameters { get; } = new List<Parameter>();
public CallingConvention CallingConvention { get; set; }
public ExceptionSpecType ExceptionSpecType { get; set; }
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;
}
@@ -70,7 +70,7 @@ private void CheckInvalidOperators(Class @class)
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 @@ private void CreateIndexer(Class @class, Method @operator)
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);
}
}
@@ -104,19 +104,18 @@ private void AddDelegatesToDictionary(Declaration decl, Module module)
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
@@ -52,16 +52,20 @@ public override bool VisitFunctionDecl(Function function)
Access = AccessSpecifier.Public,
Kind = CXXMethodKind.Normal,
ReturnType = function.ReturnType,
Parameters = function.Parameters,
CallingConvention = function.CallingConvention,
IsVariadic = function.IsVariadic,
IsInline = function.IsInline,
Conversion = MethodConversionKind.FunctionToInstanceMethod,
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);
@@ -46,14 +46,19 @@ public override bool VisitFunctionDecl(Function function)
Access = AccessSpecifier.Public,
Kind = CXXMethodKind.Normal,
ReturnType = function.ReturnType,
Parameters = function.Parameters,
CallingConvention = function.CallingConvention,
IsVariadic = function.IsVariadic,
IsInline = function.IsInline,
IsStatic = true,
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}",
@@ -149,10 +149,13 @@ public override bool VisitClassDecl(Class @class)
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);

0 comments on commit 649df6e

Please sign in to comment.