コード例 #1
0
        private Expression ImplementInitializingMixins(ThisExpression @this, IList <Type> expectedMixinTypes, Expression isDeserialization)
        {
            var mixinInitExpressions = new List <Expression>();

            for (int i = 0; i < expectedMixinTypes.Count; i++)
            {
                if (typeof(IInitializableMixin).IsTypePipeAssignableFrom(expectedMixinTypes[i]))
                {
                    // ((IInitializableMixin) __extensions[i]).Initialize (mixinTargetInstance, <NewNextCallProxy (i + 1)>, isDeserialization);

                    var initExpression = Expression.Call(
                        Expression.Convert(
                            Expression.ArrayAccess(_extensionsField, Expression.Constant(i)),
                            typeof(IInitializableMixin)),
                        s_initializeMixinMethod,
                        @this,
                        NewNextCallProxy(@this, i + 1),
                        isDeserialization);

                    mixinInitExpressions.Add(initExpression);
                }
            }

            return(Expression.BlockOrEmpty(mixinInitExpressions));
        }
コード例 #2
0
 public override INode VisitThisExpression(ThisExpression thisExpression)
 {
     return(new ThisExpression(thisExpression.Context)
     {
         Type = thisExpression.Type
     });
 }
コード例 #3
0
        public void ThisExpression()
        {
            var e = new ThisExpression();

            Assert.IsTrue(e.IsTrivial);
            Assert.AreEqual("this", e.ToString());
        }
コード例 #4
0
        /// <inheritdoc />
        protected override EvaluationResult DoEval(Context context, ModuleLiteral env, EvaluationStackFrame frame)
        {
            var receiver = ThisExpression.Eval(context, env, frame);

            if (receiver.IsErrorValue)
            {
                return(EvaluationResult.Error);
            }

            if (receiver.Value is ObjectLiteral obj)
            {
                if (Selector.GetParent(context.FrontEndContext.SymbolTable) != FullSymbol.Invalid)
                {
                    context.Errors.ReportFailResolveModuleSelector(env, this);
                    return(EvaluationResult.Error);
                }

                return(obj.GetOrEvalField(
                           context,
                           Selector.GetName(context.FrontEndContext.SymbolTable),
                           recurs: false,
                           origin: env,
                           location: Location));
            }

            context.Errors.ReportUnexpectedValueType(
                env,
                ThisExpression,
                receiver, new[] { typeof(ModuleLiteral), typeof(ObjectLiteral) });

            return(EvaluationResult.Error);
        }
コード例 #5
0
        public void SetUp()
        {
            _declaringType        = ObjectMother.GetMutableType();
            _parameterExpression1 = ObjectMother.GetParameterExpression(typeof(string), "param1");
            _parameterExpression2 = ObjectMother.GetParameterExpression(typeof(int), "param2");
            _thisExpression       = new ThisExpression(_declaringType);

            _callExpressionHelperMock = MockRepository.GenerateStrictMock <ICallExpressionHelper> ();
            _invocationType           = typeof(FuncContext <object, string, int, int>);
            _memberFieldMock          = MockRepository.GenerateStrictMock <IStorage> ();
            _delegateFieldMock        = MockRepository.GenerateStrictMock <IStorage> ();
            _aspectFieldMock1         = MockRepository.GenerateStrictMock <IStorage> ();
            _aspectFieldMock2         = MockRepository.GenerateStrictMock <IStorage> ();
            _adviceMethod1            = ObjectMother.GetMethodInfo();
            _adviceMethod2            = ObjectMother.GetMethodInfo();
            var advices = new[] { Tuple.Create(_adviceMethod1, _aspectFieldMock1), Tuple.Create(_adviceMethod2, _aspectFieldMock2) };

            _expressionHelper = new InterceptionExpressionHelper(
                _callExpressionHelperMock,
                _thisExpression,
                new[] { _parameterExpression1, _parameterExpression2 },
                _invocationType,
                advices,
                _memberFieldMock,
                _delegateFieldMock);
        }
