コード例 #1
0
 public TypeInferenceOperationKey(
     RelinqScriptExpression self, RelinqScriptType myType, IEnumerable<Type> closure)
 {
     Self = self.SurelyNotNull();
     MyType = myType;
     Closure = closure;
 }
コード例 #2
0
ファイル: TypeInferenceProxy.cs プロジェクト: xeno-by/relinq
        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();
        }
コード例 #3
0
 public InconsistentConditionalExpression(JSToCSharpExceptionType type, RelinqScriptExpression root, ConditionalExpression expression, RelinqScriptType inferredTypeOfTest, RelinqScriptType inferredTypeOfIfTrue, RelinqScriptType inferredTypeOfIfFalse) 
     : base(type, root, expression)
 {
     InferredTypeOfTest = inferredTypeOfTest;
     InferredTypeOfIfTrue = inferredTypeOfIfTrue;
     InferredTypeOfIfFalse = inferredTypeOfIfFalse;
 }
コード例 #4
0
ファイル: TypeInferenceProxy.cs プロジェクト: xeno-by/relinq
        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);
            }
        }
コード例 #5
0
 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;
 }
コード例 #6
0
 public CSharpBuilderException(JSToCSharpExceptionType type, RelinqScriptExpression root, RelinqScriptExpression expression, CompilationContext ctx, Exception innerException)
     : base(innerException)
 {
     Type = type;
     Root = root;
     Expression = expression;
     Context = ctx;
 }
コード例 #7
0
 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);
 }
コード例 #8
0
        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();
        }
コード例 #9
0
        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;
        }
コード例 #10
0
ファイル: TypeInferenceProxy.cs プロジェクト: xeno-by/relinq
        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;
        }
コード例 #11
0
 public CSharpBuilderException(JSToCSharpExceptionType type, RelinqScriptExpression root, RelinqScriptExpression expression, CompilationContext ctx)
     : this(type, root, expression, ctx, null)
 {
 }
コード例 #12
0
ファイル: ExpressionsHelper.cs プロジェクト: xeno-by/relinq
 public static bool IsIndirectChildOf(this RelinqScriptExpression e1, RelinqScriptExpression e2)
 {
     if (e1 == null || e2 == null) return false;
     return e1 == e2 || IsIndirectChildOf(e1.Parent, e2);
 }
コード例 #13
0
 public MemberAccessExpression(String name, RelinqScriptExpression target)
     : base(ExpressionType.MemberAccess, target.AsArray())
 {
     Name = name;
     Target = Children.ElementAt(0);
 }
コード例 #14
0
ファイル: TypeInferenceEngine.cs プロジェクト: xeno-by/relinq
        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);
            }
        }
コード例 #15
0
 public TypeInferenceException(JSToCSharpExceptionType type, RelinqScriptExpression root, RelinqScriptExpression expression)
     : this(type, root, expression, null)
 {
 }
コード例 #16
0
ファイル: InvokeExpression.cs プロジェクト: xeno-by/relinq
 public InvokeExpression(RelinqScriptExpression target, IEnumerable<RelinqScriptExpression> args)
     : base(ExpressionType.Invoke, target.AsArray().Concat(args))
 {
     Target = Children.ElementAt(0);
     Args = Children.Skip(1);
 }
コード例 #17
0
 private void SeekRootToLeafPathsRecursive(RelinqScriptExpression node, List<String> ln)
 {
     if (node.Children.Count() == 0) ln.Add(node.ShortTPath);
     node.Children.ForEach(child => SeekRootToLeafPathsRecursive(child, ln));
 }
コード例 #18
0
ファイル: TypeInferenceEngine.cs プロジェクト: xeno-by/relinq
 public TypeInferenceEngine(RelinqScriptExpression ast, IntegrationContext integration)
 {
     Ctx = new TypeInferenceContext(ast, new TypeInferenceCache(), integration);
 }
コード例 #19
0
ファイル: TypeInferenceEngine.cs プロジェクト: xeno-by/relinq
        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);
        }
コード例 #20
0
 public VariableOverridesKeywordException(RelinqScriptExpression root, LambdaExpression le, String name)
     : base(JSToCSharpExceptionType.VariableOverridesKeyword, root, le)
 {
     Name = name;
 }
コード例 #21
0
 public ConditionalExpression(RelinqScriptExpression cond, RelinqScriptExpression ifTrue, RelinqScriptExpression ifFalse)
     : base(ExpressionType.Conditional, new []{cond, ifTrue, ifFalse})
 {
 }
コード例 #22
0
 public NoSuchIndexerException(RelinqScriptExpression root, IndexerExpression ie, RelinqScriptType typeOfTarget)
     : base(JSToCSharpExceptionType.NoSuchIndexer, root, ie)
 {
     InferredTypeOfTarget = typeOfTarget;
 }
コード例 #23
0
ファイル: LambdaExpression.cs プロジェクト: xeno-by/relinq
 public LambdaExpression(IEnumerable<String> args, RelinqScriptExpression body)
     : base(ExpressionType.Lambda, body.AsArray())
 {
     Args = args;
     Body = Children.ElementAt(0);
 }
コード例 #24
0
 public UndeclaredVariableException(RelinqScriptExpression root, VariableExpression ve, Closure closure) 
     : base(JSToCSharpExceptionType.UndeclaredVariable, root, ve)
 {
     Closure = closure;
     Name = ve.Name;
 }
コード例 #25
0
 public CannotResolveQuasiTypeFromContextException(RelinqScriptExpression root, RelinqScriptExpression expression, CompilationContext ctx)
     : base(JSToCSharpExceptionType.CannotResolveQuasiTypeFromContext, root, expression, ctx)
 {
 }
コード例 #26
0
ファイル: TypeInferenceEngine.cs プロジェクト: xeno-by/relinq
 public TypeInferenceCache InferTypes(RelinqScriptExpression e)
 {
     InferTypes(e, Inferences);
     return Inferences;
 }
コード例 #27
0
 public NoSuchOperatorException(RelinqScriptExpression root, OperatorExpression oe, IEnumerable<RelinqScriptType> operandTypes)
     : base(JSToCSharpExceptionType.NoSuchIndexer, root, oe)
 {
     InferredOperandTypes = operandTypes.ToArray();
     OperatorName = oe.Type.GetOpCode();
 }
コード例 #28
0
ファイル: TypeInferenceEngine.cs プロジェクト: xeno-by/relinq
 private void InferTypes(RelinqScriptExpression e, TypeInferenceCache cache)
 {
     _sap.InferTypes(e, cache, InferTypesImpl);
 }
コード例 #29
0
 public CannotForgeAnonymousTypeException(RelinqScriptExpression root, NewExpression ne, string offendingProperty, RelinqScriptType offendingType)
     : base(JSToCSharpExceptionType.CannotForgeAnonymousType, root, ne)
 {
     OffendingProperty = offendingProperty;
     OffendingType = offendingType;
 }
コード例 #30
0
 private List<String> GetAllRootToLeafPaths(RelinqScriptExpression root)
 {
     var ln = new List<String>();
     SeekRootToLeafPathsRecursive(root, ln);
     return ln;
 }