Пример #1
0
        public void ProcessStatementTryCatch(DMASTProcStatementTryCatch tryCatch)
        {
            string catchLabel = _proc.NewLabelName();
            string endLabel   = _proc.NewLabelName();

            _proc.StartScope();
            ProcessBlockInner(tryCatch.TryBody);
            _proc.EndScope();
            _proc.Jump(endLabel);

            if (tryCatch.CatchParameter != null)
            {
                //TODO set the value to what is thrown in try
                var param = tryCatch.CatchParameter as DMASTProcStatementVarDeclaration;
                if (!_proc.TryAddLocalVariable(param.Name, param.Type))
                {
                    DMCompiler.Error(new CompilerError(param.Location, $"Duplicate var {param.Name}"));
                }
            }

            //TODO make catching actually work
            _proc.AddLabel(catchLabel);
            if (tryCatch.CatchBody != null)
            {
                _proc.StartScope();
                ProcessBlockInner(tryCatch.CatchBody);
                _proc.EndScope();
            }
            _proc.AddLabel(endLabel);
        }
Пример #2
0
 public void VisitProcStatementTryCatch(DMASTProcStatementTryCatch tryCatch)
 {
     tryCatch.TryBody.Visit(this);
     tryCatch.CatchBody?.Visit(this);
 }