コード例 #6
0
ファイル: IndexExpression.cs プロジェクト: kittinap/kunnjae
        /// <inheritdoc />
        protected override EvaluationResult DoEval(Context context, ModuleLiteral env, EvaluationStackFrame frame)
        {
            var e = ThisExpression.Eval(context, env, frame);

            if (e.IsErrorValue)
            {
                return(EvaluationResult.Error);
            }

            var indexObj = Index.Eval(context, env, frame);

            if (indexObj.IsErrorValue)
            {
                return(EvaluationResult.Error);
            }

            // Extracting local to avoid casting multiple times
            var stringIndexer = indexObj.Value as string;

            if (e.Value is ArrayLiteral arrayLiteral)
            {
                if (indexObj.Value is int index)
                {
                    if (index < 0 || index >= arrayLiteral.Length)
                    {
                        // This behavior is different from the TypeScript one, but this is actually helpful
                        context.Errors.ReportArrayIndexOufOfRange(env, this, index, arrayLiteral.Length);
                        return(EvaluationResult.Error);
                    }

                    return(arrayLiteral[index]);
                }

                // indexer for an array can be a number for getting elements, or string
                if (stringIndexer == null)
                {
                    context.Errors.ReportUnexpectedValueType(env, Index, indexObj, typeof(int), typeof(string));
                    return(EvaluationResult.Error);
                }

                // Falling back to object literal case if the indexer is a string.
            }

            if (e.Value is ObjectLiteral objectLiteral)
            {
                if (stringIndexer != null)
                {
                    var selectorId = context.FrontEndContext.StringTable.AddString(stringIndexer);
                    return(objectLiteral.GetOrEvalField(context, selectorId, recurs: false, origin: env, location: Location));
                }

                context.Errors.ReportUnexpectedValueType(env, Index, indexObj, typeof(string));
                return(EvaluationResult.Error);
            }

            // Indexer in typescript never fails and return undefined.
            // Following this pattern.
            return(EvaluationResult.Undefined);
        }
コード例 #7
0
        public Expression VisitThis(ThisExpression node)
        {
            ArgumentUtility.CheckNotNull("node", node);

            _ilGenerator.Emit(OpCodes.Ldarg_0);

            return(node);
        }
コード例 #8
0
 public ThisAction(ParseInfo parseInfo, Scope scope, ThisExpression context)
 {
     ThisType = scope.GetThis();
     if (ThisType == null)
     {
         parseInfo.Script.Diagnostics.Error("Keyword 'this' cannot be used here.", context.Range);
     }
 }
コード例 #9
0
ファイル: ParserTests.cs プロジェクト: Xadneil/JSInterpreter
        public void ShouldParseThis()
        {
            var program = new Parser.Parser("this").ParseScript();
            var body    = program.scriptBody.statements;

            Assert.Single(body);
            Assert.Equal(ThisExpression.Instance(false), body.First().As <ExpressionStatement>().expression.As <ThisExpression>());
        }
コード例 #10
0
        public static MethodExecutionExpression Adapt(MutableMethodInfo method)
        {
            var instance   = new ThisExpression(method.DeclaringType);
            var baseMethod = NonVirtualCallMethodInfoAdapter.Adapt(method.UnderlyingSystemMethodInfo);
            var parameters = method.ParameterExpressions.Cast <Expression>();
            var body       = Call(instance, baseMethod, parameters);

            return(new MethodExecutionExpression(method, body));
        }
コード例 #11
0
 public override object Visit(ThisExpression node, object obj)
 {
     if (node.Location == ((AstNode)obj).Location || found)
     {
         found = true;
         return(this.table);
     }
     return(base.Visit(node, obj));
 }
コード例 #12
0
        public Expression VisitThis(ThisExpression node)
        {
            var name = "__value";

            if (HoistedLocals.ContainsKey(name) == false)
            {
                HoistedLocals.Add(name, node);
            }
            return(node);
        }
コード例 #13
0
 public object VisitThis(ThisExpression node)
 {
     if (Target is object)
     {
         node.Type = Target.GetType();
         return(Target);
     }
     node.Type = TypeProvider.ObjectType;
     return(NoTarget);
 }
