Exemplo n.º 1
0
        LabelStatement CreateLabel(Node sourceNode)
        {
            InternalLabel label = CodeBuilder.CreateLabel(sourceNode, "$state$" + _labels.Count);

            _labels.Add(label.LabelStatement);
            return(label.LabelStatement);
        }
Exemplo n.º 2
0
            // returns a proxy for a label if branch must be hijacked to run finally
            // otherwise returns same label back
            public InternalLabel ProxyLabelIfNeeded(InternalLabel label)
            {
                // no need to proxy a label in the current frame or when we are at the root
                if (IsRoot() || (_labelsOpt != null && _labelsOpt.Contains(label)))
                {
                    return(label);
                }

                var proxyLabels   = this.proxyLabels;
                var proxiedLabels = this.proxiedLabels;

                if (proxyLabels == null)
                {
                    this.proxyLabels   = proxyLabels = new Dictionary <InternalLabel, InternalLabel>();
                    this.proxiedLabels = proxiedLabels = new List <InternalLabel>();
                }

                InternalLabel proxy;

                if (!proxyLabels.TryGetValue(label, out proxy))
                {
                    proxy = _builder.CreateLabel(label.LabelStatement, "proxy" + label.Name, _tryDepth);
                    proxyLabels.Add(label, proxy);
                    proxiedLabels.Add(label);
                }

                return(proxy);
            }
Exemplo n.º 3
0
            public InternalLabel ProxyReturnIfNeeded(
                Method containingMethod,
                Node valueOpt,
                out InternalLocal retVal)
            {
                retVal = null;

                // no need to proxy returns  at the root
                if (IsRoot())
                {
                    return(null);
                }

                var returnProxy = returnProxyLabel;

                if (returnProxy == null)
                {
                    returnProxyLabel = returnProxy = _builder.CreateLabel(valueOpt ?? containingMethod, "returnProxy", _tryDepth);
                }

                if (valueOpt != null)
                {
                    retVal = returnValue;
                    if (retVal == null)
                    {
                        Debug.Assert(_tryStatementOpt != null);
                        returnValue = retVal = _builder.DeclareTempLocal(
                            containingMethod,
                            ((ITypedEntity)valueOpt.Entity).Type);
                    }
                }

                return(returnProxy);
            }
Exemplo n.º 4
0
        private Block PendBranches(
            AwaitFinallyFrame frame,
            InternalLocal pendingBranchVar,
            InternalLabel finallyLabel)
        {
            var bodyStatements = new Block();

            // handle proxy labels if have any
            var proxiedLabels = frame.proxiedLabels;
            var proxyLabels   = frame.proxyLabels;

            // skip 0 - it means we took no explicit branches
            int i = 1;

            if (proxiedLabels != null)
            {
                for (int cnt = proxiedLabels.Count; i <= cnt; i++)
                {
                    var proxied = proxiedLabels[i - 1];
                    var proxy   = proxyLabels[proxied];

                    PendBranch(bodyStatements, proxy, i, pendingBranchVar, finallyLabel);
                }
            }

            var returnProxy = frame.returnProxyLabel;

            if (returnProxy != null)
            {
                PendBranch(bodyStatements, returnProxy, i, pendingBranchVar, finallyLabel);
            }

            return(bodyStatements);
        }
Exemplo n.º 5
0
        private void RunOnce()
        {
            //find internallabel
            if (NavUtilLib.GlobalVariables.Settings.enableDebugging)
            {
                Debug.Log("NavUtil: iM look");
            }
            var iM = internalProp.internalModules.First(m => m.GetType() == typeof(InternalLabel));

            if (NavUtilLib.GlobalVariables.Settings.enableDebugging)
            {
                Debug.Log("NavUtil: iM found, casting...");
            }

            rwyLabel = (InternalLabel)iM;

            if (NavUtilLib.GlobalVariables.Settings.enableDebugging)
            {
                Debug.Log("NavUtil: iM Cast!");
            }

            rwyLabel.SetText(NavUtilLib.GlobalVariables.FlightData.rwyList[NavUtilLib.GlobalVariables.FlightData.rwyIdx].shortID);

            NavUtilLib.GlobalVariables.Audio.initializeAudio();

            ranOnce = true;
        }
Exemplo n.º 6
0
        LabelStatement CreateLabel(Node sourceNode)
        {
            InternalLabel label = CodeBuilder.CreateLabel(sourceNode, "$state$" + _labels.Count);

            _labels.Add(label.LabelStatement);
            _tryStatementInfoForLabels.Add(_tryStatementStack.Count > 0 ? _tryStatementStack.Peek() : null);
            return(label.LabelStatement);
        }
