/// <summary> /// Writes a method signature to the output. /// </summary> public void WriteSignatureToOutput( JavascriptFormatter output, JSFunctionExpression enclosingFunction, MethodReference methodReference, MethodSignature methodSignature, TypeReferenceContext referenceContext, bool forConstructor ) { int index; var record = new CachedSignatureRecord(methodReference, methodSignature, forConstructor); if ((enclosingFunction.Method != null) && (enclosingFunction.Method.Method != null)) { var functionIdentifier = enclosingFunction.Method.Method.Identifier; CacheSet localSignatureSet; if (LocalCachedSets.TryGetValue(functionIdentifier, out localSignatureSet)) { if (localSignatureSet.Signatures.TryGetValue(record, out index)) { output.WriteRaw("$s{0:X2}", index); return; } } } if (!Global.Signatures.TryGetValue(record, out index)) { output.Signature(methodReference, methodSignature, referenceContext, forConstructor, true); } else { output.WriteRaw("$S{0:X2}()", index); } }
private void CacheSignature(MethodReference method, MethodSignature signature, bool isConstructor) { Func <GenericParameter, bool> filter = (gp) => { // If the generic parameter can be expanded given the type that declared the method, don't cache locally. var resolved = MethodSignature.ResolveGenericParameter(gp, method.DeclaringType); // Note that we have to ensure the resolved type is not generic either. A generic parameter can resolve to a // *different* generic parameter, and that is still correct - i.e. SomeMethod<A> calls SomeMethod<B>, // in that case resolving B will yield A. if ((resolved != gp) && (resolved != null) && !TypeUtil.IsOpenType(resolved)) { return(false); } var ownerMethod = gp.Owner as MethodReference; if (ownerMethod == null) { return(true); } if (ownerMethod == method) { return(false); } // FIXME: Nulls? else if (ownerMethod.Resolve() == method.Resolve()) { return(false); } else { return(true); } }; var cacheLocally = false; if (TypeUtil.IsOpenType(signature.ReturnType, filter)) { cacheLocally = true; } else if (signature.ParameterTypes.Any((gp) => TypeUtil.IsOpenType(gp, filter))) { cacheLocally = true; } else if (TypeUtil.IsOpenType(method.DeclaringType, filter)) { cacheLocally = true; } var set = GetCacheSet(cacheLocally); var record = new CachedSignatureRecord(method, signature, isConstructor); if (!set.Signatures.ContainsKey(record)) { set.Signatures.Add(record, set.Signatures.Count); } }
/// <summary> /// Writes a method signature to the output. /// </summary> public void WriteSignatureToOutput( JavascriptFormatter output, JSFunctionExpression enclosingFunction, MethodReference methodReference, MethodSignature methodSignature, TypeReferenceContext referenceContext, bool forConstructor ) { int index; CachedSignatureRecord cacheRecord; GenericParameter[] rewrittenGenericParameters = null; if (LocalCachingEnabled && PreferLocalCacheForGenericMethodSignatures) { cacheRecord = new CachedSignatureRecord(methodReference, GenericTypesRewriter.NormalizedConstructorSignature(methodReference, methodSignature, forConstructor), forConstructor); } else { RewritedCacheRecord <MethodSignature> rewritten = GenericTypesRewriter.Normalized(methodReference, methodSignature, forConstructor); cacheRecord = new CachedSignatureRecord(methodReference, rewritten.CacheRecord, forConstructor, rewritten.RewritedGenericParameters.Length); rewrittenGenericParameters = rewritten.RewritedGenericParameters; } if ((enclosingFunction.Method != null) && (enclosingFunction.Method.Method != null)) { var functionIdentifier = enclosingFunction.Method.Method.Identifier; CacheSet localSignatureSet; if (LocalCachedSets.TryGetValue(functionIdentifier, out localSignatureSet)) { if (localSignatureSet.Signatures.TryGetValue(cacheRecord, out index)) { output.WriteRaw("$s{0:X2}", index); return; } } } if (!Global.Signatures.TryGetValue(cacheRecord, out index)) { output.Signature(methodReference, methodSignature, referenceContext, forConstructor, true); } else { output.WriteRaw("$S{0:X2}", index); output.LPar(); if (rewrittenGenericParameters != null) { output.CommaSeparatedList(rewrittenGenericParameters, referenceContext); } output.RPar(); } }
private void CacheSignature(MethodReference method, MethodSignature signature, bool isConstructor) { Func <GenericParameter, bool> filter = (gp) => { var ownerMethod = gp.Owner as MethodReference; if (ownerMethod == null) { return(true); } if (ownerMethod == method) { return(false); } // FIXME: Nulls? else if (ownerMethod.Resolve() == method.Resolve()) { return(false); } else { return(true); } }; var cacheLocally = false; if (TypeUtil.IsOpenType(signature.ReturnType, filter)) { cacheLocally = true; } else if (signature.ParameterTypes.Any((gp) => TypeUtil.IsOpenType(gp, filter))) { cacheLocally = true; } else if (TypeUtil.IsOpenType(method.DeclaringType, filter)) { cacheLocally = true; } Dictionary <CachedSignatureRecord, int> signatureSet; int index; var set = GetCacheSet(cacheLocally); var record = new CachedSignatureRecord(method, signature, isConstructor); if (!set.Signatures.ContainsKey(record)) { set.Signatures.Add(record, set.Signatures.Count); } }
public bool Equals(ref CachedSignatureRecord rhs) { var result = ( (Method == rhs.Method) || (Method.FullName == rhs.Method.FullName) ) && Signature.Equals(rhs.Signature) && (IsConstructor == rhs.IsConstructor); if (!result) { return(false); } else { return(result); } }