コード例 #14
0
ファイル: Resolver.cs プロジェクト: neistow/Enkel
        public Unit VisitThisExpression(ThisExpression expression)
        {
            if (_currentClass == ClassType.None)
            {
                throw new ResolveException("Can't use 'this' outside of class");
            }

            ResolveLocal(expression, expression.Token);
            return(Unit.Value);
        }
コード例 #15
0
ファイル: Resolver.cs プロジェクト: h2oboi89/lox
        public object VisitThisExpression(ThisExpression expression)
        {
            if (scope.InClass)
            {
                scope.ResolveValue(expression, expression.Keyword);
            }
            else
            {
                Interpreter.ScopeError(expression.Keyword, "Cannot use 'this' outside of a class.");
            }

            return(null);
        }
コード例 #16
0
        /// <summary>
        /// Validation, checking whether the member is a valid property.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public MemberExpression Validate(IValidationScope context)
        {
            var @this      = ThisExpression.Validate(context);
            var thisType   = @this.SemanticType;
            var csharpType = context.TypeSystem.GetTypeByNative(thisType);
            var symbol     = csharpType.GetByName(Delimiter, MemberName);

            if (!(symbol is IProperty))
            {
                throw new LocateableException(Location, "Expecting property!");
            }
            validatedProperty = symbol as IProperty;
            SemanticType      = validatedProperty.ReturnType;
            return(this);
        }
コード例 #17
0
        /// <summary>
        /// Outputs a user-friendly representation of this expression.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            var delimiter = "";

            switch (Delimiter)
            {
            case IdDelimiter.Dollar: delimiter = "$"; break;

            case IdDelimiter.Dot: delimiter = "."; break;

            case IdDelimiter.Hash: delimiter = "#"; break;

            case IdDelimiter.SingleArrow: delimiter = "->"; break;

            case IdDelimiter.Slash: delimiter = "/"; break;
            }
            return($"{ThisExpression.ToString()}{delimiter}{MemberName}");
        }
コード例 #18
0
        public static ThisExpression Create(
            AphidExpressionContext context_aphidExpressionContext,
            int value_i,
            int value_i1
            )
        {
            ThisExpression thisExpression
                = new ThisExpression(context_aphidExpressionContext);

            ((AphidExpression)thisExpression).Index  = value_i;
            ((AphidExpression)thisExpression).Length = value_i1;
            return(thisExpression);

            // TODO: Edit factory method of ThisExpression
            // This method should be able to configure the object in all possible ways.
            // Add as many parameters as needed,
            // and assign their values to each field by using the API.
        }
コード例 #19
0
        /// <summary>
        /// Adds new assignment statements at the end of the specified block.
        /// </summary>
        /// <param name="vars">Information of the current scope in SSAMap.</param>
        /// <param name="node">Block of statement to add the new declarations.</param>
        private void addAssignmentStatements(Dictionary <string, SSAElement> vars, Block node)
        {
            FieldAccessExpression      op1;
            SingleIdentifierExpression eop1;
            SingleIdentifierExpression op2;
            ThisExpression             th = new ThisExpression(node.Location);

            foreach (KeyValuePair <string, SSAElement> pair in vars)
            {
                if (pair.Value.IndexSSA > 0)
                {
                    eop1            = new SingleIdentifierExpression(pair.Key.Substring(6, pair.Key.Length - 6), node.Location);
                    eop1.IndexOfSSA = -1;
                    op1             = new FieldAccessExpression(th, eop1, node.Location);
                    op2             = new SingleIdentifierExpression(pair.Key, node.Location);
                    op2.IndexOfSSA  = pair.Value.IndexSSA;
                    node.AddStatement(new AssignmentExpression(op1, op2, AssignmentOperator.Assign, node.Location));
                }
            }
        }
