Ejemplo n.º 1
0
 protected override bool Walk(WriteStatement node)
 {
     if (node.Value is MethodCallExpression)
     {
         var mce = node.Value as MethodCallExpression;
         if (mce.Method.Name == "Create" && mce.Type == typeof(Callable))
         {
             var cbe = mce.Arguments[0] as CodeBlockExpression;
             if (cbe != null && cbe.Block.Inlined)
             {
                 node.Value = null;
             }
         }
     }
     if (node.Value is NewExpression)
     {
         var mce = node.Value as NewExpression;
         if (mce.Type.Name.Contains("TypedClosure"))
         {
             var cbe = mce.Arguments[0] as CodeBlockExpression;
             if (cbe != null && cbe.Block.Inlined)
             {
                 node.Value = null;
             }
         }
     }
     return(base.Walk(node));
 }
Ejemplo n.º 2
0
                protected override void PostWalk(WriteStatement node)
                {
                    base.PostWalk(node);

                    var v   = node.Variable;
                    var val = node.Value;

                    if (v.Type == typeof(object))
                    {
                        if (val.Type != typeof(object) && val.Type != typeof(SymbolId) && !v.Uninitialized)
                        {
                            v.Type = val.Type;
                        }
                    }
                    else if (v.Type != val.Type)
                    {
                        v.Type = typeof(object);
                    }
                    else
                    {
                        writecounts[node.Variable]--;
                    }

                    if (writecounts[node.Variable] > 1)
                    {
                        v.Type = typeof(object);
                    }
                }
Ejemplo n.º 3
0
                protected override bool Walk(WriteStatement node)
                {
                    var val = node.Value;
                    var var = node.Variable;

                    ProcessAssignment(val, var, true);

                    return(base.Walk(node));
                }
Ejemplo n.º 4
0
                protected override void PostWalk(WriteStatement node)
                {
                    base.PostWalk(node);

                    var val = node.Value;
                    var var = node.Variable;

                    val        = ProcessAssignment(val, var);
                    node.Value = val;
                }
Ejemplo n.º 5
0
        private IStatement WriteStatement()
        {
            EatToken(TokenType.WRITE);
            EatToken(TokenType.LPARENT);
            WriteStatement writeStatement = new WriteStatement(Expression());

            EatToken(TokenType.RPARENT);

            return(writeStatement);
        }
Ejemplo n.º 6
0
        public object Visit_WriteStatement(WriteStatement writeStatement)
        {
            TreeViewItem item = new TreeViewItem();

            item.IsExpanded = true;

            item.Header = "Write";
            item.Items.Add(writeStatement.Expression.Visit(this));

            return(item);
        }
Ejemplo n.º 7
0
        private string EmitWriteStatement(WriteStatement writeStatement)
        {
            string r = "\n        //Begin write statement...\n";

            //string r = "";

            //throw new Compiler.Exceptions.NotImplementedException(
            //        writeStatement.LineNumber, "WRITE statement");

            //Base this on EmitDisplayVerb rather than on the style that
            //EmitReadStatement uses. EmitDisplayVerb and this should probably
            //both call a common lower level method that works out what's to
            //be dispayed or written to a file, and have a parameter that states
            //whether or not it's being written to a file (and which file?) or
            //if it's going to the screen.

            r += EmitOutputBase(null, writeStatement);
            r += "        //End of write statement\n";
            return(r);
        }
Ejemplo n.º 8
0
                protected override void PostWalk(WriteStatement node)
                {
                    base.PostWalk(node);

                    var v   = node.Variable;
                    var val = node.Value;

                    if (v.Type == typeof(object))
                    {
                        if (val.Type != typeof(object) && val.Type != typeof(SymbolId) && !v.Uninitialized)
                        {
                            v.Type = val.Type;
                        }
                    }
                    else if (v.Type != val.Type)
                    {
                        v.Type = typeof(object);
                    }
                    else if (v.Type == typeof(Callable))
                    {
                        var uv = Unwrap(val);
                        if (!uv.Type.IsAssignableFrom(v.Type))
                        {
                            v.Type     = typeof(object);
                            node.Value = Ast.ConvertHelper(Unwrap(val), typeof(object));
                        }
                        else
                        {
                            writecounts[node.Variable]--;
                        }
                    }
                    else
                    {
                        writecounts[node.Variable]--;
                    }

                    if (writecounts[node.Variable] > 1)
                    {
                        v.Type = typeof(object);
                    }
                }
