Exemplo n.º 1
0
 /// <see cref="MarkupExtension.ProvideValue"/>
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     TypeArguments.Add(TypeArgument);
     ConstructorArguments.Add(App.Container);
     ConstructorArguments.Add(Name);
     return(base.ProvideValue(serviceProvider));
 }
Exemplo n.º 2
0
 public XamlTypeName(XamlType xamlType)
 {
     if (xamlType == null)
     {
         throw new ArgumentNullException("xamlType");
     }
     this.Name      = xamlType.Name;
     this.Namespace = xamlType.GetXamlNamespaces()[0];
     if (xamlType.TypeArguments != null)
     {
         foreach (XamlType argumentType in xamlType.TypeArguments)
         {
             TypeArguments.Add(new XamlTypeName(argumentType));
         }
     }
 }
Exemplo n.º 3
0
        public CodeTypeReference(Type baseType)
        {
#if NET_2_0
            if (baseType == null)
            {
                throw new ArgumentNullException("baseType");
            }

            if (baseType.IsGenericParameter)
            {
                this.baseType         = baseType.Name;
                this.referenceOptions = CodeTypeReferenceOptions.GenericTypeParameter;
            }
            else if (baseType.IsGenericTypeDefinition)
            {
                this.baseType = baseType.FullName;
            }
            else if (baseType.IsGenericType)
            {
                this.baseType = baseType.GetGenericTypeDefinition().FullName;
                foreach (Type arg in baseType.GetGenericArguments())
                {
                    if (arg.IsGenericParameter)
                    {
                        TypeArguments.Add(new CodeTypeReference(new CodeTypeParameter(arg.Name)));
                    }
                    else
                    {
                        TypeArguments.Add(new CodeTypeReference(arg));
                    }
                }
            }
            else
#endif
            if (baseType.IsArray)
            {
                this.arrayRank        = baseType.GetArrayRank();
                this.arrayElementType = new CodeTypeReference(baseType.GetElementType());
                this.baseType         = arrayElementType.BaseType;
            }
            else
            {
                Parse(baseType.FullName);
            }
            this.isInterface = baseType.IsInterface;
        }
Exemplo n.º 4
0
        private void InitializeFromType(Type type)
        {
            _baseType = type.Name;
            if (!type.IsGenericParameter)
            {
                Type currentType = type;
                while (currentType.IsNested)
                {
                    currentType = currentType.DeclaringType;
                    _baseType   = currentType.Name + "+" + _baseType;
                }
                if (!String.IsNullOrEmpty(type.Namespace))
                {
                    _baseType = type.Namespace + "." + _baseType;
                }
            }

            TypeInfo info = type.GetTypeInfo();

            // pick up the type arguments from an instantiated generic type but not an open one
            if (info.IsGenericType && !info.ContainsGenericParameters)
            {
                Type[] genericArgs = type.GetGenericArguments();
                for (int i = 0; i < genericArgs.Length; i++)
                {
                    TypeArguments.Add(new CodeTypeReference(genericArgs[i]));
                }
            }
            else if (!info.IsGenericTypeDefinition)
            {
                // if the user handed us a non-generic type, but later
                // appends generic type arguments, we'll pretend
                // it's a generic type for their sake - this is good for
                // them if they pass in System.Nullable class when they
                // meant the System.Nullable<T> value type.
                _needsFixup = true;
            }
        }
