示例#1
0
        private void set(AnalyzingContext context)
        {
            var This  = context.CurrentArguments[0];
            var value = context.CurrentArguments[1];

            context.SetField(This, _fieldName, value);
        }
示例#2
0
        /// <summary>
        /// Handler called whenever call on null instance is detected.
        /// </summary>
        /// <param name="context">Context used during analysis.</param>
        private void nullCallHandler(AnalyzingContext context)
        {
            AppDomain.Log("WARNING", "Call on null instance detected: " + context.CurrentCall.Name);

            foreach (var argument in context.CurrentArguments.Skip(1))
            {
                if (argument.IsDirty)
                {
                    continue;
                }

                if (Settings.IsDirect(argument.Info))
                {
                    continue;
                }

                if (argument.Info.TypeName == Runtime.Null.TypeInfo.TypeName)
                {
                    continue;
                }

                context.SetDirty(argument);
                AppDomain.Log("WARNING", "Setting dirty flag for {0}", argument);
            }
        }
        protected virtual bool GetDivide(Token result, AnalyzingContext context)
        {
            var count = context.SourceCode.Length;

            //item.CharType: Colon
            //Mapped nodes:
            //    "//" "/*"
            if (context.NextLetterIndex + 2 <= count)
            {
                var str = context.SourceCode.Substring(context.NextLetterIndex, 2);
                if ("//" == str)
                {
                    SkipSingleLineNote(context);
                    return(false);
                }
                else if ("/*" == str)
                {
                    SkipMultilineNote(context);
                    return(false);
                }
            }

            result.TokenType = new TokenType(
                "__error", context.CurrentChar().ToString(), context.CurrentChar().ToString());
            result.LexicalError = true;
            context.NextLetterIndex++;
            return(true);
        }
        /// <summary>
        /// ;
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        protected virtual bool GetSemicolon(Token result, AnalyzingContext context)
        {
            var count = context.SourceCode.Length;

            //item.CharType: greaterThan
            //Mapped nodes:
            //    ""
            if (context.NextLetterIndex + 1 <= count)
            {
                var str = context.SourceCode.Substring(context.NextLetterIndex, 1);
                if (";" == str)
                {
                    result.TokenType = new TokenType(
                        ContextfreeGrammarTokenType.__semicolon, str, "\"" + str + "\"");
                    context.NextLetterIndex += 1;
                    return(true);
                }
            }

            result.TokenType = new TokenType(
                "__error", context.CurrentChar().ToString(), context.CurrentChar().ToString());
            result.LexicalError = true;
            context.NextLetterIndex++;
            return(true);
        }
示例#5
0
 /// <summary>
 /// Executes instruction in given context.
 /// </summary>
 /// <param name="context">Context where instruction is executed.</param>
 public override void Execute(AnalyzingContext context)
 {
     if (context.IsTrue(_condition))
     {
         context.Jump(Target);
     }
 }
示例#6
0
        public override void Execute(AnalyzingContext context)
        {
            //literal can have another initial values from previous cached runs,
            //however literal behaves like it is created again so we will reset
            //previous flags.
            _literal.IsDirty       = false;
            _literal.CreationBlock = context.CurrentCall.CurrentBlock;

            context.SetValue(_targetVariable, _literal);
        }
示例#7
0
 private static void Validate(AnalyzingContext context)
 {
     if (context.NumberOfOpenedParentheses != context.NumberOfClosedParentheses)
     {
         throw new FormatException("Number of opened and closed parentheses does not match");
     }
     if (context.OpenedStrings != context.ClosedStrings)
     {
         throw new FormatException("Unterminated string");
     }
 }
示例#8
0
 private void EnsureParenthesesAreWellFormed(Token token, AnalyzingContext context)
 {
     if (token.TokenType == TokenType.OpeningParenthesis)
     {
         context.NumberOfOpenedParentheses++;
     }
     else if (token.TokenType == TokenType.ClosingParenthesis)
     {
         context.NumberOfClosedParentheses++;
     }
 }
示例#9
0
 private static void Validate(AnalyzingContext context)
 {
     if (context.NumberOfOpenedParentheses != context.NumberOfClosedParentheses)
     {
         throw new FormatException("Number of opened and closed parentheses does not match");
     }
     if (context.OpenedStrings != context.ClosedStrings)
     {
         throw new FormatException("Unterminated string");
     }
 }