Ejemplo n.º 9
0
 protected override bool Walk(WriteStatement node)
 {
     if (!Generator.assigns.ContainsKey(node.Variable.Name))
     {
         if (node.Value is BoundExpression)
         {
             var be = node.Value as BoundExpression;
             if (be.Variable.Block != node.Variable.Block || Generator.assigns.ContainsKey(be.Variable.Name) || be.Type != node.Variable.Type)
             {
                 return(base.Walk(node));
             }
         }
         if (node.Variable.AssumedValue == null)
         {
             if (node.Value.Type == node.Variable.Type)
             {
                 node.Variable.AssumedValue = node.Value;
             }
         }
     }
     return(base.Walk(node));
 }
Ejemplo n.º 10
0
            private static IToken BuildCodeElementFromType(CodeElementType type, Token lastTokenBeforeError, string informationText)
            {
                CodeElement codeElement = null;

                switch (type)
                {
                case CodeElementType.ProgramIdentification:
                    codeElement = new ProgramIdentification();
                    break;

                case CodeElementType.ProgramEnd:
                    codeElement = new ProgramEnd();
                    break;

                case CodeElementType.ClassIdentification:
                    codeElement = new ClassIdentification();
                    break;

                case CodeElementType.ClassEnd:
                    codeElement = new ClassEnd();
                    break;

                case CodeElementType.FactoryIdentification:
                    codeElement = new FactoryIdentification();
                    break;

                case CodeElementType.FactoryEnd:
                    codeElement = new FactoryEnd();
                    break;

                case CodeElementType.ObjectIdentification:
                    codeElement = new ObjectIdentification();
                    break;

                case CodeElementType.ObjectEnd:
                    codeElement = new ObjectEnd();
                    break;

                case CodeElementType.MethodIdentification:
                    codeElement = new MethodIdentification();
                    break;

                case CodeElementType.MethodEnd:
                    codeElement = new MethodEnd();
                    break;

                case CodeElementType.EnvironmentDivisionHeader:
                    codeElement = new EnvironmentDivisionHeader();
                    break;

                case CodeElementType.DataDivisionHeader:
                    codeElement = new DataDivisionHeader();
                    break;

                case CodeElementType.ProcedureDivisionHeader:
                    codeElement = new ProcedureDivisionHeader();
                    break;

                case CodeElementType.DeclarativesHeader:
                    codeElement = new DeclarativesHeader();
                    break;

                case CodeElementType.DeclarativesEnd:
                    codeElement = new DeclarativesEnd();
                    break;

                case CodeElementType.SectionHeader:
                    codeElement = new SectionHeader();
                    break;

                case CodeElementType.ConfigurationSectionHeader:
                    codeElement = new ConfigurationSectionHeader();
                    break;

                case CodeElementType.InputOutputSectionHeader:
                    codeElement = new InputOutputSectionHeader();
                    break;

                case CodeElementType.FileSectionHeader:
                    codeElement = new FileSectionHeader();
                    break;

                case CodeElementType.WorkingStorageSectionHeader:
                    codeElement = new WorkingStorageSectionHeader();
                    break;

                case CodeElementType.LocalStorageSectionHeader:
                    codeElement = new LocalStorageSectionHeader();
                    break;

                case CodeElementType.LinkageSectionHeader:
                    codeElement = new LinkageSectionHeader();
                    break;

                case CodeElementType.ParagraphHeader:
                    codeElement = new ParagraphHeader();
                    break;

                case CodeElementType.FileControlParagraphHeader:
                    codeElement = new FileControlParagraphHeader();
                    break;

                case CodeElementType.IOControlParagraphHeader:
                    codeElement = new IOControlParagraphHeader();
                    break;

                case CodeElementType.SentenceEnd:
                    codeElement = new SentenceEnd();
                    break;

                case CodeElementType.FileDescriptionEntry:
                    codeElement = new FileDescriptionEntry();
                    break;

                case CodeElementType.DataDescriptionEntry:
                    codeElement = new DataDescriptionEntry();
                    break;

                case CodeElementType.DataRedefinesEntry:
                    codeElement = new DataRedefinesEntry();
                    break;

                case CodeElementType.DataRenamesEntry:
                    codeElement = new DataRenamesEntry();
                    break;

                case CodeElementType.DataConditionEntry:
                    codeElement = new DataConditionEntry();
                    break;

                case CodeElementType.FileControlEntry:
                    codeElement = new FileControlEntry();
                    break;

                case CodeElementType.IOControlEntry:
                    codeElement = new RerunIOControlEntry();
                    break;

                case CodeElementType.SourceComputerParagraph:
                    codeElement = new SourceComputerParagraph();
                    break;

                case CodeElementType.ObjectComputerParagraph:
                    codeElement = new ObjectComputerParagraph();
                    break;

                case CodeElementType.SpecialNamesParagraph:
                    codeElement = new SpecialNamesParagraph();
                    break;

                case CodeElementType.RepositoryParagraph:
                    codeElement = new RepositoryParagraph();
                    break;

                case CodeElementType.AcceptStatement:
                    codeElement = new AcceptFromInputDeviceStatement();
                    break;

                case CodeElementType.AddStatement:
                    codeElement = new AddSimpleStatement();
                    break;

                case CodeElementType.AlterStatement:
                    codeElement = new AlterStatement();
                    break;

                case CodeElementType.CallStatement:
                    codeElement = new CallStatement();
                    break;

                case CodeElementType.CancelStatement:
                    codeElement = new CancelStatement();
                    break;

                case CodeElementType.CloseStatement:
                    codeElement = new CloseStatement();
                    break;

                case CodeElementType.ComputeStatement:
                    codeElement = new ComputeStatement();
                    break;

                case CodeElementType.ContinueStatement:
                    codeElement = new ContinueStatement();
                    break;

                case CodeElementType.DeleteStatement:
                    codeElement = new DeleteStatement();
                    break;

                case CodeElementType.DisplayStatement:
                    codeElement = new DisplayStatement();
                    break;

                case CodeElementType.DivideStatement:
                    codeElement = new DivideSimpleStatement();
                    break;

                case CodeElementType.EntryStatement:
                    codeElement = new EntryStatement();
                    break;

                case CodeElementType.EvaluateStatement:
                    codeElement = new EvaluateStatement();
                    break;

                case CodeElementType.ExecStatement:
                    codeElement = new ExecStatement();
                    break;

                case CodeElementType.ExitMethodStatement:
                    codeElement = new ExitMethodStatement();
                    break;

                case CodeElementType.ExitProgramStatement:
                    codeElement = new ExitProgramStatement();
                    break;

                case CodeElementType.ExitStatement:
                    codeElement = new ExitStatement();
                    break;

                case CodeElementType.GobackStatement:
                    codeElement = new GobackStatement();
                    break;

                case CodeElementType.GotoStatement:
                    codeElement = new GotoSimpleStatement();
                    break;

                case CodeElementType.IfStatement:
                    codeElement = new IfStatement();
                    break;

                case CodeElementType.InitializeStatement:
                    codeElement = new InitializeStatement();
                    break;

                case CodeElementType.InspectStatement:
                    codeElement = new InspectTallyingStatement();
                    break;

                case CodeElementType.InvokeStatement:
                    codeElement = new InvokeStatement();
                    break;

                case CodeElementType.MergeStatement:
                    codeElement = new MergeStatement();
                    break;

                case CodeElementType.MoveStatement:
                    codeElement = new MoveSimpleStatement(null, null, null);
                    break;

                case CodeElementType.MultiplyStatement:
                    codeElement = new MultiplySimpleStatement();
                    break;

                case CodeElementType.NextSentenceStatement:
                    codeElement = new NextSentenceStatement();
                    break;

                case CodeElementType.OpenStatement:
                    codeElement = new OpenStatement();
                    break;

                case CodeElementType.PerformProcedureStatement:
                    codeElement = new PerformProcedureStatement();
                    break;

                case CodeElementType.PerformStatement:
                    codeElement = new PerformStatement();
                    break;

                case CodeElementType.ReadStatement:
                    codeElement = new ReadStatement();
                    break;

                case CodeElementType.ReleaseStatement:
                    codeElement = new ReleaseStatement();
                    break;

                case CodeElementType.ReturnStatement:
                    codeElement = new ReturnStatement();
                    break;

                case CodeElementType.RewriteStatement:
                    codeElement = new RewriteStatement();
                    break;

                case CodeElementType.SearchStatement:
                    codeElement = new SearchSerialStatement();
                    break;

                case CodeElementType.SetStatement:
                    codeElement = new SetStatementForAssignment();
                    break;

                case CodeElementType.SortStatement:
                    codeElement = new SortStatement();
                    break;

                case CodeElementType.StartStatement:
                    codeElement = new StartStatement();
                    break;

                case CodeElementType.StopStatement:
                    codeElement = new StopStatement();
                    break;

                case CodeElementType.StringStatement:
                    codeElement = new StringStatement();
                    break;

                case CodeElementType.SubtractStatement:
                    codeElement = new SubtractSimpleStatement();
                    break;

                case CodeElementType.UnstringStatement:
                    codeElement = new UnstringStatement();
                    break;

                case CodeElementType.UseStatement:
                    codeElement = new UseAfterIOExceptionStatement();
                    break;

                case CodeElementType.WriteStatement:
                    codeElement = new WriteStatement();
                    break;

                case CodeElementType.XmlGenerateStatement:
                    codeElement = new XmlGenerateStatement();
                    break;

                case CodeElementType.XmlParseStatement:
                    codeElement = new XmlParseStatement();
                    break;

                case CodeElementType.AtEndCondition:
                    codeElement = new AtEndCondition();
                    break;

                case CodeElementType.NotAtEndCondition:
                    codeElement = new NotAtEndCondition();
                    break;

                case CodeElementType.AtEndOfPageCondition:
                    codeElement = new AtEndOfPageCondition();
                    break;

                case CodeElementType.NotAtEndOfPageCondition:
                    codeElement = new NotAtEndOfPageCondition();
                    break;

                case CodeElementType.OnExceptionCondition:
                    codeElement = new OnExceptionCondition();
                    break;

                case CodeElementType.NotOnExceptionCondition:
                    codeElement = new NotOnExceptionCondition();
                    break;

                case CodeElementType.OnOverflowCondition:
                    codeElement = new OnOverflowCondition();
                    break;

                case CodeElementType.NotOnOverflowCondition:
                    codeElement = new NotOnOverflowCondition();
                    break;

                case CodeElementType.InvalidKeyCondition:
                    codeElement = new InvalidKeyCondition();
                    break;

                case CodeElementType.NotInvalidKeyCondition:
                    codeElement = new NotInvalidKeyCondition();
                    break;

                case CodeElementType.OnSizeErrorCondition:
                    codeElement = new OnSizeErrorCondition();
                    break;

                case CodeElementType.NotOnSizeErrorCondition:
                    codeElement = new NotOnSizeErrorCondition();
                    break;

                case CodeElementType.ElseCondition:
                    codeElement = new ElseCondition();
                    break;

                case CodeElementType.WhenCondition:
                    codeElement = new WhenCondition();
                    break;

                case CodeElementType.WhenOtherCondition:
                    codeElement = new WhenOtherCondition();
                    break;

                case CodeElementType.WhenSearchCondition:
                    codeElement = new WhenSearchCondition();
                    break;

                case CodeElementType.AddStatementEnd:
                    codeElement = new AddStatementEnd();
                    break;

                case CodeElementType.CallStatementEnd:
                    codeElement = new CallStatementEnd();
                    break;

                case CodeElementType.ComputeStatementEnd:
                    codeElement = new ComputeStatementEnd();
                    break;

                case CodeElementType.DeleteStatementEnd:
                    codeElement = new DeleteStatementEnd();
                    break;

                case CodeElementType.DivideStatementEnd:
                    codeElement = new DivideStatementEnd();
                    break;

                case CodeElementType.EvaluateStatementEnd:
                    codeElement = new EvaluateStatementEnd();
                    break;

                case CodeElementType.IfStatementEnd:
                    codeElement = new IfStatementEnd();
                    break;

                case CodeElementType.InvokeStatementEnd:
                    codeElement = new InvokeStatementEnd();
                    break;

                case CodeElementType.MultiplyStatementEnd:
                    codeElement = new MultiplyStatementEnd();
                    break;

                case CodeElementType.PerformStatementEnd:
                    codeElement = new PerformStatementEnd();
                    break;

                case CodeElementType.ReadStatementEnd:
                    codeElement = new ReadStatementEnd();
                    break;

                case CodeElementType.ReturnStatementEnd:
                    codeElement = new ReturnStatementEnd();
                    break;

                case CodeElementType.RewriteStatementEnd:
                    codeElement = new RewriteStatementEnd();
                    break;

                case CodeElementType.SearchStatementEnd:
                    codeElement = new SearchStatementEnd();
                    break;

                case CodeElementType.StartStatementEnd:
                    codeElement = new StartStatementEnd();
                    break;

                case CodeElementType.StringStatementEnd:
                    codeElement = new StringStatementEnd();
                    break;

                case CodeElementType.SubtractStatementEnd:
                    codeElement = new SubtractStatementEnd();
                    break;

                case CodeElementType.UnstringStatementEnd:
                    codeElement = new UnstringStatementEnd();
                    break;

                case CodeElementType.WriteStatementEnd:
                    codeElement = new WriteStatementEnd();
                    break;

                case CodeElementType.XmlStatementEnd:
                    codeElement = new XmlStatementEnd();
                    break;

                case CodeElementType.LibraryCopy:
                    codeElement = new LibraryCopyCodeElement();
                    break;

                case CodeElementType.FunctionDeclarationHeader:
                    codeElement = new FunctionDeclarationHeader(null, AccessModifier.Private, FunctionType.Undefined);
                    break;

                case CodeElementType.FunctionDeclarationEnd:
                    codeElement = new FunctionDeclarationEnd();
                    break;

                default:
                    throw new NotImplementedException();
                }
                if (lastTokenBeforeError != null)
                {
                    var missingToken = new MissingToken(TokenType.InvalidToken, informationText, lastTokenBeforeError.TokensLine, lastTokenBeforeError.StopIndex);
                    codeElement.ConsumedTokens.Add(missingToken);
                }
                return(codeElement);
            }