Exemplo n.º 5
0
		//
		// Creates a proxy base method call inside this container for hoisted base member calls
		//
		public MethodSpec CreateHoistedBaseCallProxy (ResolveContext rc, MethodSpec method)
		{
			Method proxy_method;

			//
			// One proxy per base method is enough
			//
			if (hoisted_base_call_proxies == null) {
				hoisted_base_call_proxies = new Dictionary<MethodSpec, Method> ();
				proxy_method = null;
			} else {
				hoisted_base_call_proxies.TryGetValue (method, out proxy_method);
			}

			if (proxy_method == null) {
				string name = CompilerGeneratedContainer.MakeName (method.Name, null, "BaseCallProxy", hoisted_base_call_proxies.Count);

				MemberName member_name;
				TypeArguments targs = null;
				TypeSpec return_type = method.ReturnType;
				var local_param_types = method.Parameters.Types;

				if (method.IsGeneric) {
					//
					// Copy all base generic method type parameters info
					//
					var hoisted_tparams = method.GenericDefinition.TypeParameters;
					var tparams = new TypeParameters ();

					targs = new TypeArguments ();
					targs.Arguments = new TypeSpec[hoisted_tparams.Length];
					for (int i = 0; i < hoisted_tparams.Length; ++i) {
						var tp = hoisted_tparams[i];
						var local_tp = new TypeParameter (tp, null, new MemberName (tp.Name, Location), null);
						tparams.Add (local_tp);

						targs.Add (new SimpleName (tp.Name, Location));
						targs.Arguments[i] = local_tp.Type;
					}

					member_name = new MemberName (name, tparams, Location);

					//
					// Mutate any method type parameters from original
					// to newly created hoisted version
					//
					var mutator = new TypeParameterMutator (hoisted_tparams, tparams);
					return_type = mutator.Mutate (return_type);
					local_param_types = mutator.Mutate (local_param_types);
				} else {
					member_name = new MemberName (name);
				}

				var base_parameters = new Parameter[method.Parameters.Count];
				for (int i = 0; i < base_parameters.Length; ++i) {
					var base_param = method.Parameters.FixedParameters[i];
					base_parameters[i] = new Parameter (new TypeExpression (local_param_types [i], Location),
						base_param.Name, base_param.ModFlags, null, Location);
					base_parameters[i].Resolve (this, i);
				}

				var cloned_params = ParametersCompiled.CreateFullyResolved (base_parameters, method.Parameters.Types);
				if (method.Parameters.HasArglist) {
					cloned_params.FixedParameters[0] = new Parameter (null, "__arglist", Parameter.Modifier.NONE, null, Location);
					cloned_params.Types[0] = Module.PredefinedTypes.RuntimeArgumentHandle.Resolve ();
				}

				// Compiler generated proxy
				proxy_method = new Method (this, new TypeExpression (return_type, Location),
					Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED | Modifiers.DEBUGGER_HIDDEN,
					member_name, cloned_params, null);

				var block = new ToplevelBlock (Compiler, proxy_method.ParameterInfo, Location) {
					IsCompilerGenerated = true
				};

				var mg = MethodGroupExpr.CreatePredefined (method, method.DeclaringType, Location);
				mg.InstanceExpression = new BaseThis (method.DeclaringType, Location);
				if (targs != null)
					mg.SetTypeArguments (rc, targs);

				// Get all the method parameters and pass them as arguments
				var real_base_call = new Invocation (mg, block.GetAllParametersArguments ());
				Statement statement;
				if (method.ReturnType.Kind == MemberKind.Void)
					statement = new StatementExpression (real_base_call);
				else
					statement = new Return (real_base_call, Location);

				block.AddStatement (statement);
				proxy_method.Block = block;

				members.Add (proxy_method);
				proxy_method.Define ();
				proxy_method.PrepareEmit ();

				hoisted_base_call_proxies.Add (method, proxy_method);
			}

			return proxy_method.Spec;
		}
