~sandy-dunlop/wildcatcobol/dev

« back to all changes in this revision

Viewing changes to src/Wildcat.Cobol.Compiler/ILGenerator/IO.cs

  • Committer: Sandy Dunlop
  • Date: 2007-09-05 20:33:27 UTC
  • Revision ID: sandyd@marvin.local-20070905203327-5mrm7ulgj6ewefiq
Implemented some more of the code for writing sequential data files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
194
194
        
195
195
        private string EmitWriteStatement(WriteStatement writeStatement)
196
196
        {
197
 
                string r = "";
 
197
                //string r = "";
198
198
            
199
 
            throw new Compiler.Exceptions.NotImplementedException(
200
 
                    writeStatement.LineNumber, "WRITE statement");
 
199
            //throw new Compiler.Exceptions.NotImplementedException(
 
200
            //        writeStatement.LineNumber, "WRITE statement");
201
201
                
202
202
                //Base this on EmitDisplayVerb rather than on the style that
203
203
                //EmitReadStatement uses. EmitDisplayVerb and this should probably
206
206
                //whether or not it's being written to a file (and which file?) or
207
207
                //if it's going to the screen.
208
208
 
209
 
                return r;
 
209
            return EmitOutputBase(null, writeStatement);
210
210
        }
211
211
        
212
212
        private string EmitDisplayVerb(DisplayVerb display)
 
213
        {
 
214
            return EmitOutputBase(display, null);
 
215
        }
 
216
        
 
217
        private string EmitOutputBase(DisplayVerb display, WriteStatement writeStatement)
213
218
        {
214
219
            string r = "";
 
220
                    string className = "__CobolProgram";
215
221
            
216
222
            //Build the format string and param types list...
217
223
            string fmt = "";
218
 
            int objects = 0;
219
 
            for (int i = 0; i < display.Sources.Count; i++)
220
 
            {
221
 
                Source source = display.Sources[i] as Source;
 
224
            int objects = 0;
 
225
            
 
226
            ArrayList sources;
 
227
            if (display!=null)
 
228
            {
 
229
                sources = display.Sources;
 
230
            }else{
 
231
                //TODO: writeStatement.Filename is not correct here...
 
232
                
 
233
//              r += "        " + ILAddress(1) + "ldarg.0\n";
 
234
//              r += "        " + ILAddress(5);
 
235
//              r += "ldfld class [mscorlib]System.IO.StreamReader "+className+"::_writer_"+ILIdentifier(writeStatement.Filename.Name)+"\n";
 
236
                sources = new ArrayList();
 
237
                sources.Add(writeStatement.From);
 
238
            }
 
239
            
 
240
            for (int i = 0; i < sources.Count; i++)
 
241
            {
 
242
                Source source = sources[i] as Source;
222
243
                if (IsGroup(source))
223
244
                {
224
245
                        Identifier id = source as Identifier;
272
293
 
273
294
            //Load the values...
274
295
            int obj = 0;
275
 
            foreach (Source source in display.Sources)
 
296
            foreach (Source source in sources)
276
297
            {
277
298
                if (IsGroup(source))
278
299
                {
307
328
                }
308
329
            }
309
330
            
310
 
            //Call Write or WriteLine...
311
 
            r += ILAddress(5);
312
 
            string parms = "string, object[]";
313
 
            if (display.NoAdvancing)
314
 
            {
315
 
                r += "call void class [mscorlib]System.Console::Write(" + parms + ")";
316
 
            }else{
317
 
                r += "call void class [mscorlib]System.Console::WriteLine(" + parms + ")";
 
331
            if (display!=null)
 
332
            {
 
333
                //Call Write or WriteLine...
 
334
                r += ILAddress(5);
 
335
                string parms = "string, object[]";
 
336
                if (display.NoAdvancing)
 
337
                {
 
338
                        r += "call void class [mscorlib]System.Console::Write(" + parms + ")";
 
339
                }else{
 
340
                        r += "call void class [mscorlib]System.Console::WriteLine(" + parms + ")";
 
341
                }
 
342
                r += "\n";
 
343
            }else{
 
344
                
 
345
                //TODO: Emit stream writing code
 
346
                
 
347
                //throw new Compiler.Exceptions.NotImplementedException(
 
348
                //        writeStatement.LineNumber, "WRITE statement");
 
349
                        
 
350
                r += "        " + ILAddress(5);
 
351
                r += "callvirt instance string class [mscorlib]System.IO.StreamWriter::WriteLine()\n"; 
 
352
                        
318
353
            }
319
 
            r += "\n";
320
354
            return r;
321
355
        }
322
356