~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-10-14 16:14:53 UTC
  • mfrom: (7.1.5 filewrite)
  • Revision ID: sandy.dunlop@gmail.com-20071014161453-otgf2yviplpqbviq
Merging from filewrite branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
133
133
        
134
134
        private string EmitReadStatement(ReadStatement readStatement)
135
135
        {
136
 
                string r = "";
 
136
                string r = "\n        //Begin read statement...\n";
137
137
                    string className = "__CobolProgram";
138
138
                
139
139
                FileAndSortDescriptionEntry fsde = GetFSDE(readStatement.Filename.Name);
194
194
                        r+=r2;
195
195
                        r+=r3;
196
196
 
 
197
            r+="        //End of read statement\n";
197
198
                return r;
198
199
        }
199
200
        
200
201
        private string EmitWriteStatement(WriteStatement writeStatement)
201
202
        {
 
203
                string r = "\n        //Begin write statement...\n";
202
204
                //string r = "";
203
205
            
204
206
            //throw new Compiler.Exceptions.NotImplementedException(
211
213
                //whether or not it's being written to a file (and which file?) or
212
214
                //if it's going to the screen.
213
215
 
214
 
            return EmitOutputBase(null, writeStatement);
 
216
            r+= EmitOutputBase(null, writeStatement);
 
217
            r+="        //End of write statement\n";
 
218
            return r;
215
219
        }
216
220
        
217
221
        private string EmitDisplayVerb(DisplayVerb display)
222
226
        private string EmitOutputBase(DisplayVerb display, WriteStatement writeStatement)
223
227
        {
224
228
            string r = "";
225
 
                    string className = "__CobolProgram";
 
229
                    string className = "__CobolProgram";
 
230
                    DataDescription dde = null;
226
231
            
227
232
            //Build the format string and param types list...
228
233
            string fmt = "";
233
238
            {
234
239
                sources = display.Sources;
235
240
            }else{
236
 
                //TODO: writeStatement.Filename is not correct here...
237
 
                
238
 
                System.Console.WriteLine("Processing WRITE statement");
239
 
                System.Console.WriteLine("RecordName = " + writeStatement.RecordName);
240
 
                DataDescription dde = GetDDEByName(writeStatement.RecordName.Name);
 
241
                dde = GetDDEByName(writeStatement.RecordName.Name);
241
242
                if (dde==null)
242
243
                {
243
244
                    Console.WriteLine("dde is NULL");
244
245
                }
245
246
                
246
 
                //TODO: Get FSDE from DDE
247
 
                Console.WriteLine("dde.FSDE.Name.Value = " + dde.FSDE.Name.Value);
248
 
                
249
 
                
250
 
//              r += "        " + ILAddress(1) + "ldarg.0\n";
251
 
//              r += "        " + ILAddress(5);
252
 
//              r += "ldfld class [mscorlib]System.IO.StreamReader "+className+"::_writer_"+ILIdentifier(writeStatement.Filename.Name)+"\n";
 
247
                r += "        " + ILAddress(1) + "ldarg.0\n";
 
248
                r += "        " + ILAddress(5);
 
249
                r += "ldfld class [mscorlib]System.IO.StreamWriter "+className+"::_writer_"+ILIdentifier(dde.FSDE.Name.Name)+"\n";
 
250
                
253
251
                sources = new ArrayList();
254
 
                if (writeStatement.From!=null)
 
252
                if (writeStatement.RecordName!=null)
255
253
                {
256
 
                    sources.Add(writeStatement.From);
 
254
                    sources.Add(writeStatement.RecordName);
257
255
                }
258
256
                //TODO: What should be done when there are no FROM identifiers?
259
257
            }
352
350
            if (display!=null)
353
351
            {
354
352
                //Call Write or WriteLine...
355
 
                r += ILAddress(5);
 
353
                r += "        " + ILAddress(5);
356
354
                string parms = "string, object[]";
357
355
                if (display.NoAdvancing)
358
356
                {
362
360
                }
363
361
                r += "\n";
364
362
            }else{
365
 
                
366
 
                //TODO: Emit stream writing code
367
 
                
368
 
                //throw new Compiler.Exceptions.NotImplementedException(
369
 
                //        writeStatement.LineNumber, "WRITE statement");
370
 
                        
371
 
                r += "        " + ILAddress(5);
372
 
                r += "callvirt instance string class [mscorlib]System.IO.StreamWriter::WriteLine()\n"; 
373
 
                        
 
363
                //Write...
 
364
                r += "        " + ILAddress(5);
 
365
                r += "callvirt instance void class [mscorlib]System.IO.StreamWriter::WriteLine(string,object[])\n"; 
 
366
                
 
367
                //Flush...
 
368
                r += "        " + ILAddress(1) + "ldarg.0\n";
 
369
                r += "        " + ILAddress(5);
 
370
                r += "ldfld class [mscorlib]System.IO.StreamWriter "+className+"::_writer_"+ILIdentifier(dde.FSDE.Name.Name)+"\n";
 
371
                r += "        " + ILAddress(5);
 
372
                r += "callvirt instance void class [mscorlib]System.IO.StreamWriter::Flush()\n"; 
374
373
            }
375
374
            return r;
376
375
        }
384
383
            //Console.WriteLine("accept.Identifier = "+accept.Identifier);
385
384
            //Console.WriteLine("accept.Identifier.Definition = "+accept.Identifier.Definition);
386
385
            DataType type = accept.Identifier.Definition.Type;
387
 
            //string typ = _program.GetVarType(v);
388
 
 
 
386
            //string typ = _program.GetVarType(v);
 
387
            
389
388
            if (type == DataType.Integer)
390
389
            {
391
390
                r += "        " + ILAddress(5);
396
395
                r += "\n";
397
396
                //Now parse location 0 (__cobolInputTemp) and store in v
398
397
                r += "        " + ILAddress(1) + "ldarg.0\n";
399
 
                r += "        " + ILAddress(2) + "ldloc.1\n";
400
 
                r += "        " + ILAddress(4) + "call int32 int32::Parse(string)\n";
 
398
                r += "        " + ILAddress(1) + "ldloc.1\n";
 
399
                r += "        " + ILAddress(5) + "call int32 int32::Parse(string)\n";
401
400
                r += "        ";
402
401
                r += ILAddress(5) + "stfld int32 __CobolProgram::" + v;
403
402
                r += "\n";
413
412
                r += "        ";
414
413
                r += ILAddress(5) + "stfld string __CobolProgram::" + v;
415
414
                r += "\n";
 
415
 
 
416
                if (IsGroup(accept.Identifier))
 
417
                {
 
418
                    //TOOD: Set flag to indicate group is empty to true
 
419
                    //      Then let EmitStore change it if necessary
 
420
                    r += "        " + ILAddress(1) + "ldarg.0\n"; //Hidden pointer to 'this'
 
421
                    r += "        " + ILAddress(1) + "ldc.i4.0\n"; //Zero, used for 'false'
 
422
                    r += "        " + ILAddress(5) + "stfld bool __CobolProgram::_hasData_"+v+"\n";
 
423
                    //laod false  _isEmpty_
 
424
                    
 
425
                    r += "        ";
 
426
                    r += ILAddress(1) + "ldarg.0"; //Hidden pointer to 'this'
 
427
                    r += "\n";
 
428
                    r += "        ";
 
429
                    r += ILAddress(5) + "ldfld string __CobolProgram::" + v;
 
430
                    r += "\n";
 
431
                    r += EmitStore(accept.Identifier,null);
 
432
                }
416
433
            }
 
434
            
 
435
 
417
436
            return r;
418
437
        }        
419
438
    }