示例#10
0
 private void EnsureParenthesesAreWellFormed(Token token, AnalyzingContext context)
 {
     if (token.TokenType == TokenType.OpeningParenthesis)
     {
         context.NumberOfOpenedParentheses++;
     }
     else if (token.TokenType == TokenType.ClosingParenthesis)
     {
         context.NumberOfClosedParentheses++;
     }
 }
        protected override bool TryGetToken(
            AnalyzingContext context, Token result, SourceCodeCharType charType)
        {
            bool gotToken = false;

            switch (charType)
            {
            case SourceCodeCharType.Letter:
                gotToken = GetLetter(result, context);
                break;

            case SourceCodeCharType.UnderLine:
                gotToken = Getunderline(result, context);
                break;

            case SourceCodeCharType.Or:
                gotToken = GetOr(result, context);
                break;

            case SourceCodeCharType.LessThan:
                gotToken = GetLessThan(result, context);
                break;

            case SourceCodeCharType.GreaterThan:
                gotToken = GetGreaterThan(result, context);
                break;

            case SourceCodeCharType.DoubleQuotation:
                gotToken = GetDoubleQuotation(result, context);
                break;

            case SourceCodeCharType.Semicolon:
                gotToken = GetSemicolon(result, context);
                break;

            case SourceCodeCharType.Colon:
                gotToken = GetColon(result, context);
                break;

            case SourceCodeCharType.Divide:
                gotToken = GetDivide(result, context);
                break;

            case SourceCodeCharType.Space:
                gotToken = GetSpace(result, context);
                break;

            default:
                gotToken = GetUnknown(result, context);
                break;
            }

            return(gotToken);
        }
示例#12
0
 /// <summary>
 /// Executes instruction in given context.
 /// </summary>
 /// <param name="context">Context where instruction is executed.</param>
 /// <exception cref="System.NotSupportedException">Argument is not available</exception>
 public override void Execute(AnalyzingContext context)
 {
     if (context.CurrentArguments.Length > 0)
     {
         var sourceValue = context.CurrentArguments[_argumentNumber];
         context.SetValue(_targetVariable, sourceValue);
     }
     else
     {
         throw new NotSupportedException("Argument is not available");
     }
 }
 private void EnsureStringsAreWellFormed(Token token, AnalyzingContext context)
 {
     if (!context.IsInString && token.TokenType == TokenType.String)
     {
         context.IsInString = true;
         context.OpenedStrings++;
     }
     else if (context.IsInString && token.TokenType == TokenType.String)
     {
         context.IsInString = false;
         context.ClosedStrings++;
     }
 }
示例#14
0
        /// <summary>
        /// Executes instruction in given context.
        /// </summary>
        /// <param name="context">Context where instruction is executed.</param>
        public override void Execute(AnalyzingContext context)
        {
            var newInstance = context.Machine.CreateInstance(_objectInfo);

            if (RemoveProvider != null)
            {
                newInstance.HintCreationNavigation(RemoveProvider.GetNavigation());
            }

            newInstance.CreationBlock = context.CurrentCall.CurrentBlock;

            context.SetValue(_targetVariable, newInstance);
        }
示例#15
0
 private void EnsureStringsAreWellFormed(Token token, AnalyzingContext context)
 {
     if (!context.IsInString && token.TokenType == TokenType.String)
     {
         context.IsInString = true;
         context.OpenedStrings++;
     }
     else if (context.IsInString && token.TokenType == TokenType.String)
     {
         context.IsInString = false;
         context.ClosedStrings++;
     }
 }
示例#16
0
 public void Analyze(IEnumerable<Token> tokens)
 {
     var context = new AnalyzingContext();
     foreach (var token in tokens)
     {
         if (token.TokenType == TokenType.Unrecognized)
         {
             throw new UnrecognizedTokenException(token);
         }
         EnsureParenthesesAreWellFormed(token, context);
         EnsureStringsAreWellFormed(token, context);
     }
     Validate(context);
 }
示例#17
0
        private Instance createInstance(AnalyzingContext context, object directObject)
        {
            if (directObject is Array)
            {
                var enumerable = directObject as System.Collections.IEnumerable;
                var array      = new MEFEditor.TypeSystem.Runtime.Array <InstanceWrap>(enumerable, context);

                return(context.Machine.CreateDirectInstance(array));
            }
            else
            {
                return(context.Machine.CreateDirectInstance(directObject));
            }
        }
