public static void InitItemsTable( string file ) { StreamReader reader = File.OpenText( file ); string line; while ( (line = reader.ReadLine()) != null ) { line = line.Trim(); if ( line == "" || line.StartsWith( "#" ) ) continue; string[] splt = line.Split( ' ', '\t' ); string[] ids = splt[0].Split( '-' ); int itemId = Int32.Parse( ids[0], System.Globalization.NumberStyles.HexNumber ); int itemIdEnd = ids.Length > 1 ? Int32.Parse( ids[1], System.Globalization.NumberStyles.HexNumber ) : itemId; TypeArguments typeArgu = new TypeArguments(); if ( splt.Length > 1 ) { string[] types = splt[1].Split( '-' ); typeArgu.Type = types[0]; if ( types.Length > 1 ) typeArgu.Arguments = types[1]; } for ( int id = itemId; id <= itemIdEnd; id++ ) { ItemsTable[id] = typeArgu; } } reader.Close(); }
protected override TypeExpr DoResolveAsTypeStep (IMemberContext ec) { var type = ec.Module.PredefinedTypes.Nullable.Resolve (loc); if (type == null) return null; TypeArguments args = new TypeArguments (underlying); GenericTypeExpr ctype = new GenericTypeExpr (type, args, loc); return ctype.ResolveAsTypeTerminal (ec, false); }
public override TypeExpr ResolveAsType (IMemberContext ec) { var type = ec.Module.PredefinedTypes.Nullable.Resolve (); if (type == null) return null; TypeArguments args = new TypeArguments (underlying); GenericTypeExpr ctype = new GenericTypeExpr (type, args, loc); return ctype.ResolveAsType (ec); }
protected override TypeExpr DoResolveAsTypeStep (IMemberContext ec) { if (TypeManager.generic_nullable_type == null) { TypeManager.generic_nullable_type = TypeManager.CoreLookupType (ec.Compiler, "System", "Nullable", 1, MemberKind.Struct, true); } TypeArguments args = new TypeArguments (underlying); GenericTypeExpr ctype = new GenericTypeExpr (TypeManager.generic_nullable_type, args, loc); return ctype.ResolveAsTypeTerminal (ec, false); }
public override TypeSpec ResolveAsType (IMemberContext ec) { eclass = ExprClass.Type; var otype = ec.Module.PredefinedTypes.Nullable.Resolve (); if (otype == null) return null; TypeArguments args = new TypeArguments (new TypeExpression (underlying, loc)); GenericTypeExpr ctype = new GenericTypeExpr (otype, args, loc); type = ctype.ResolveAsType (ec); return type; }
public void SetUp() { theFactory = MockRepository.GenerateMock<IServiceFactory>(); theChain = new RoutedChain("something"); theRouteData = new Dictionary<string, object>(); theArguments = new TypeArguments(); theBehavior = MockRepository.GenerateMock<IActionBehavior>(); theFactory.Stub(x => x.BuildBehavior(theArguments, theChain.UniqueId)) .Return(theBehavior); theInvoker = new BehaviorInvoker(theFactory, theChain); }
public async Task Invoke(TypeArguments arguments, IDictionary<string, object> routeValues) { var currentChain = new CurrentChain(_chain, routeValues); arguments.Set(typeof(ICurrentChain), currentChain); if (arguments.Has(typeof (IChainExecutionLog))) { arguments.Get<IChainExecutionLog>().RootChain = _chain; } if (_chain.Filters.Any(filter => filter.Filter(arguments) == DoNext.Stop)) { return; } IActionBehavior behavior = null; if (arguments.Has(typeof (IChainExecutionLog))) { arguments.Get<IChainExecutionLog>().Trace("Building the Behaviors", () => { behavior = _factory.BuildBehavior(arguments, _chain.UniqueId); }); } else { behavior = _factory.BuildBehavior(arguments, _chain.UniqueId); } try { await behavior.Invoke().ConfigureAwait(false); } finally { var disposable = behavior as IDisposable; disposable?.Dispose(); } }
public DoNext Filter(TypeArguments arguments) { if (arguments.Has(typeof (Latch))) return DoNext.Stop; var request = arguments.Get<IHttpRequest>(); if (!request.HasHeader(HttpRequestHeaders.AcceptEncoding)) return DoNext.Continue; var acceptEncoding = request .GetSingleHeader(HttpRequestHeaders.AcceptEncoding); var encoding = _encoders.MatchFor(acceptEncoding); var writer = arguments.Get<IHttpResponse>(); writer.AppendHeader(HttpRequestHeaders.ContentEncoding, encoding.MatchingEncoding.Value); writer.UseEncoding(encoding); arguments.Set(typeof (Latch), new Latch()); return DoNext.Continue; }
public SessionlessAsynchronousHttpHandler(IBehaviorInvoker invoker, TypeArguments arguments, IDictionary<string, object> routeData) { _invoker = invoker; _arguments = arguments; _routeData = routeData; }
public CompletionMemberAccess (Expression e, string partial_name, TypeArguments targs, Location l) { this.expr = e; this.loc = l; this.partial_name = partial_name; this.targs = targs; }
public DoNext Filter(TypeArguments arguments) { return _returnValue; }
private void Parse(string baseType) { if (baseType == null || baseType.Length == 0) { this.baseType = typeof(void).FullName; return; } 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; } }
public Expression CreateCallSiteBinder(ResolveContext ec, Arguments args) { Arguments binder_args = new Arguments(member != null ? 5 : 3); bool is_member_access = member is MemberAccess; CSharpBinderFlags call_flags; if (!is_member_access && member is SimpleName) { call_flags = CSharpBinderFlags.InvokeSimpleName; is_member_access = true; } else { call_flags = 0; } binder_args.Add(new Argument(new BinderFlags(call_flags, this))); if (is_member_access) { binder_args.Add(new Argument(new StringLiteral(ec.BuiltinTypes, member.Name, member.Location))); } if (member != null && member.HasTypeArguments) { TypeArguments ta = member.TypeArguments; if (ta.Resolve(ec, false)) { var targs = new ArrayInitializer(ta.Count, loc); foreach (TypeSpec t in ta.Arguments) { targs.Add(new TypeOf(t, loc)); } binder_args.Add(new Argument(new ImplicitlyTypedArrayCreation(targs, loc))); } } else if (is_member_access) { binder_args.Add(new Argument(new NullLiteral(loc))); } binder_args.Add(new Argument(new TypeOf(ec.CurrentType, loc))); Expression real_args; if (args == null) { // Cannot be null because .NET trips over real_args = new ArrayCreation( new MemberAccess(GetBinderNamespace(loc), "CSharpArgumentInfo", loc), new ArrayInitializer(0, loc), loc); } else { real_args = new ImplicitlyTypedArrayCreation(args.CreateDynamicBinderArguments(ec), loc); } binder_args.Add(new Argument(real_args)); return(new Invocation(GetBinder(is_member_access ? "InvokeMember" : "Invoke", loc), binder_args)); }
public SessionLessFubuHttpHandler(IBehaviorInvoker invoker, TypeArguments arguments, IDictionary <string, object> routeData) { _invoker = invoker; _arguments = arguments; _routeData = routeData; }
void case_363() #line 3409 "ps-parser.jay" { Error_TypeExpected (lexer.Location); yyVal = new TypeArguments (); }
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> ()); }
public NestedStructureMapContainerBehavior(IContainer container, TypeArguments arguments, Guid behaviorId) { _container = container; _arguments = arguments; _behaviorId = behaviorId; }
public IHttpHandler Build(IBehaviorInvoker invoker, TypeArguments arguments, RouteValueDictionary routeValues) { return new SessionLessFubuHttpHandler(invoker, arguments, routeValues); }
public QueryExpressionAccess(Expression expr, string methodName, TypeArguments typeArguments, Location loc) : base(expr, methodName, typeArguments, loc) { }
private void Initialize(string typeName, CodeTypeReferenceOptions options) { Options = options; if (string.IsNullOrEmpty(typeName)) { 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. var q = new Queue <int>(); 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; var typeArgumentList = new List <CodeTypeReference>(); var subTypeNames = new Stack <string>(); 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(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(typeArgumentList[i]); } while (q.Count > 1) { type = new CodeTypeReference(type, 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 = q.Dequeue(); ArrayElementType = type; } else if (typeArgumentList.Count > 0) { for (int i = 0; i < typeArgumentList.Count; i++) { TypeArguments.Add(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; } }
public IHttpHandler Build(IBehaviorInvoker invoker, TypeArguments arguments, RouteValueDictionary routeValues) { return(new SynchronousFubuHttpHandler(invoker, arguments, routeValues)); }
public SynchronousFubuHttpHandler(IBehaviorInvoker invoker, TypeArguments arguments, IDictionary<string, object> routeData) : base(invoker, arguments, routeData) { }
public T Build <T>(TypeArguments arguments) { throw new NotImplementedException(); }
void case_370() #line 3081 "cs-parser.jay" { Error_TypeExpected (lexer.Location); yyVal = new TypeArguments (); }
/// <summary> /// ProvideValue, which returns the concrete object of the generic type</summary> /// <param name="serviceProvider">The service provider</param> /// <returns>The instance of the type</returns> public override object ProvideValue(IServiceProvider serviceProvider) { #if CS_4 string[] baseTypeArray = _typeName.Split(':'); var namespaceResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as System.Xaml.IXamlNamespaceResolver; if (namespaceResolver == null) { throw new Exception("The Generic markup extension requires an IXamlNamespaceResolver service provider"); } var schemaContextProvider = serviceProvider.GetService(typeof(System.Xaml.IXamlSchemaContextProvider)) as System.Xaml.IXamlSchemaContextProvider; if (schemaContextProvider == null) { throw new Exception("The Generic markup extension requires an IXamlSchemaContextProvider service provider"); } var xamlNamespace = namespaceResolver.GetNamespace(baseTypeArray[0]); string name = baseTypeArray[1] + "`" + TypeArguments.Count.ToString(); var xamlTypeName = new System.Xaml.Schema.XamlTypeName(xamlNamespace, name); var xamlType = schemaContextProvider.SchemaContext.GetXamlType(xamlTypeName); if (xamlType == null) { throw new Exception("The type could not be resolved"); } Type genericType = xamlType.UnderlyingType; // Get an array of the type arguments Type[] typeArgumentArray = new Type[TypeArguments.Count]; TypeArguments.CopyTo(typeArgumentArray, 0); // Create the concrete type, e.g. Collection<String> var concreteType = genericType.MakeGenericType(typeArgumentArray); // Create an instance of that type return(Activator.CreateInstance(concreteType)); #else IXamlTypeResolver xamlTypeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver; if (xamlTypeResolver == null) { throw new Exception("The Generic markup extension requires an IXamlTypeResolver service provider"); } // Get e.g. "Collection`1" type string name = _typeName + "`" + TypeArguments.Count.ToString(); Type genericType = xamlTypeResolver.Resolve(name); // Get an array of the type arguments Type[] typeArgumentArray = new Type[TypeArguments.Count]; TypeArguments.CopyTo(typeArgumentArray, 0); // Create the concrete type, e.g. Collection<String> Type concreteType = genericType.MakeGenericType(typeArgumentArray); // Create an instance of that type return(Activator.CreateInstance(concreteType)); #endif }
public IHttpHandler Build(IBehaviorInvoker invoker, TypeArguments arguments, RouteValueDictionary routeValues) { return new AsynchronousHttpHandler(invoker, arguments, routeValues); }
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; }
protected Invocation CreateQueryExpression (Expression lSide, TypeArguments typeArguments, ArrayList arguments) { return new QueryExpressionInvocation ( new QueryExpressionAccess (lSide, MethodName, typeArguments, loc), arguments); }
void case_364() #line 3417 "ps-parser.jay" { TypeArguments type_args = new TypeArguments (); type_args.Add ((FullNamedExpression) yyVals[0+yyTop]); yyVal = type_args; }
public IPipelineGraph ToNestedGraph(TypeArguments arguments = null) { var nestedPluginGraph = _pluginGraph.ToNestedGraph(); if (arguments != null) { foreach (var pair in arguments.Defaults) { nestedPluginGraph.Families[pair.Key] = PluginFamily.ExplicitOverride(pair.Key, pair.Value); } } var instances = new ComplexInstanceGraph(this, nestedPluginGraph, ContainerRole.Nested); return new PipelineGraph(nestedPluginGraph, instances, this, _singletons, new ContainerSpecificObjectCache()); }
public static FullNamedExpression CreateDelegateTypeExpression (BuiltinTypes builtinTypes, ParametersCompiled parameters, FullNamedExpression retType, Location loc){ bool hasParams = parameters != null && parameters.Count > 0; int paramCount = hasParams ? parameters.Count : 0; bool hasRetType = !(retType is TypeExpression && ((TypeExpression)retType).Type == builtinTypes.Void); int typeParamCount = paramCount; if (hasRetType) typeParamCount++; TypeArguments typeArgs = null; if (typeParamCount > 0) { var typeArgArray = new FullNamedExpression[typeParamCount]; for (var i = 0; i < paramCount; i++) { if (i < paramCount) { var param = parameters.FixedParameters[i] as Parameter; typeArgArray[i] = param.TypeExpression; } else { typeArgArray[i] = retType; } } typeArgs = new TypeArguments (typeArgArray); } if (!hasRetType) { return new MemberAccess(new SimpleName("System", loc), "Action", typeArgs, loc); } else { return new MemberAccess(new SimpleName("System", loc), "Func", typeArgs, loc); } }
public QueryExpressionAccess (Expression expr, string methodName, TypeArguments typeArguments, Location loc) : base (expr, methodName, typeArguments, loc) { }
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; }
// // 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; }
public void ExtractItems( StreamWriter writer ) { ArrayList blocks = new ArrayList(); foreach ( WorldItem item in m_Items.Values ) { ItemsBlock block = FindBlock( blocks, item ); if ( block == null ) { block = new ItemsBlock( item.ItemId, item.Hue, item.ItemIdName ); block.Add( item ); blocks.Add( block ); } else { block.Add( item ); } } foreach ( ItemsBlock block in blocks ) { TypeArguments typeArgu = ItemsTable[(int)block.ItemId] as TypeArguments; if ( typeArgu != null && typeArgu.Type == null ) continue; if ( typeArgu == null ) { typeArgu = new TypeArguments(); typeArgu.Type = "Static"; } string arguments = block.Hue != 0 ? string.Format( "Hue=0x{0:X}", block.Hue ) : ""; if ( arguments.Length > 0 && typeArgu.Arguments != null ) arguments += "; "; arguments += typeArgu.Arguments; writer.WriteLine( "# {0}", block.Name ); writer.WriteLine( "{0} 0x{1:X4}{2}", typeArgu.Type, block.ItemId, arguments.Length > 0 ? string.Format( " ({0})", arguments ) : "" ); foreach ( WorldItem packet in block.List ) writer.WriteLine( "{0} {1} {2}", packet.Position.X, packet.Position.Y, packet.Position.Z ); writer.WriteLine(); } }