public TypeInferenceOperationKey( RelinqScriptExpression self, RelinqScriptType myType, IEnumerable<Type> closure) { Self = self.SurelyNotNull(); MyType = myType; Closure = closure; }
private void AfterCall(Guid id, RelinqScriptExpression e, TypeInferenceCache cache) { var startedEntry = History.Single(entry2 => entry2.Id == id); var finishedEntry = new TypeInferenceHistoryEntry(startedEntry); finishedEntry.InferredType = cache.ContainsKey(e) ? cache[e] : null; if (e.IsCall()) { RelinqScriptExpression invtarget = null; if (e is InvokeExpression) { invtarget = e.Children.ElementAt(0); } else if (e is IndexerExpression || e is OperatorExpression) { invtarget = e; } if (invtarget != null && cache.Invocations.ContainsKey(invtarget)) { finishedEntry.InferredInvocation = cache.Invocations[invtarget]; } } History.Add(finishedEntry); if (History.Count % 20000 == 0) DumpHistory(); }
public InconsistentConditionalExpression(JSToCSharpExceptionType type, RelinqScriptExpression root, ConditionalExpression expression, RelinqScriptType inferredTypeOfTest, RelinqScriptType inferredTypeOfIfTrue, RelinqScriptType inferredTypeOfIfFalse) : base(type, root, expression) { InferredTypeOfTest = inferredTypeOfTest; InferredTypeOfIfTrue = inferredTypeOfIfTrue; InferredTypeOfIfFalse = inferredTypeOfIfFalse; }
public void InferTypes(RelinqScriptExpression e, TypeInferenceCache cache, Action<RelinqScriptExpression, TypeInferenceCache> impl) { Action<RelinqScriptExpression, TypeInferenceCache> wrappedImpl = (e1, cache1) => { #if TRACE var id = BeforeCall(e, cache); try { impl(e, cache); } finally { AfterCall(id, e, cache); } #else impl(e, cache); #endif }; if (Cache == null) { wrappedImpl(e, cache); } else { Cache.RunThroughCache(e, cache, wrappedImpl); } }
public NoSuchMemberException(RelinqScriptExpression root, MemberAccessExpression mae, RelinqScriptType typeOfTarget) : base(mae.Parent is InvokeExpression && mae.ChildIndex == 0 ? JSToCSharpExceptionType.NoSuchMethod : JSToCSharpExceptionType.NoSuchFieldOrProp, root, mae) { InferredTypeOfTarget = typeOfTarget; MemberName = mae.Name; }
public CSharpBuilderException(JSToCSharpExceptionType type, RelinqScriptExpression root, RelinqScriptExpression expression, CompilationContext ctx, Exception innerException) : base(innerException) { Type = type; Root = root; Expression = expression; Context = ctx; }
public ConstantInferenceFailedException(RelinqScriptExpression root, ConstantExpression ce) : base(JSToCSharpExceptionType.ConstantInferenceFailed, root, ce) { Constant = ce.Content; TokenType = String.Format("{0}.{1} ({2})", typeof(EcmaScriptV3Lexer).Name, ce.Token.Type.GetSymbolicName<EcmaScriptV3Parser>(), ce.Token.Type); }
public TypeInferenceException(JSToCSharpExceptionType type, RelinqScriptExpression root, RelinqScriptExpression expression, Exception innerException) : base(innerException) { Type = type; Root = root; Expression = expression; var full = TypeInferenceEngine._sap.History.ToArray(); History = full.Where(e => e.Expression.IsIndirectChildOf(root)).ToArray(); }
public TypeInferenceContext(RelinqScriptExpression root, TypeInferenceCache inferences, IntegrationContext integration) { Root = root; // ctx.Root might only be one of the following: // * Invoke expression (for both cases of compile-time and late-bound invocation) // * Indexer or Operator expression // * Root of an entire AST if (Root.Parent != null && !Root.IsCall()) { throw new NotSupportedException(root.ToString()); } Inferences = inferences; Integration = integration; }
private Guid BeforeCall(RelinqScriptExpression e, TypeInferenceCache cache) { var startedEntry = new TypeInferenceHistoryEntry{Expression = e}; startedEntry.InferredType = cache.ContainsKey(e) ? cache[e] : null; History.Add(startedEntry); Func<LambdaExpression, String, RelinqScriptType> argType = (lambda, arg) => { var argIndex = Array.IndexOf(lambda.Args.ToArray(), arg); var lambdaType = ((Lambda)cache[lambda]).Type.GetFunctionSignature(); return lambdaType.GetParameters()[argIndex].ParameterType; }; e.GetClosure().ForEach(kvp => startedEntry.Closure.Add(kvp.Key, cache.ContainsKey(kvp.Value) ? argType(kvp.Value, kvp.Key) : null)); return startedEntry.Id; }
public CSharpBuilderException(JSToCSharpExceptionType type, RelinqScriptExpression root, RelinqScriptExpression expression, CompilationContext ctx) : this(type, root, expression, ctx, null) { }
public static bool IsIndirectChildOf(this RelinqScriptExpression e1, RelinqScriptExpression e2) { if (e1 == null || e2 == null) return false; return e1 == e2 || IsIndirectChildOf(e1.Parent, e2); }
public MemberAccessExpression(String name, RelinqScriptExpression target) : base(ExpressionType.MemberAccess, target.AsArray()) { Name = name; Target = Children.ElementAt(0); }
private void InferTypesImpl(RelinqScriptExpression e, TypeInferenceCache cache) { try { switch (e.NodeType) { case ExpressionType.Keyword: InferKeyword((KeywordExpression)e, cache); break; case ExpressionType.Variable: InferVariable((VariableExpression)e, cache); break; case ExpressionType.Constant: InferConstant((ConstantExpression)e, cache); break; case ExpressionType.New: InferNew((NewExpression)e, cache); break; case ExpressionType.Lambda: InferLambda((LambdaExpression)e, cache); break; case ExpressionType.MemberAccess: InferMemberAccess((MemberAccessExpression)e, cache); break; case ExpressionType.Invoke: InferInvoke((InvokeExpression)e, cache); break; case ExpressionType.Indexer: InferIndexer((IndexerExpression)e, cache); break; case ExpressionType.Operator: InferOperator((OperatorExpression)e, cache); break; case ExpressionType.Conditional: InferConditional((ConditionalExpression)e, cache); break; default: throw new TypeInferenceException( JSToCSharpExceptionType.UnexpectedNodeType, Root, e); } } catch (TypeInferenceException) { throw; } catch (Exception ex) { throw new TypeInferenceException( JSToCSharpExceptionType.Unexpected, Root, e, ex); } }
public TypeInferenceException(JSToCSharpExceptionType type, RelinqScriptExpression root, RelinqScriptExpression expression) : this(type, root, expression, null) { }
public InvokeExpression(RelinqScriptExpression target, IEnumerable<RelinqScriptExpression> args) : base(ExpressionType.Invoke, target.AsArray().Concat(args)) { Target = Children.ElementAt(0); Args = Children.Skip(1); }
private void SeekRootToLeafPathsRecursive(RelinqScriptExpression node, List<String> ln) { if (node.Children.Count() == 0) ln.Add(node.ShortTPath); node.Children.ForEach(child => SeekRootToLeafPathsRecursive(child, ln)); }
public TypeInferenceEngine(RelinqScriptExpression ast, IntegrationContext integration) { Ctx = new TypeInferenceContext(ast, new TypeInferenceCache(), integration); }
private void InferMethodGroup(MethodGroup mg, RelinqScriptExpression root, TypeInferenceCache cache) { // q: should existing but not accessible (security!) methods be included into the resolution? // a: yes and here's why: // scenario 1. Included; when overload resolution binds to an unauthorized method = crash. // scenario 2. Not included, so overload resolution binds to an unexpected method = fail. // lets us the fail fast if the resolution is unnecessary. // inferences made here won't be wasted anyways since they get cached var ctx = new TypeInferenceContext(root, cache, Integration); var preview = new TypeInferenceEngine(ctx); root.CallArgs().ForEach(child => preview.InferTypes(child)); // we cannot pass the preview.Ctx inside since it might have // potentially half-inferred lambdas that won't be able to be reinferred // by MG resolution since ctx is init only. var resolved = mg.Resolve(ctx); cache.Add(root, resolved.Signature.ReturnType); cache.Invocations.Add(root, resolved); cache.Upgrade(resolved.Inferences); }
public VariableOverridesKeywordException(RelinqScriptExpression root, LambdaExpression le, String name) : base(JSToCSharpExceptionType.VariableOverridesKeyword, root, le) { Name = name; }
public ConditionalExpression(RelinqScriptExpression cond, RelinqScriptExpression ifTrue, RelinqScriptExpression ifFalse) : base(ExpressionType.Conditional, new []{cond, ifTrue, ifFalse}) { }
public NoSuchIndexerException(RelinqScriptExpression root, IndexerExpression ie, RelinqScriptType typeOfTarget) : base(JSToCSharpExceptionType.NoSuchIndexer, root, ie) { InferredTypeOfTarget = typeOfTarget; }
public LambdaExpression(IEnumerable<String> args, RelinqScriptExpression body) : base(ExpressionType.Lambda, body.AsArray()) { Args = args; Body = Children.ElementAt(0); }
public UndeclaredVariableException(RelinqScriptExpression root, VariableExpression ve, Closure closure) : base(JSToCSharpExceptionType.UndeclaredVariable, root, ve) { Closure = closure; Name = ve.Name; }
public CannotResolveQuasiTypeFromContextException(RelinqScriptExpression root, RelinqScriptExpression expression, CompilationContext ctx) : base(JSToCSharpExceptionType.CannotResolveQuasiTypeFromContext, root, expression, ctx) { }
public TypeInferenceCache InferTypes(RelinqScriptExpression e) { InferTypes(e, Inferences); return Inferences; }
public NoSuchOperatorException(RelinqScriptExpression root, OperatorExpression oe, IEnumerable<RelinqScriptType> operandTypes) : base(JSToCSharpExceptionType.NoSuchIndexer, root, oe) { InferredOperandTypes = operandTypes.ToArray(); OperatorName = oe.Type.GetOpCode(); }
private void InferTypes(RelinqScriptExpression e, TypeInferenceCache cache) { _sap.InferTypes(e, cache, InferTypesImpl); }
public CannotForgeAnonymousTypeException(RelinqScriptExpression root, NewExpression ne, string offendingProperty, RelinqScriptType offendingType) : base(JSToCSharpExceptionType.CannotForgeAnonymousType, root, ne) { OffendingProperty = offendingProperty; OffendingType = offendingType; }
private List<String> GetAllRootToLeafPaths(RelinqScriptExpression root) { var ln = new List<String>(); SeekRootToLeafPathsRecursive(root, ln); return ln; }