Exemplo n.º 6
0
        private void Initialize(string typeName, CodeTypeReferenceOptions options)
        {
            Options = options;
            if (typeName == null || typeName.Length == 0)
            {
                typeName          = typeof(void).FullName;
                _baseType         = typeName;
                _arrayRank        = 0;
                _arrayElementType = null;
                return;
            }

            typeName = RipOffAssemblyInformationFromTypeName(typeName);

            int end     = typeName.Length - 1;
            int current = end;

            _needsFixup = true;      // default to true, and if we find arity or generic type args, we'll clear the flag.

            // Scan the entire string for valid array tails and store ranks for array tails
            // we found in a queue.
            Queue q = new Queue();

            while (current >= 0)
            {
                int rank = 1;
                if (typeName[current--] == ']')
                {
                    while (current >= 0 && typeName[current] == ',')
                    {
                        rank++;
                        current--;
                    }

                    if (current >= 0 && typeName[current] == '[')
                    { // found a valid array tail
                        q.Enqueue(rank);
                        current--;
                        end = current;
                        continue;
                    }
                }
                break;
            }

            // Try find generic type arguments
            current = end;
            ArrayList typeArgumentList = new ArrayList();
            Stack     subTypeNames     = new Stack();

            if (current > 0 && typeName[current--] == ']')
            {
                _needsFixup = false;
                int unmatchedRightBrackets = 1;
                int subTypeNameEndIndex    = end;

                // Try find the matching '[', if we can't find it, we will not try to parse the string
                while (current >= 0)
                {
                    if (typeName[current] == '[')
                    {
                        // break if we found matched brackets
                        if (--unmatchedRightBrackets == 0)
                        {
                            break;
                        }
                    }
                    else if (typeName[current] == ']')
                    {
                        ++unmatchedRightBrackets;
                    }
                    else if (typeName[current] == ',' && unmatchedRightBrackets == 1)
                    {
                        //
                        // Type name can contain nested generic types. Following is an example:
                        // System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],
                        //          [System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]],
                        //           mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
                        //
                        // Spliltting by ',' won't work. We need to do first-level split by ','.
                        //
                        if (current + 1 < subTypeNameEndIndex)
                        {
                            subTypeNames.Push(typeName.Substring(current + 1, subTypeNameEndIndex - current - 1));
                        }

                        subTypeNameEndIndex = current;
                    }
                    --current;
                }

                if (current > 0 && (end - current - 1) > 0)
                {
                    // push the last generic type argument name if there is any
                    if (current + 1 < subTypeNameEndIndex)
                    {
                        subTypeNames.Push(typeName.Substring(current + 1, subTypeNameEndIndex - current - 1));
                    }

                    // we found matched brackets and the brackets contains some characters.
                    while (subTypeNames.Count > 0)
                    {
                        String name = RipOffAssemblyInformationFromTypeName((string)subTypeNames.Pop());
                        typeArgumentList.Add(new CodeTypeReference(name));
                    }
                    end = current - 1;
                }
            }

            if (end < 0)
            {  // this can happen if we have some string like "[...]"
                _baseType = typeName;
                return;
            }

            if (q.Count > 0)
            {
                CodeTypeReference type = new CodeTypeReference(typeName.Substring(0, end + 1), Options);

                for (int i = 0; i < typeArgumentList.Count; i++)
                {
                    type.TypeArguments.Add((CodeTypeReference)typeArgumentList[i]);
                }

                while (q.Count > 1)
                {
                    type = new CodeTypeReference(type, (int)q.Dequeue());
                }

                // we don't need to create a new CodeTypeReference for the last one.
                Debug.Assert(q.Count == 1, "We should have one and only one in the rank queue.");
                _baseType         = null;
                _arrayRank        = (int)q.Dequeue();
                _arrayElementType = type;
            }
            else if (typeArgumentList.Count > 0)
            {
                for (int i = 0; i < typeArgumentList.Count; i++)
                {
                    TypeArguments.Add((CodeTypeReference)typeArgumentList[i]);
                }

                _baseType = typeName.Substring(0, end + 1);
            }
            else
            {
                _baseType = typeName;
            }

            // Now see if we have some arity.  baseType could be null if this is an array type.
            if (_baseType != null && _baseType.IndexOf('`') != -1)
            {
                _needsFixup = false;
            }
        }
Exemplo n.º 7
0
void case_371()
#line 3089 "cs-parser.jay"
{
		TypeArguments type_args = new TypeArguments ();
		type_args.Add ((FullNamedExpression) yyVals[0+yyTop]);
		yyVal = type_args;
		locationListStack.Push (new List<Location> ());
	  }
