Ignore:
Timestamp:
Jun 26, 2023, 6:08:23 PM (17 months ago)
Author:
chronos
Message:
  • Added: Support for procedures.
  • Added: Project pascal file can be opened from main menu. Last file name is remembered.
  • Modified: Improved XML output of source structure.
Location:
branches/xpascal/Generators
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/xpascal/Generators/GeneratorCSharp.pas

    r230 r233  
    227227
    228228procedure TGeneratorCSharp.GenerateProgram(Block: TBlock; Prog: TProgram);
    229 begin
     229var
     230  MainClass: string;
     231begin
     232  if Prog.Name <> '' then MainClass := Prog.Name
     233    else MainClass := 'App';
    230234  AddTextLine('using System;');
    231235  AddTextLine;
    232   AddTextLine('public class ' + Prog.Name);
     236  AddTextLine('public class ' + MainClass);
    233237  AddTextLine('{');
    234238  Indent := Indent + 1;
     
    237241  AddTextLine('public static void Main()');
    238242  AddTextLine('{');
    239   AddTextLine('  ' + Prog.Name + ' app = new ' + Prog.Name + '();');
     243  AddTextLine('  ' + MainClass + ' app = new ' + MainClass + '();');
    240244  AddTextLine('  app.Entry();');
    241245  AddTextLine('}');
  • branches/xpascal/Generators/GeneratorXml.pas

    r232 r233  
    1111  TGeneratorXml = class(TGenerator)
    1212  private
    13     procedure GenerateNodes(SourceNodes: TSourceNodeList<TSourceNode>);
    14     procedure GenerateNode(SourceNode: TSourceNode);
     13    procedure GenerateNodes(SourceNodes: TSourceNodeList<TSourceNode>;
     14      NodeName: string);
     15    procedure GenerateNode(SourceNode: TSourceNode; NodeName: string);
    1516  public
    1617    procedure Generate; override;
     
    2627{ TGeneratorXml }
    2728
    28 procedure TGeneratorXml.GenerateNodes(SourceNodes: TSourceNodeList<TSourceNode>);
     29procedure TGeneratorXml.GenerateNodes(SourceNodes: TSourceNodeList<TSourceNode>;
     30  NodeName: string);
    2931var
    3032  I: Integer;
     
    3234  for I := 0 to SourceNodes.Count - 1 do begin
    3335    if SourceNodes[I] is TSourceNode then begin
    34       GenerateNode(TSourceNode(SourceNodes[I]));
     36      GenerateNode(TSourceNode(SourceNodes[I]), NodeName);
    3537    end else raise Exception.Create(SUnsupportedNodeType);
    3638  end;
    3739end;
    3840
    39 procedure TGeneratorXml.GenerateNode(SourceNode: TSourceNode);
     41procedure TGeneratorXml.GenerateNode(SourceNode: TSourceNode; NodeName: string);
    4042var
    4143  I: Integer;
     
    4547begin
    4648  if SourceNode is TSourceNode then begin
    47     AddTextLine('<' + SourceNode.ClassName + '>');
     49    AddTextLine('<' + NodeName + '>');
    4850    Indent := Indent + 1;
    4951    for I := 0 to SourceNode.FieldsCount - 1 do begin
    5052      Field := SourceNode.GetField(I);
    51       if Field.DataType = dtObject then begin
    52         Obj := SourceNode.GetValueObject(I);
    53         if Obj is TSourceNode then
    54           GenerateNode(TSourceNode(Obj));
    55       end else
    56       if Field.DataType = dtList then begin
    57         SourceNode.GetValue(I, List);
    58         GenerateNodes(List);
    59       end else
    60       if Field.DataType = dtString then begin
    61         AddTextLine('<' + Field.Name + '>' + SourceNode.GetValueString(I) + '<' + Field.Name + '>');
     53      try
     54        if Field.DataType = dtObject then begin
     55          Obj := SourceNode.GetValueObject(I);
     56          if Obj is TSourceNode then
     57            GenerateNode(TSourceNode(Obj), Field.Name);
     58        end else
     59        if Field.DataType = dtList then begin
     60          SourceNode.GetValue(I, List);
     61          if List.Count > 0 then
     62            GenerateNodes(List, Field.Name);
     63        end else
     64        if Field.DataType = dtString then begin
     65          if SourceNode.GetValueString(I) <> '' then
     66            AddTextLine('<' + Field.Name + '>' + SourceNode.GetValueString(I) +
     67              '</' + Field.Name + '>');
     68        end;
     69      finally
     70        Field.Free;
    6271      end;
    63       Field.Free;
    6472    end;
    6573    Indent := Indent - 1;
    66     AddTextLine('</' + SourceNode.ClassName + '>');
     74    AddTextLine('</' + NodeName + '>');
    6775  end else
    6876    raise Exception.Create(SUnsupportedNodeType);
     
    7179procedure TGeneratorXml.Generate;
    7280begin
    73   GenerateNode(Prog);
     81  AddTextLine('<?xml version="1.0" encoding="UTF-8"?>');
     82  GenerateNode(Prog, 'Program');
    7483end;
    7584
Note: See TracChangeset for help on using the changeset viewer.