コード例 #20
0
        /// <inheritdoc />
        protected override EvaluationResult DoEval(Context context, ModuleLiteral env, EvaluationStackFrame frame)
        {
            var receiver = ThisExpression.Eval(context, env, frame);

            if (receiver.IsErrorValue)
            {
                return(EvaluationResult.Error);
            }

            if (receiver.IsUndefined)
            {
                context.Errors.ReportFailResolveSelectorDueToUndefined(env, this);
                return(EvaluationResult.Error);
            }

            if (receiver.Value is Expression thisExpressionResult)
            {
                if (thisExpressionResult.TryProject(context, Selector, env, context.PredefinedTypes, out EvaluationResult projectionResult, Location))
                {
                    return(projectionResult);
                }

                context.Errors.ReportUnexpectedValueType(
                    env,
                    ThisExpression,
                    receiver, typeof(ObjectLiteral), typeof(ArrayLiteral), typeof(ModuleLiteral));
                return(EvaluationResult.Error);
            }

            // Trying to find member function for well-known types.
            var boundMember = context.PredefinedTypes.ResolveMember(receiver.Value, Selector);

            if (boundMember != null)
            {
                // If bound member represents a property we need to evaluate it.
                return(boundMember.IsProperty ? EvaluateAmbientProperty(context, env, boundMember) : EvaluationResult.Create(boundMember));
            }

            context.Errors.ReportMissingProperty(env, Selector, receiver.Value, Location);
            return(EvaluationResult.Error);
        }
コード例 #21
0
ファイル: OtherExpressions.cs プロジェクト: Beier/Omnium
        public override void ExitThisExpression(ThisExpression thisExpression)
        {
            var classDeclaration = thisExpression.NearestAncestorOfType <ClassDeclaration>();

            if (classDeclaration == null)
            {
                Errors.Add(new CompilationError(thisExpression.Context, "The this keyword can only be used inside classes"));
                thisExpression.Type = new NullType();
            }
            else if (classDeclaration.GenericTypeDeclarations.Any())
            {
                thisExpression.Type = new GenericType(thisExpression.Context,
                                                      ReferenceToType(thisExpression.Context, classDeclaration).Yield()
                                                      .Concat(classDeclaration.GenericTypeDeclarations.Select(x => ReferenceToType(thisExpression.Context, x)))
                                                      );
            }
            else
            {
                thisExpression.Type = ReferenceToType(thisExpression.Context, classDeclaration);
            }
        }
コード例 #22
0
ファイル: ExpressionIntepreter.cs プロジェクト: skipme/jint
 public JsValue EvaluateThisExpression(ThisExpression thisExpression)
 {
     return _engine.ExecutionContext.ThisBinding;
 }
コード例 #23
0
 /// <inheritdoc />
 public override string ToDebugString()
 {
     return(I($"{ThisExpression.ToDebugString()}.{ToDebugString(Selector)}"));
 }
コード例 #24
0
 /// <inheritdoc />
 public override string ToStringShort(StringTable stringTable)
 {
     return(I($"{ThisExpression.ToStringShort(stringTable)}.{Selector.ToString(stringTable)}"));
 }
コード例 #25
0
 /// <inheritdoc />
 protected override void DoSerialize(BuildXLWriter writer)
 {
     ThisExpression.Serialize(writer);
     writer.Write(Selector);
 }
 protected virtual void Write(IndentedTextWriter writer, ThisExpression expression)
 {
     writer.Write("this");
 }