Exemplo n.º 8
0
        private void Parse(string baseType)
        {
            if (baseType == null || baseType.Length == 0)
            {
                this.baseType = typeof(void).FullName;
                return;
            }

#if NET_2_0
            int array_start = baseType.IndexOf('[');
            if (array_start == -1)
            {
                this.baseType = baseType;
                return;
            }

            int array_end = baseType.LastIndexOf(']');
            if (array_end < array_start)
            {
                this.baseType = baseType;
                return;
            }

            int lastAngle = baseType.LastIndexOf('>');
            if (lastAngle != -1 && lastAngle > array_end)
            {
                this.baseType = baseType;
                return;
            }

            string[] args = baseType.Substring(array_start + 1, array_end - array_start - 1).Split(',');

            if ((array_end - array_start) != args.Length)
            {
                this.baseType = baseType.Substring(0, array_start);
                int           escapeCount = 0;
                int           scanPos     = array_start;
                StringBuilder tb          = new StringBuilder();
                while (scanPos < baseType.Length)
                {
                    char currentChar = baseType[scanPos];

                    switch (currentChar)
                    {
                    case '[':
                        if (escapeCount > 1 && tb.Length > 0)
                        {
                            tb.Append(currentChar);
                        }
                        escapeCount++;
                        break;

                    case ']':
                        escapeCount--;
                        if (escapeCount > 1 && tb.Length > 0)
                        {
                            tb.Append(currentChar);
                        }

                        if (tb.Length != 0 && (escapeCount % 2) == 0)
                        {
                            TypeArguments.Add(tb.ToString());
                            tb.Length = 0;
                        }
                        break;

                    case ',':
                        if (escapeCount > 1)
                        {
                            // skip anything after the type name until we
                            // reach the next separator
                            while (scanPos + 1 < baseType.Length)
                            {
                                if (baseType[scanPos + 1] == ']')
                                {
                                    break;
                                }
                                scanPos++;
                            }
                        }
                        else if (tb.Length > 0)
                        {
                            CodeTypeReference typeArg = new CodeTypeReference(tb.ToString());
                            TypeArguments.Add(typeArg);
                            tb.Length = 0;
                        }
                        break;

                    default:
                        tb.Append(currentChar);
                        break;
                    }
                    scanPos++;
                }
            }
            else
            {
                arrayElementType = new CodeTypeReference(baseType.Substring(0, array_start));
                arrayRank        = args.Length;
            }
#else
            int array_start = baseType.LastIndexOf('[');
            if (array_start == -1)
            {
                this.baseType = baseType;
                return;
            }

            int array_end = baseType.LastIndexOf(']');
            if (array_end < array_start)
            {
                this.baseType = baseType;
                return;
            }

            string[] args = baseType.Substring(array_start + 1, array_end - array_start - 1).Split(',');

            bool isArray = true;
            foreach (string arg in args)
            {
                if (arg.Length != 0)
                {
                    isArray = false;
                    break;
                }
            }
            if (isArray)
            {
                arrayElementType = new CodeTypeReference(baseType.Substring(0, array_start));
                arrayRank        = args.Length;
            }
            else
            {
                this.baseType = baseType;
            }
#endif
        }
        private void Initialize(string typeName)
        {
            if (typeName == null || typeName.Length == 0)
            {
                typeName              = typeof(void).FullName;
                this.baseType         = typeName;
                this.arrayRank        = 0;
                this.arrayElementType = null;
                return;
            }

            typeName = RipOffAssemblyInformationFromTypeName(typeName);

            int end     = typeName.Length - 1;
            int current = end;

            needsFixup = true;      // default to true, and if we find arity or generic type args, we'll clear the flag.

            // Scan the entire string for valid array tails and store ranks for array tails
            // we found in a queue.
            Queue q = new Queue();

            while (current >= 0)
            {
                int rank = 1;
                if (typeName[current--] == ']')
                {
                    while (current >= 0 && typeName[current] == ',')
                    {
                        rank++;
                        current--;
                    }

                    if (current >= 0 && typeName[current] == '[') // found a valid array tail
                    {
                        q.Enqueue(rank);
                        current--;
                        end = current;
                        continue;
                    }
                }
                break;
            }

            // Try find generic type arguments
            current = end;
            ArrayList typeArgumentList = new ArrayList();
            Stack     subTypeNames     = new Stack();

            if (current > 0 && typeName[current--] == ']')
            {
                needsFixup = false;
                int unmatchedRightBrackets = 1;
                int subTypeNameEndIndex    = end;

                // Try find the matching '[', if we can't find it, we will not try to parse the string
                while (current >= 0)
                {
                    if (typeName[current] == '[')
                    {
                        // break if we found matched brackets
                        if (--unmatchedRightBrackets == 0)
                        {
                            break;
                        }
                    }
                    else if (typeName[current] == ']')
                    {
                        ++unmatchedRightBrackets;
                    }
                    else if (typeName[current] == ',' && unmatchedRightBrackets == 1)
                    {
                        //
                        if (current + 1 < subTypeNameEndIndex)
                        {
                            subTypeNames.Push(typeName.Substring(current + 1, subTypeNameEndIndex - current - 1));
                        }

                        subTypeNameEndIndex = current;
                    }
                    --current;
                }

                if (current > 0 && (end - current - 1) > 0)
                {
                    // push the last generic type argument name if there is any
                    if (current + 1 < subTypeNameEndIndex)
                    {
                        subTypeNames.Push(typeName.Substring(current + 1, subTypeNameEndIndex - current - 1));
                    }

                    // we found matched brackets and the brackets contains some characters.
                    while (subTypeNames.Count > 0)
                    {
                        String name = RipOffAssemblyInformationFromTypeName((string)subTypeNames.Pop());
                        typeArgumentList.Add(new CodeTypeReference(name));
                    }
                    end = current - 1;
                }
            }

            if (end < 0)    // this can happen if we have some string like "[...]"
            {
                this.baseType = typeName;
                return;
            }

            if (q.Count > 0)
            {
                CodeTypeReference type = new CodeTypeReference(typeName.Substring(0, end + 1));

                for (int i = 0; i < typeArgumentList.Count; i++)
                {
                    type.TypeArguments.Add((CodeTypeReference)typeArgumentList[i]);
                }

                while (q.Count > 1)
                {
                    type = new CodeTypeReference(type, (int)q.Dequeue());
                }

                // we don't need to create a new CodeTypeReference for the last one.
                Debug.Assert(q.Count == 1, "We should have one and only one in the rank queue.");
                this.baseType         = null;
                this.arrayRank        = (int)q.Dequeue();
                this.arrayElementType = type;
            }
            else if (typeArgumentList.Count > 0)
            {
                for (int i = 0; i < typeArgumentList.Count; i++)
                {
                    TypeArguments.Add((CodeTypeReference)typeArgumentList[i]);
                }

                this.baseType = typeName.Substring(0, end + 1);
            }
            else
            {
                this.baseType = typeName;
            }

            // Now see if we have some arity.  baseType could be null if this is an array type.
            if (baseType != null && baseType.IndexOf('`') != -1)
            {
                needsFixup = false;
            }
        }