示例#18
0
        /// <summary>
        /// Wrap given data of type T into instance.
        /// <remarks>Is called from code emitted by expression tree</remarks>.
        /// </summary>
        /// <typeparam name="T">Type from which instance will be wrapped.</typeparam>
        /// <param name="context">Data to be wrapped.</param>
        /// <param name="data">The data.</param>
        /// <returns>Instance wrapping given data.</returns>
        internal protected virtual Instance Wrap <T>(AnalyzingContext context, T data)
        {
            var machine = context.Machine;

            if (typeof(T).IsArray)
            {
                var array = new Array <InstanceWrap>((System.Collections.IEnumerable)data, context);
                return(machine.CreateDirectInstance(array, TypeDescriptor.Create <T>()));
            }
            else
            {
                return(machine.CreateDirectInstance(data));
            }
        }
示例#19
0
        public void Analyze(IEnumerable <Token> tokens)
        {
            var context = new AnalyzingContext();

            foreach (var token in tokens)
            {
                if (token.TokenType == TokenType.Unrecognized)
                {
                    throw new UnrecognizedTokenException(token);
                }
                EnsureParenthesesAreWellFormed(token, context);
                EnsureStringsAreWellFormed(token, context);
            }
            Validate(context);
        }
示例#20
0
        /// <summary>
        /// Invokes the specified method in given context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="methodToInvoke">The method to invoke.</param>
        internal void Invoke(AnalyzingContext context, DirectMethod methodToInvoke)
        {
            Context = context;
            Edits   = context.Edits;

            try
            {
                This = CurrentArguments[0];
                methodToInvoke(context);
            }
            finally
            {
                This    = null;
                Context = null;
                Edits   = null;
            }
        }
示例#21
0
        private void get(AnalyzingContext context)
        {
            var This = context.CurrentArguments[0];

            Instance fieldValue;

            if (This is DirectInstance)
            {
                fieldValue = null;
            }
            else
            {
                fieldValue = context.GetField(This, _fieldName) as Instance;
            }

            context.Return(fieldValue);
        }
示例#22
0
        /// <summary>
        /// Executes instruction in given context.
        /// </summary>
        /// <param name="context">Context where instruction is executed.</param>
        public override void Execute(AnalyzingContext context)
        {
            if (context.ContainsGlobal(_targetVariable))
            {
                //shared value is already initialized
                return;
            }

            //create shared instance
            var sharedInstance = context.Machine.CreateInstance(_sharedInstanceInfo);

            context.SetGlobal(_targetVariable, sharedInstance);
            if (_initializer != null)
            {
                context.FetchCall(_initializer, new Instance[] { sharedInstance });
            }
        }
示例#23
0
        private Instance createMetaDataInstance(AnalyzingContext analyzingContext, TypeDescriptor metaDataType, MetaExport metaExport)
        {
            var instance = analyzingContext.Machine.CreateInstance(metaDataType);

            //register call handler for instance, that
            //will handle all method calls
            _context.RegisterCallHandler(instance, (c) =>
            {
                var method = Naming.GetMethodName(c.CurrentCall.Name);
                var key    = method.Substring(Naming.GetterPrefix.Length);
                var item   = metaExport.GetItem(key);

                var metaDataInstance = createMetaItemInstance(analyzingContext, item);
                c.Return(metaDataInstance);
            });

            return(instance);
        }
示例#24
0
        /// <summary>
        /// Hints the identifier.
        /// </summary>
        /// <param name="hint">The hint.</param>
        /// <param name="context">The context.</param>
        internal void HintID(string hint, AnalyzingContext context)
        {
            if (

                hint.StartsWith("$") ||
                !ID.StartsWith("$")
                )
            {
                return;
            }

            var idHint = context.Machine.CreateID(hint);
            var oldID  = ID;

            ID = idHint;

            context.Machine.ReportIDChange(oldID);
        }
示例#25
0
        /// <summary>
        /// Run instruction described by given context.
        /// </summary>
        /// <param name="context">Properly initialized context.</param>
        /// <exception cref="System.NotSupportedException">
        /// Entry method hasn't been found
        /// or
        /// Execution limit has been reached
        /// </exception>
        private void runContext(AnalyzingContext context)
        {
            if (context.CurrentCall == null)
            {
                throw new NotSupportedException("Entry method hasn't been found");
            }

            var initialLimit   = Settings.ExecutionLimit;
            var executionLimit = initialLimit;

            //interpretation processing
            while (!context.IsExecutionEnd)
            {
                //process instruction
                var instruction = context.NextInstruction();
                if (instruction == null)
                {
                    break;
                }

                if (executionLimit == initialLimit)
                {
                    //set initial block for argument instances
                    foreach (var instance in _createdInstances)
                    {
                        instance.Value.CreationBlock = context.CurrentCall.CurrentBlock;
                    }
                }

                context.Prepare(instruction);
                instruction.Execute(context);

                //limit execution
                --executionLimit;
                if (executionLimit < 0)
                {
                    throw new NotSupportedException("Execution limit has been reached");
                }
            }
        }