Exemplo n.º 7
0
        private Block SwitchBlock(Statement body, int ordinal, InternalLabel endpoint)
        {
            var result = new Block();

            result.Add(_F.CreateLabel(result, CompilerContext.Current.GetUniqueName("L" + ordinal), _tryDepth).LabelStatement);
            result.Add(body);
            result.Add(_F.CreateGoto(endpoint, _tryDepth));
            return(result);
        }
Exemplo n.º 8
0
        LabelStatement CreateLabel(Node sourceNode)
        {
            InternalLabel label = CodeBuilder.CreateLabelStatement(sourceNode,
                                                                   "___state" + _labels.Count);

            _labels.Add(label.LabelStatement);
            _moveNext.AddLabel(label);
            return(label.LabelStatement);
        }
Exemplo n.º 9
0
        private Block CreateSwitch(List <Statement> handlers, InternalLabel endLabel, InternalLocal switchVar)
        {
            var blocks       = handlers.Zip(Enumerable.Range(1, handlers.Count), (s, i1) => SwitchBlock(s, i1, endLabel)).ToArray();
            var resultSwitch = _F.CreateSwitch(_F.CreateLocalReference(switchVar),
                                               blocks.Select(b => b.FirstStatement).Cast <LabelStatement>());
            var result = new Block(resultSwitch);

            result.Statements.AddRange(blocks);
            result.Statements.Add(endLabel.LabelStatement);
            return(result);
        }
Exemplo n.º 10
0
 void ResolveLabelReferences()
 {
     foreach (ReferenceExpression reference in _state.LabelReferences)
     {
         InternalLabel label = _state.ResolveLabel(reference.Name);
         if (null == label)
         {
             Error(reference, CompilerErrorFactory.NoSuchLabel(reference, reference.Name));
         }
         else
         {
             reference.Entity = label;
         }
     }
 }
Exemplo n.º 11
0
        private void RunOnce()
        {
            //find internallabel
            Log.detail("NavUtil: iM look");
            InternalModule iM = internalProp.internalModules.First(m => m.GetType() == typeof(InternalLabel));

            Log.detail("NavUtil: iM found, casting...");

            rwyLabel = (InternalLabel)iM;

            Log.detail("NavUtil: iM Cast!");

            rwyLabel.SetText(NavUtilLib.GlobalVariables.FlightData.currentBodyRunways[NavUtilLib.GlobalVariables.FlightData.rwyIdx].shortID);

            ranOnce = true;
        }
Exemplo n.º 12
0
        private void PendBranch(
            Block bodyStatements,
            InternalLabel proxy,
            int i,
            InternalLocal pendingBranchVar,
            InternalLabel finallyLabel)
        {
            // branch lands here
            bodyStatements.Add(proxy.LabelStatement);

            // pend the branch
            bodyStatements.Add(_F.CreateAssignment(
                                   _F.CreateLocalReference(pendingBranchVar),
                                   _F.CreateIntegerLiteral(i)));

            // skip other proxies
            bodyStatements.Add(_F.CreateGoto(finallyLabel, _tryDepth));
        }
Exemplo n.º 13
0
 public void AddLabel(InternalLabel label)
 {
     _labels.Add(label.Name, label);
 }
Exemplo n.º 14
0
 public void AddLabel(InternalLabel label)
 {
     _labels.Add(label.Name, label);
 }
