~sandy-dunlop/wildcatcobol/dev

« back to all changes in this revision

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

  • Committer: Sandy Dunlop
  • Date: 2007-10-14 16:14:15 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: sandy.dunlop@gmail.com-20071014161415-ycq6t3nulucpsavw
Fixing an issue with anonymous data definition entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
877
877
        {
878
878
            string r = "";
879
879
            //TODO: Implement"corresponding"
880
 
            //TODO: Implement "MOVE SPACES..."
881
 
            if (move.From.IsSpaces)
882
 
            {
883
 
                //TODO: Type checking
884
 
                //TODO: Line number in exception
885
 
                //TODO: Look variable up in definitions and get size, then move n spaces into it.
886
 
                foreach (Identifier toIdentifier in move.To)
 
880
            //TODO: Implement "MOVE SPACES..."
 
881
            if (move.From.GetType() == typeof(FigurativeConstant))
 
882
            {
 
883
                FigurativeConstant constant = move.From as FigurativeConstant;
 
884
                if (constant.Type == FigurativeConstantType.Spaces)
887
885
                {
888
 
                    int size = toIdentifier.Definition.Size;
889
 
                    //Console.WriteLine("MOVE SPACES TO variable of size "+size);
890
 
                    r += "        ";
891
 
                    r += ILAddress(1) + "ldarg.0"; //Hidden pointer to 'this'
892
 
                    r += "\n";
893
 
                    Literal literal = new Literal();
894
 
                    literal.Type = VariableType.String;
895
 
                    literal.Value = "";
896
 
                    for (int i = 0; i < size; i++)
 
886
                    //TODO: Type checking
 
887
                    //TODO: Line number in exception
 
888
                    //TODO: Look variable up in definitions and get size, then move n spaces into it.
 
889
                    foreach (Identifier toIdentifier in move.To)
897
890
                    {
898
 
                        literal.Value += " ";
899
 
                    }
900
 
                    r += EmitLiteral(literal);
901
 
                    r += EmitStore(toIdentifier); //TODO: This needs changed for subscripts
902
 
                }
 
891
                        int size = toIdentifier.Definition.Size;
 
892
                        //Console.WriteLine("MOVE SPACES TO variable of size "+size);
 
893
                        r += "        ";
 
894
                        r += ILAddress(1) + "ldarg.0"; //Hidden pointer to 'this'
 
895
                        r += "\n";
 
896
                        Literal literal = new Literal();
 
897
                        literal.Type = VariableType.String;
 
898
                        literal.Value = "";
 
899
                        for (int i = 0; i < size; i++)
 
900
                        {
 
901
                            literal.Value += " ";
 
902
                        }
 
903
                        r += EmitLiteral(literal);
 
904
                        r += EmitStore(toIdentifier); //TODO: This needs changed for subscripts
 
905
                        if (IsGroup(toIdentifier))
 
906
                        {
 
907
                            r += "        " + ILAddress(1) + "ldarg.0\n"; //Hidden pointer to 'this'
 
908
                            r += "        " + ILAddress(1) + "ldc.i4.0\n"; //Zero, used for 'false'
 
909
                            r += "        " + ILAddress(5) + "stfld bool __CobolProgram::_hasData_"+toIdentifier.Definition.Name+"\n";
 
910
                        }
 
911
                    }
 
912
                }else{
 
913
                    Console.WriteLine("TODO: Other figurative constants not supported yet");
 
914
                }
903
915
            }
904
916
            else
905
917
            {
1307
1319
 
1308
1320
                        //Call substring:
1309
1321
                        //  IL_0011:  callvirt instance string string::Substring(int32, int32)
1310
 
                        r += "        " + ILAddress(5) + "callvirt instance string string::Substring(int32, int32)\n";
 
1322
                        r += "        " + ILAddress(5) + "callvirt instance string string::Substring(int32, int32)\n";
1311
1323
 
1312
1324
                        //Store result:
1313
1325
                        //  IL_0016:  stfld string WorkingStorageTest.Program::bb1
1414
1426
            {
1415
1427
                a = "a";
1416
1428
            }
1417
 
            if (id.Definition.IsGroup)
 
1429
            if (id.Definition.IsGroup && !id.Definition.IsAnonymous)
1418
1430
            {
1419
1431
                //TODO: Make this work
1420
 
                Console.WriteLine("EmitLoadField Groups/Records not supported yet");
 
1432
                //Console.WriteLine("EmitLoadField Groups/Records not supported yet");
1421
1433
                        
 
1434
                r += "        " + ILAddress(1) + "pop\n";
 
1435
                
 
1436
                //Build the format string...
 
1437
                        List<DataDescription> ddes = ListElements(id.Definition);
 
1438
                        int obj = 0;
 
1439
                        string fmt = "";
 
1440
                        foreach (DataDescription dd in ddes)
 
1441
                        {
 
1442
                        fmt += "{" + obj + ",-" + dd.Size + "}";
 
1443
                            obj++;
 
1444
                        }
 
1445
                        //Load the format string...
 
1446
                r += "        " + ILAddress(5);
 
1447
                r += "ldstr \"" + fmt + "\"\n";
 
1448
                        Console.WriteLine("fmt = "+fmt);
 
1449
                
1422
1450
                //Create an array
1423
 
                        List<DataDescription> ddes = ListElements(id.Definition);
1424
 
                r += "        " + ILAddress(1) + "pop\n";
1425
1451
                r += "        " + ILAddress(5);
1426
1452
                r += "ldc.i4 " + ddes.Count + "\n";
1427
1453
                r += "        " + ILAddress(5);
1428
1454
                r += "newarr [mscorlib]System.Object\n";
1429
1455
    
1430
1456
                //Load elements into array
1431
 
                        int obj = 0;
 
1457
                        obj = 0;
1432
1458
                        foreach (DataDescription dd in ddes)
1433
1459
                        {
1434
1460
                                Identifier tmp = new Identifier();
1437
1463
                            r += "        " + ILAddress(1) + "dup\n";
1438
1464
                            r += "        " + ILAddress(5) + "ldc.i4 "+obj+"\n";
1439
1465
                            r += EmitLoadSource(tmp as Source, false, true);
1440
 
                            if (tmp.Definition.Type == DataType.Integer){
1441
 
                                //TODO: Do this for boolean as well?
1442
 
                            r += "        " + ILAddress(5) + "call instance string int32::ToString()\n";
1443
 
                            }
1444
1466
                            r += "        " + ILAddress(1) + "stelem.ref\n";
1445
 
                            obj++;
 
1467
                    obj++;                          
1446
1468
                        }
1447
 
                    r += "        " + ILAddress(5) + "call string string::Concat(string[])\n";
 
1469
                    r += "        " + ILAddress(5) + "call string string::Format(string,object[])\n";
1448
1470
            }else{
1449
1471
                    string typ = null;
1450
1472
                    try{
2031
2053
                return EmitLiteral(literal,false);
2032
2054
        }
2033
2055
        
2034
 
        private string EmitSpaces()
2035
 
        {
2036
 
            string r = "";
2037
 
            r += "        ";
2038
 
            r += ILAddress(5);
2039
 
            r += "ldstr \"\"";
2040
 
            r += "\n";
2041
 
            return r;
2042
 
        }
2043
 
 
2044
 
 
2045
2056
        private string EmitBasis(Basis basis)
2046
2057
        {
2047
2058
            //TODO: Variable Types