コード例 #27
0
        public Expression ParseFactor()
        {
            Expression exp;

            switch (_currentToken.TokenType)
            {
            case AphidTokenType.LeftBrace:
                exp = ParseObjectExpression();
                break;

            case AphidTokenType.LeftBracket:
                exp = ParseArrayExpression();
                break;

            case AphidTokenType.LeftParenthesis:
                NextToken();
                exp = ParseExpression();
                Match(AphidTokenType.RightParenthesis);
                break;

            case AphidTokenType.String:
                exp = ParseStringExpression();
                break;

            case AphidTokenType.Number:
                exp = ParseNumberExpression();
                break;

            case AphidTokenType.MinusOperator:
                NextToken();
                var numExp = ParseNumberExpression();
                numExp.Value *= -1;
                exp           = numExp;
                break;

            case AphidTokenType.Identifier:
                exp = ParseIdentifierExpression();

                if (_currentToken.TokenType == AphidTokenType.definedKeyword)
                {
                    NextToken();
                    exp = new UnaryOperatorExpression(AphidTokenType.definedKeyword, exp)
                    {
                        IsPostfix = true
                    };
                }

                break;

            case AphidTokenType.functionOperator:
                exp = ParseFunctionExpression();
                break;

            //case AphidTokenType.forKeyword:
            //    exp = ParseForExpression();
            //    break;

            case AphidTokenType.retKeyword:
            case AphidTokenType.deleteKeyword:
                exp = ParseUnaryExpression();
                break;

            case AphidTokenType.trueKeyword:
                exp = new BooleanExpression(true);
                NextToken();
                break;

            case AphidTokenType.falseKeyword:
                exp = new BooleanExpression(false);
                NextToken();
                break;

            case AphidTokenType.thisKeyword:
                exp = new ThisExpression();
                NextToken();
                break;

            //case AphidTokenType.extendKeyword:
            //    exp = ParseExtendExpression();
            //    break;

            //case AphidTokenType.ifKeyword:
            //    exp = ParseIfExpression();
            //    break;

            case AphidTokenType.LoadScriptOperator:
                exp = ParseLoadScriptExpression();
                break;

            case AphidTokenType.LoadLibraryOperator:
                exp = ParseLoadLibraryExpression();
                break;

            case AphidTokenType.nullKeyword:
                exp = new NullExpression();
                NextToken();
                break;

            case AphidTokenType.breakKeyword:
                exp = new BreakExpression();
                NextToken();
                break;

            case AphidTokenType.HexNumber:
                exp = new NumberExpression((decimal)Convert.ToInt64(_currentToken.Lexeme.Substring(2), 16));
                NextToken();
                break;

            case AphidTokenType.PatternMatchingOperator:
                var matchExp = new PatternMatchingExpression();
                NextToken();
                Match(AphidTokenType.LeftParenthesis);
                matchExp.TestExpression = ParseExpression();
                Match(AphidTokenType.RightParenthesis);

                while (true)
                {
                    var tests = new List <Expression>();

                    while (true)
                    {
                        tests.Add(ParseExpression());

                        if (_currentToken.TokenType == AphidTokenType.Comma)
                        {
                            NextToken();
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (_currentToken.TokenType == AphidTokenType.ColonOperator)
                    {
                        NextToken();

                        var b = ParseExpression();

                        foreach (var t in tests)
                        {
                            matchExp.Patterns.Add(new Tuple <Expression, Expression>(t, b));
                        }
                    }
                    else
                    {
                        matchExp.Patterns.Add(new Tuple <Expression, Expression>(null, tests[0]));
                    }

                    if (_currentToken.TokenType == AphidTokenType.Comma)
                    {
                        NextToken();
                    }
                    else
                    {
                        break;
                    }
                }

                exp = matchExp;
                break;

            default:
                throw new AphidParserException(_currentToken);
            }

            return(exp);
        }
コード例 #28
0
 public JsValue EvaluateThisExpression(ThisExpression thisExpression)
 {
     return(_engine.ExecutionContext.ThisBinding);
 }
コード例 #29
0
 public MemberReferenceExpression(MemberDeclaration memberDeclaration)
 {
     TargetObject       = new ThisExpression();
     _memberDeclaration = memberDeclaration;
 }
コード例 #30
0
 public virtual void Visit(ThisExpression node)
 {
 }
コード例 #31
0
 private static void WriteThis(CodeTextBuilder code, ThisExpression expression)
 {
     code.Write("this");
 }
コード例 #32
0
ファイル: StatementVisitor.cs プロジェクト: crazyants/NWheels
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public virtual void VisitThisExpression(ThisExpression expression)
        {
            VisitAbstractExpression(expression);
        }
コード例 #33
0
 private void EmitThisExpression(ThisExpression e)
 {
     Write("this");
 }
コード例 #34
0
        public void ThisExpressionProducesThis()
        {
            var expression = new ThisExpression();

            Assert.AreEqual("this;", expression.ToString());
        }