Exemplo n.º 15
0
        /// <summary>
        /// Generate the body for <c>MoveNext()</c>.
        /// </summary>
        protected override void CreateMoveNext()
        {
            Method asyncMethod = _method.Method;

            BooMethodBuilder methodBuilder = _stateMachineClass.AddVirtualMethod("MoveNext", TypeSystemServices.VoidType);

            methodBuilder.Method.LexicalInfo = asyncMethod.LexicalInfo;
            _moveNext = methodBuilder.Entity;

            TransformLocalsIntoFields(asyncMethod);
            TransformParametersIntoFieldsInitializedByConstructor(_method.Method);

            _exprReturnLabel = CodeBuilder.CreateLabel(methodBuilder.Method, "exprReturn", 0);
            _exitLabel       = CodeBuilder.CreateLabel(methodBuilder.Method, "exitLabel", 0);
            _isGenericTask   = _method.ReturnType.ConstructedInfo != null;
            _exprRetValue    = _isGenericTask
                ? CodeBuilder.DeclareTempLocal(_moveNext.Method, _methodToStateMachineMapper.MapType(_asyncMethodBuilderMemberCollection.ResultType))
                : null;

            _cachedState = CodeBuilder.DeclareLocal(methodBuilder.Method, UniqueName("state"),
                                                    TypeSystemServices.IntType);

            _seenAwait = false;
            var rewrittenBody = (Block)Visit(_method.Method.Body);

            if (!_seenAwait)
            {
                Context.Warnings.Add(CompilerWarningFactory.AsyncNoAwait(_method.Method));
            }

            var bodyBuilder = methodBuilder.Body;

            bodyBuilder.Add(CodeBuilder.CreateAssignment(
                                CodeBuilder.CreateLocalReference(_cachedState),
                                CodeBuilder.CreateMemberReference(_state)));

            CheckForTryExcept();

            Block bodyBlock;

            if (_labels.Count > 0)
            {
                var dispatch =
                    CodeBuilder.CreateSwitch(
                        this.LexicalInfo,
                        CodeBuilder.CreateLocalReference(_cachedState),
                        _labels);
                CheckTryJumps((MethodInvocationExpression)((ExpressionStatement)dispatch).Expression);
                bodyBlock = new Block(dispatch, rewrittenBody);
            }
            else
            {
                bodyBlock = rewrittenBody;
            }
            InternalLocal exceptionLocal;

            bodyBuilder.Add(CodeBuilder.CreateTryExcept(
                                this.LexicalInfo,
                                bodyBlock,
                                new ExceptionHandler
            {
                Declaration = CodeBuilder.CreateDeclaration(
                    methodBuilder.Method,
                    UniqueName("exception"),
                    TypeSystemServices.ExceptionType,
                    out exceptionLocal),
                Block = new Block(
                    CodeBuilder.CreateFieldAssignment(
                        this.LexicalInfo,
                        _state,
                        CodeBuilder.CreateIntegerLiteral(StateMachineStates.FinishedStateMachine)),
                    new ExpressionStatement(
                        CodeBuilder.CreateMethodInvocation(
                            CodeBuilder.CreateMemberReference(
                                CodeBuilder.CreateSelfReference(_stateMachineClass.Entity),
                                (IField)_asyncMethodBuilderField.Entity),
                            _asyncMethodBuilderMemberCollection.SetException,
                            CodeBuilder.CreateLocalReference(exceptionLocal))),
                    GenerateReturn())
            }));

            // ReturnLabel (for the rewritten return expressions in the user's method body)
            bodyBuilder.Add(_exprReturnLabel.LabelStatement);

            // this.state = finishedState
            bodyBuilder.Add(CodeBuilder.CreateFieldAssignment(
                                this.LexicalInfo,
                                _state,
                                CodeBuilder.CreateIntegerLiteral(StateMachineStates.FinishedStateMachine)));

            // builder.SetResult([RetVal])
            var setResultInvocation = CodeBuilder.CreateMethodInvocation(
                CodeBuilder.CreateMemberReference(
                    CodeBuilder.CreateSelfReference(_stateMachineClass.Entity),
                    (IField)_asyncMethodBuilderField.Entity),
                _asyncMethodBuilderMemberCollection.SetResult);

            if (_isGenericTask)
            {
                setResultInvocation.Arguments.Add(CodeBuilder.CreateLocalReference(_exprRetValue));
            }

            bodyBuilder.Add(new ExpressionStatement(setResultInvocation));

            // this code is hidden behind a hidden sequence point.
            bodyBuilder.Add(_exitLabel.LabelStatement);
            bodyBuilder.Add(new ReturnStatement());
        }
Exemplo n.º 16
0
        private void RunOnce()
        {
            //find internallabel
            if (NavUtilLib.GlobalVariables.Settings.enableDebugging) Debug.Log("NavUtil: iM look");
            var iM = internalProp.internalModules.First(m => m.GetType() == typeof(InternalLabel));

            if (NavUtilLib.GlobalVariables.Settings.enableDebugging) Debug.Log("NavUtil: iM found, casting...");

            rwyLabel = (InternalLabel)iM;

            if (NavUtilLib.GlobalVariables.Settings.enableDebugging) Debug.Log("NavUtil: iM Cast!");

            rwyLabel.SetText(NavUtilLib.GlobalVariables.FlightData.rwyList[NavUtilLib.GlobalVariables.FlightData.rwyIdx].shortID);

            NavUtilLib.GlobalVariables.Audio.initializeAudio();

            ranOnce = true;
        }