public class Parameter {
[Flags]
public enum Modifier : byte {
- NONE = 0,
- REF = 1,
- OUT = 2,
- PARAMS = 4,
+ NONE = 0,
+ REF = 1,
+ OUT = 2,
+ PARAMS = 4,
+ // This is a flag which says that it's either REF or OUT.
+ ISBYREF = 8
}
- public readonly string TypeName;
- public readonly string Name;
+ public readonly Expression TypeName;
public readonly Modifier ModFlags;
public Attributes OptAttributes;
- public Type ParameterType;
+ public readonly string Name;
+ public Type parameter_type;
- public Parameter (string type, string name, Modifier mod, Attributes attrs)
+ public Parameter (Expression type, string name, Modifier mod, Attributes attrs)
{
Name = name;
ModFlags = mod;
OptAttributes = attrs;
}
+ // <summary>
+ // Resolve is used in method definitions
+ // </summary>
public bool Resolve (DeclSpace ds, Location l)
{
- ParameterType = RootContext.LookupType (ds, TypeName, false, l);
- return ParameterType != null;
+ parameter_type = ds.ResolveType (TypeName, false, l);
+
+ if (parameter_type == TypeManager.void_type){
+ Report.Error (1536, l, "`void' parameter is not permitted");
+ return false;
+ }
+
+ return parameter_type != null;
}
public Type ExternalType (DeclSpace ds, Location l)
{
- if ((ModFlags & (Parameter.Modifier.REF | Parameter.Modifier.OUT)) != 0){
- string n = ParameterType.FullName + "&";
-
- Type t = RootContext.LookupType (ds, n, false, l);
+ if ((ModFlags & Parameter.Modifier.ISBYREF) != 0)
+ return TypeManager.GetReferenceType (parameter_type);
+
+ return parameter_type;
+ }
- return t;
+ public Type ParameterType {
+ get {
+ return parameter_type;
}
-
- return ParameterType;
}
public ParameterAttributes Attributes {
get {
- switch (ModFlags){
+ int flags = ((int) ModFlags) & ~((int) Parameter.Modifier.ISBYREF);
+ switch ((Modifier) flags) {
case Modifier.NONE:
return ParameterAttributes.None;
case Modifier.REF:
/// </summary>
public string GetSignature (DeclSpace ds, Location loc)
{
- if (ParameterType == null){
+ if (parameter_type == null){
if (!Resolve (ds, loc))
return null;
}
/// This is used to reuse a set of empty parameters, because they
/// are common
/// </summary>
- public static Parameters GetEmptyReadOnlyParameters ()
- {
- if (empty_parameters == null)
- empty_parameters = new Parameters (null, null, Location.Null);
+ public static Parameters EmptyReadOnlyParameters {
+ get {
+ if (empty_parameters == null)
+ empty_parameters = new Parameters (null, null, Location.Null);
- return empty_parameters;
+ return empty_parameters;
+ }
}
public bool Empty {
//
}
- static void error100 (string name)
+ static void Error_DuplicateParameterName (string name)
{
Report.Error (
100, "The parameter name `" + name + "' is a duplicate");
for (j = i + 1; j < count; j++){
if (base_name != FixedParameters [j].Name)
continue;
- error100 (base_name);
+ Error_DuplicateParameterName (base_name);
return false;
}
if (base_name == array_par_name){
- error100 (base_name);
+ Error_DuplicateParameterName (base_name);
return false;
}
}
pc = extra;
else
pc = extra + FixedParameters.Length;
-
+
types = new Type [pc];
if (!VerifyArgs ()){
return false;
}
+ bool failed = false;
if (FixedParameters != null){
foreach (Parameter p in FixedParameters){
Type t = null;
if (p.Resolve (ds, loc))
t = p.ExternalType (ds, loc);
+ else
+ failed = true;
types [i] = t;
i++;
if (extra > 0){
if (ArrayParameter.Resolve (ds, loc))
types [i] = ArrayParameter.ExternalType (ds, loc);
+ else
+ failed = true;
+ }
+
+ if (failed){
+ types = null;
+ return false;
}
return true;
}
+
+ //
+ // This variant is used by Delegates, because they need to
+ // resolve/define names, instead of the plain LookupType
+ //
+ public bool ComputeAndDefineParameterTypes (DeclSpace ds)
+ {
+ int extra = (ArrayParameter != null) ? 1 : 0;
+ int i = 0;
+ int pc;
+
+ if (FixedParameters == null)
+ pc = extra;
+ else
+ pc = extra + FixedParameters.Length;
+
+ types = new Type [pc];
+
+ if (!VerifyArgs ()){
+ FixedParameters = null;
+ return false;
+ }
+
+ bool ok_flag = true;
+
+ if (FixedParameters != null){
+ foreach (Parameter p in FixedParameters){
+ Type t = null;
+
+ if (p.Resolve (ds, loc))
+ t = p.ExternalType (ds, loc);
+ else
+ ok_flag = false;
+
+ types [i] = t;
+ i++;
+ }
+ }
+
+ if (extra > 0){
+ if (ArrayParameter.Resolve (ds, loc))
+ types [i] = ArrayParameter.ExternalType (ds, loc);
+ else
+ ok_flag = false;
+ }
+
+ //
+ // invalidate the cached types
+ //
+ if (!ok_flag){
+ types = null;
+ }
+
+ return ok_flag;
+ }
/// <summary>
/// Returns the argument types as an array
if (FixedParameters == null && ArrayParameter == null)
return no_types;
- if (ComputeParameterTypes (ds) == false)
+ if (ComputeParameterTypes (ds) == false){
+ types = null;
return null;
-
+ }
+
return types;
}
/// Note that the returned type will not contain any dereference in this
/// case (ie, you get "int" for a ref int instead of "int&"
/// </summary>
- public Type GetParameterInfo (DeclSpace ds, int idx, out bool is_out)
+ public Type GetParameterInfo (DeclSpace ds, int idx, out Parameter.Modifier mod)
{
- is_out = false;
+ mod = Parameter.Modifier.NONE;
if (!VerifyArgs ()){
FixedParameters = null;
return null;
if (types == null)
- if (ComputeParameterTypes (ds) == false){
- is_out = false;
+ if (ComputeParameterTypes (ds) == false)
return null;
- }
//
// If this is a request for the variable lenght arg.
//
int array_idx = (FixedParameters != null ? FixedParameters.Length : 0);
- if (idx == array_idx){
- is_out = false;
+ if (idx == array_idx)
return types [idx];
- }
//
// Otherwise, it is a fixed parameter
//
Parameter p = FixedParameters [idx];
- is_out = ((p.ModFlags & (Parameter.Modifier.REF | Parameter.Modifier.OUT)) != 0);
+ mod = p.ModFlags;
+
+ if ((mod & (Parameter.Modifier.REF | Parameter.Modifier.OUT)) != 0)
+ mod |= Parameter.Modifier.ISBYREF;
return p.ParameterType;
}