示例#26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Array{ItemType}"/> class from given data.
        /// </summary>
        /// <param name="data">The data which will initialize current array.</param>
        /// <param name="context">The context.</param>
        public Array(IEnumerable data, AnalyzingContext context)
        {
            int i = 0;

            foreach (var item in data)
            {
                //handle wrapping
                var toSet = item as InstanceWrap;
                if (toSet == null)
                {
                    var instance = item as Instance;
                    if (instance == null)
                    {
                        instance = context.Machine.CreateDirectInstance(item);
                    }
                    toSet = new InstanceWrap(instance);
                }

                //set item
                set_Item(i, toSet as ItemType);
                ++i;
            }
            Length = _data.Count;
        }
示例#27
0
        /// <summary>
        /// Invoke context that is initialized by given initializer.
        /// </summary>
        /// <param name="loader">Loader used for invoking.</param>
        /// <param name="initializer">Initializer of context used for invoking.</param>
        /// <returns>Result of analyzing.</returns>
        private AnalyzingResult contextInvoker(LoaderBase loader, ContextInitializer initializer)
        {
            Settings.FireBeforeInterpretation();

            _createdInstances.Clear();
            var       context          = new AnalyzingContext(this, loader);
            Exception runtimeException = null;

#if !PassExceptions
            try
            {
#endif
            initializer(context);
            runContext(context);
#if !PassExceptions
        }
        catch (Exception ex)
        {
            if (!Settings.CatchExceptions)
            {
                //we have to pass the exception to the caller
                throw;
            }

            runtimeException = ex;
        }
#endif

            var result = context.GetResult(new Dictionary <string, Instance>(_createdInstances));
            result.RuntimeException = runtimeException;

            Settings.FireAfterInterpretation();
            _createdInstances.Clear();

            return(result);
        }
示例#28
0
        /// <summary>
        /// Executes instruction in given context.
        /// </summary>
        /// <param name="context">Context where instruction is executed.</param>
        public override void Execute(AnalyzingContext context)
        {
            var sourceValue = context.GetValue(_sourceVariable);

            context.SetValue(_targetVariable, sourceValue);
        }
示例#29
0
        /// <summary>
        /// Initializes the stack with given context.
        /// </summary>
        /// <param name="context">The context.</param>
        internal static void InitializeStack(AnalyzingContext context)
        {
            var stackInstance = context.Machine.CreateDirectInstance(new VMStack(context));

            context.SetValue(new VariableName(Transcription.StackStorage), stackInstance);
        }
示例#30
0
 /// <summary>
 /// Executes instruction in given context.
 /// </summary>
 /// <param name="context">Context where instruction is executed.</param>
 public override void Execute(AnalyzingContext context)
 {
     context.SetValue(_targetVariable, context.LastReturnValue);
 }
示例#31
0
 /// <summary>
 /// Executes instruction in given context.
 /// </summary>
 /// <param name="context">Context where instruction is executed.</param>
 public override void Execute(AnalyzingContext context)
 {
     //No operation
 }
示例#32
0
 /// <summary>
 /// Create representation of virtual machine stack.
 /// </summary>
 /// <param name="context">Analyzing context available for method call.</param>
 private VMStack(AnalyzingContext context)
 {
     _context = context;
 }
示例#33
0
        /// <summary>
        /// Executes instruction in given context.
        /// </summary>
        /// <param name="context">Context where instruction is executed.</param>
        public override void Execute(AnalyzingContext context)
        {
            var returnValue = context.GetValue(_sourceVariable);

            context.Return(returnValue);
        }
示例#34
0
        /// <summary>
        /// Executes instruction in given context.
        /// </summary>
        /// <param name="context">Context where instruction is executed.</param>
        public override void Execute(AnalyzingContext context)
        {
            var argumentValues = context.GetArguments(_arguments);

            context.FetchCall(_method, argumentValues);
        }