Ejemplo n.º 11
0
 protected override bool Walk(WriteStatement node)
 {
     writecounts[node.Variable] = writecounts.ContainsKey(node.Variable) ? writecounts[node.Variable] + 1 : 1;
     return(base.Walk(node));
 }
Ejemplo n.º 12
0
 protected internal virtual void PostWalk(WriteStatement node)
 {
 }
Ejemplo n.º 13
0
        private string EmitOutputBase(DisplayVerb display, WriteStatement writeStatement)
        {
            string          r         = "";
            string          className = "__CobolProgram";
            DataDescription dde       = null;

            //Build the format string and param types list...
            string fmt     = "";
            int    objects = 0;

            ArrayList sources;

            if (display != null)
            {
                sources = display.Sources;
            }
            else
            {
                dde = GetDDEByName(writeStatement.RecordName.Name);
                if (dde == null)
                {
                    Console.WriteLine("dde is NULL");
                }

                r += "        " + ILAddress(1) + "ldarg.0\n";
                r += "        " + ILAddress(5);
                r += "ldfld class [mscorlib]System.IO.StreamWriter " + className + "::_writer_" + ILIdentifier(dde.FSDE.Name.Name) + "\n";

                sources = new ArrayList();
                if (writeStatement.RecordName != null)
                {
                    sources.Add(writeStatement.RecordName);
                }
                //TODO: What should be done when there are no FROM identifiers?
            }

            for (int i = 0; i < sources.Count; i++)
            {
                Source source = sources[i] as Source;
                if (IsGroup(source))
                {
                    Identifier             id   = source as Identifier;
                    List <DataDescription> ddes = ListElements(id.Definition);
                    foreach (DataDescription dd in ddes)
                    {
                        fmt += "{" + objects + ",-" + dd.Size + "}";
                        objects++;
                    }
                }
                else
                {
                    //TODO:
                    //If the source specifies a substring, then that size should be used in the
                    //brackets rather than the definition's size. Simply using the definition's
                    //size breaks the 99 bottles output because the buffer variable is large
                    //and we only want one character from it.
                    //See testdisp.cbl and its output.

                    if (source.GetType() == typeof(Identifier))
                    {
                        Identifier id = source as Identifier;
                        if (id.UsesSubstring)
                        {
                            Console.WriteLine("UsesSubstring = true : " + id.Name);
                            fmt += "{" + objects + "}";
                        }
                        else
                        {
                            //Console.WriteLine("UsesSubstring = false : "+id.Name);
                            fmt += "{" + objects + ",-" + id.Definition.Size + "}";
                        }
                    }
                    else
                    {
                        fmt += "{" + objects + "}";
                    }
                    objects++;
                }
            }

            //Load the format string...
            r += "        " + ILAddress(5);
            r += "ldstr \"" + fmt + "\"\n";

            //Create an array
            r += "        " + ILAddress(5);
            r += "ldc.i4 " + objects + "\n";
            r += "        " + ILAddress(5);
            r += "newarr [mscorlib]System.Object\n";

            //Load the values...
            int obj = 0;

            foreach (Source source in sources)
            {
                if (IsGroup(source))
                {
                    Identifier id = source as Identifier;
                    //Plan:
                    // 1. Load a format string based on all of the group element sizes (and types?)
                    // 2. Load each element
                    // 3. String.Format
                    // 4. Build an object array of the elements
                    // 5. Use the format string and array in WriteLine
                    List <DataDescription> ddes = ListElements(id.Definition);

                    foreach (DataDescription dd in ddes)
                    {
                        Identifier tmp = new Identifier();
                        tmp.Name       = dd.Name;
                        tmp.Definition = dd;
                        r += "        " + ILAddress(1) + "dup\n";
                        r += "        " + ILAddress(5) + "ldc.i4 " + obj + "\n";
                        r += EmitLoadSource(tmp as Source, false, true);
                        r += "        " + ILAddress(1) + "stelem.ref\n";
                        obj++;
                    }
                }
                else
                {
                    r += "        " + ILAddress(1) + "dup\n";
                    r += "        " + ILAddress(5) + "ldc.i4 " + obj + "\n";
                    r += EmitLoadSource(source, false, true);
                    r += "        " + ILAddress(1) + "stelem.ref\n";
                    obj++;
                }
            }

            if (display != null)
            {
                //Call Write or WriteLine...
                r += "        " + ILAddress(5);
                string parms = "string, object[]";
                if (display.NoAdvancing)
                {
                    r += "call void class [mscorlib]System.Console::Write(" + parms + ")";
                }
                else
                {
                    r += "call void class [mscorlib]System.Console::WriteLine(" + parms + ")";
                }
                r += "\n";
            }
            else
            {
                //Write...
                r += "        " + ILAddress(5);
                r += "callvirt instance void class [mscorlib]System.IO.StreamWriter::WriteLine(string,object[])\n";

                //Flush...
                r += "        " + ILAddress(1) + "ldarg.0\n";
                r += "        " + ILAddress(5);
                r += "ldfld class [mscorlib]System.IO.StreamWriter " + className + "::_writer_" + ILIdentifier(dde.FSDE.Name.Name) + "\n";
                r += "        " + ILAddress(5);
                r += "callvirt instance void class [mscorlib]System.IO.StreamWriter::Flush()\n";
            }
            return(r);
        }
Ejemplo n.º 14
0
 // WriteStatement
 protected internal virtual bool Walk(WriteStatement node) { return true; }
Ejemplo n.º 15
0
        public object Visit_WriteStatement(WriteStatement writeStatement)
        {
            WriteDelegate(writeStatement.Expression.Visit(this));

            return(null);
        }
Ejemplo n.º 16
0
 protected internal virtual void PostWalk(WriteStatement node) { }
Ejemplo n.º 17
0
 // WriteStatement
 protected internal virtual bool Walk(WriteStatement node)
 {
     return(true);
 }