Exemplo n.º 10
0
		TypeExpr CreateStoreyTypeExpression (EmitContext ec)
		{
			//
			// Create an instance of storey type
			//
			TypeExpr storey_type_expr;
			if (CurrentTypeParameters != null) {
				//
				// Use current method type parameter (MVAR) for top level storey only. All
				// nested storeys use class type parameter (VAR)
				//
				var tparams = ec.CurrentAnonymousMethod != null && ec.CurrentAnonymousMethod.Storey != null ?
					ec.CurrentAnonymousMethod.Storey.CurrentTypeParameters :
					ec.CurrentTypeParameters;

				TypeArguments targs = new TypeArguments ();

				//
				// Use type parameter name instead of resolved type parameter
				// specification to resolve to correctly nested type parameters
				//
				for (int i = 0; i < tparams.Count; ++i)
					targs.Add (new SimpleName (tparams [i].Name, Location)); //  new TypeParameterExpr (tparams[i], Location));

				storey_type_expr = new GenericTypeExpr (Definition, targs, Location);
			} else {
				storey_type_expr = new TypeExpression (CurrentType, Location);
			}

			return storey_type_expr;
		}
Exemplo n.º 11
0
		protected override bool DoDefineMembers ()
		{
			if (!base.DoDefineMembers ())
				return false;

			Location loc = Location;

			var equals_parameters = ParametersCompiled.CreateFullyResolved (
				new Parameter (new TypeExpression (Compiler.BuiltinTypes.Object, loc), "obj", 0, null, loc), Compiler.BuiltinTypes.Object);

			Method equals = new Method (this, new TypeExpression (Compiler.BuiltinTypes.Bool, loc),
				Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("Equals", loc),
				equals_parameters, null);

			equals_parameters[0].Resolve (equals, 0);

			Method tostring = new Method (this, new TypeExpression (Compiler.BuiltinTypes.String, loc),
				Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("ToString", loc),
				ParametersCompiled.EmptyReadOnlyParameters, null);

			ToplevelBlock equals_block = new ToplevelBlock (Compiler, equals.ParameterInfo, loc);

			TypeExpr current_type;
			if (CurrentTypeParameters != null) {
				var targs = new TypeArguments ();
				for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
					targs.Add (new TypeParameterExpr (CurrentTypeParameters[i], Location));
				}

				current_type = new GenericTypeExpr (Definition, targs, loc);
			} else {
				current_type = new TypeExpression (Definition, loc);
			}

			var li_other = LocalVariable.CreateCompilerGenerated (CurrentType, equals_block, loc);
			equals_block.AddStatement (new BlockVariable (new TypeExpression (li_other.Type, loc), li_other));
			var other_variable = new LocalVariableReference (li_other, loc);

			MemberAccess system_collections_generic = new MemberAccess (new MemberAccess (
				new QualifiedAliasMember ("global", "System", loc), "Collections", loc), "Generic", loc);

			Expression rs_equals = null;
			Expression string_concat = new StringConstant (Compiler.BuiltinTypes, "{", loc);
			Expression rs_hashcode = new IntConstant (Compiler.BuiltinTypes, -2128831035, loc);
			for (int i = 0; i < parameters.Count; ++i) {
				var p = parameters [i];
				var f = (Field) Members [i * 2];

				MemberAccess equality_comparer = new MemberAccess (new MemberAccess (
					system_collections_generic, "EqualityComparer",
						new TypeArguments (new SimpleName (CurrentTypeParameters [i].Name, loc)), loc),
						"Default", loc);

				Arguments arguments_equal = new Arguments (2);
				arguments_equal.Add (new Argument (new MemberAccess (new This (f.Location), f.Name)));
				arguments_equal.Add (new Argument (new MemberAccess (other_variable, f.Name)));

				Expression field_equal = new Invocation (new MemberAccess (equality_comparer,
					"Equals", loc), arguments_equal);

				Arguments arguments_hashcode = new Arguments (1);
				arguments_hashcode.Add (new Argument (new MemberAccess (new This (f.Location), f.Name)));
				Expression field_hashcode = new Invocation (new MemberAccess (equality_comparer,
					"GetHashCode", loc), arguments_hashcode);

				IntConstant FNV_prime = new IntConstant (Compiler.BuiltinTypes, 16777619, loc);				
				rs_hashcode = new Binary (Binary.Operator.Multiply,
					new Binary (Binary.Operator.ExclusiveOr, rs_hashcode, field_hashcode),
					FNV_prime);

				Expression field_to_string = new Conditional (new BooleanExpression (new Binary (Binary.Operator.Inequality,
					new MemberAccess (new This (f.Location), f.Name), new NullLiteral (loc))),
					new Invocation (new MemberAccess (
						new MemberAccess (new This (f.Location), f.Name), "ToString"), null),
					new StringConstant (Compiler.BuiltinTypes, string.Empty, loc), loc);

				if (rs_equals == null) {
					rs_equals = field_equal;
					string_concat = new Binary (Binary.Operator.Addition,
						string_concat,
						new Binary (Binary.Operator.Addition,
							new StringConstant (Compiler.BuiltinTypes, " " + p.Name + " = ", loc),
							field_to_string));
					continue;
				}

				//
				// Implementation of ToString () body using string concatenation
				//				
				string_concat = new Binary (Binary.Operator.Addition,
					new Binary (Binary.Operator.Addition,
						string_concat,
						new StringConstant (Compiler.BuiltinTypes, ", " + p.Name + " = ", loc)),
					field_to_string);

				rs_equals = new Binary (Binary.Operator.LogicalAnd, rs_equals, field_equal);
			}

			string_concat = new Binary (Binary.Operator.Addition,
				string_concat,
				new StringConstant (Compiler.BuiltinTypes, " }", loc));

			//
			// Equals (object obj) override
			//		
			var other_variable_assign = new TemporaryVariableReference (li_other, loc);
			equals_block.AddStatement (new StatementExpression (
				new SimpleAssign (other_variable_assign,
					new As (equals_block.GetParameterReference (0, loc),
						current_type, loc), loc)));

			Expression equals_test = new Binary (Binary.Operator.Inequality, other_variable, new NullLiteral (loc));
			if (rs_equals != null)
				equals_test = new Binary (Binary.Operator.LogicalAnd, equals_test, rs_equals);
			equals_block.AddStatement (new Return (equals_test, loc));

			equals.Block = equals_block;
			equals.Define ();
			Members.Add (equals);

			//
			// GetHashCode () override
			//
			Method hashcode = new Method (this, new TypeExpression (Compiler.BuiltinTypes.Int, loc),
				Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN,
				new MemberName ("GetHashCode", loc),
				ParametersCompiled.EmptyReadOnlyParameters, null);

			//
			// Modified FNV with good avalanche behavior and uniform
			// distribution with larger hash sizes.
			//
			// const int FNV_prime = 16777619;
			// int hash = (int) 2166136261;
			// foreach (int d in data)
			//     hash = (hash ^ d) * FNV_prime;
			// hash += hash << 13;
			// hash ^= hash >> 7;
			// hash += hash << 3;
			// hash ^= hash >> 17;
			// hash += hash << 5;

			ToplevelBlock hashcode_top = new ToplevelBlock (Compiler, loc);
			Block hashcode_block = new Block (hashcode_top, loc, loc);
			hashcode_top.AddStatement (new Unchecked (hashcode_block, loc));

			var li_hash = LocalVariable.CreateCompilerGenerated (Compiler.BuiltinTypes.Int, hashcode_top, loc);
			hashcode_block.AddStatement (new BlockVariable (new TypeExpression (li_hash.Type, loc), li_hash));
			LocalVariableReference hash_variable_assign = new LocalVariableReference (li_hash, loc);
			hashcode_block.AddStatement (new StatementExpression (
				new SimpleAssign (hash_variable_assign, rs_hashcode)));

			var hash_variable = new LocalVariableReference (li_hash, loc);
			hashcode_block.AddStatement (new StatementExpression (
				new CompoundAssign (Binary.Operator.Addition, hash_variable,
					new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 13, loc)))));
			hashcode_block.AddStatement (new StatementExpression (
				new CompoundAssign (Binary.Operator.ExclusiveOr, hash_variable,
					new Binary (Binary.Operator.RightShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 7, loc)))));
			hashcode_block.AddStatement (new StatementExpression (
				new CompoundAssign (Binary.Operator.Addition, hash_variable,
					new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 3, loc)))));
			hashcode_block.AddStatement (new StatementExpression (
				new CompoundAssign (Binary.Operator.ExclusiveOr, hash_variable,
					new Binary (Binary.Operator.RightShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 17, loc)))));
			hashcode_block.AddStatement (new StatementExpression (
				new CompoundAssign (Binary.Operator.Addition, hash_variable,
					new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 5, loc)))));

			hashcode_block.AddStatement (new Return (hash_variable, loc));
			hashcode.Block = hashcode_top;
			hashcode.Define ();
			Members.Add (hashcode);

			//
			// ToString () override
			//

			ToplevelBlock tostring_block = new ToplevelBlock (Compiler, loc);
			tostring_block.AddStatement (new Return (string_concat, loc));
			tostring.Block = tostring_block;
			tostring.Define ();
			Members.Add (tostring);

			return true;
		}
Exemplo n.º 12
0
void case_364()
#line 3417 "ps-parser.jay"
{
		TypeArguments type_args = new TypeArguments ();
		type_args.Add ((FullNamedExpression) yyVals[0+yyTop]);
		yyVal = type_args;
	  }