Changeset 55


Ignore:
Timestamp:
Aug 10, 2010, 1:48:38 PM (14 years ago)
Author:
george
Message:

Fix: View proper source file after click to error message.
Made partial changes to support unit interface and implementation sections.

Location:
branches/DelphiToC
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • branches/DelphiToC/Analyze/UParser.pas

    r54 r55  
    5151    procedure ParseExpression(SourceCode: TExpression);
    5252    procedure ParseUsedModuleList(SourceCode: TUsedModuleList);
    53     procedure ParseModule(SourceCode: TModule);
    54     procedure ParseUnit(SourceCode: TModule);
    55     procedure ParseProgram(SourceCode: TModule);
     53    function ParseModule: TModule;
     54    procedure ParseUnit(SourceCode: TModuleUnit);
     55    procedure ParseUnitInterface(SourceCode: TUnitInterface);
     56    procedure ParseUnitImplementation(SourceCode: TUnitImplementation);
     57    procedure ParseProgram(SourceCode: TModuleProgram);
    5658    procedure ParseCommonBlock(SourceCode: TCommonBlock; EndSymbol: char = ';');
    5759    function ParseCommand(SourceCode: TCommonBlock): TCommand;
     
    628630{ TParserModule }
    629631
    630 procedure TPascalParser.ParseModule(SourceCode: TModule);
    631 begin
    632   if FNextToken = 'program' then
    633     ParseProgram(SourceCode)
    634   else if FNextToken = 'unit' then
    635     ParseUnit(SourceCode)
    636   else
    637     ParseProgram(SourceCode);
    638 end;
    639 
    640 procedure TPascalParser.ParseProgram(SourceCode: TModule);
     632function TPascalParser.ParseModule: TModule;
     633begin
     634  if FNextToken = 'unit' then begin
     635    Result := TModuleUnit.Create;
     636    ParseUnit(TModuleUnit(Result));
     637  end else begin //if FNextToken = 'program' then begin
     638    Result := TModuleProgram.Create;
     639    ParseProgram(TModuleProgram(Result));
     640  end;
     641end;
     642
     643procedure TPascalParser.ParseProgram(SourceCode: TModuleProgram);
    641644var
    642645  Identifier: string;
    643646begin
    644   with SourceCode do
    645   begin
    646     if FNextToken = 'program' then
    647     begin
     647  with SourceCode do begin
     648    if FNextToken = 'program' then begin
    648649      Expect('program');
    649650      Name := ReadCode;
    650       ModuleType := mdProgram;
    651651      Expect(';');
    652652    end else Name := '';
     
    656656      ParseUsedModuleList(UsedModules);
    657657
    658     ParseCommonBlock(SourceCode, '.');
    659   end;
    660 end;
    661 
    662 procedure TPascalParser.ParseUnit(SourceCode: TModule);
     658    ParseCommonBlock(Body, '.');
     659  end;
     660end;
     661
     662procedure TPascalParser.ParseUnit(SourceCode: TModuleUnit);
    663663var
    664664  NewModule: TModule;
    665665begin
    666666  Expect('unit');
    667   with Sourcecode do
    668   begin
     667  with Sourcecode do begin
    669668    Name := ReadCode;
    670     ModuleType := mdUnit;
    671669  end;
    672670  Expect(';');
    673   //ParseInterface;
    674   //ParseImplementation;
    675 end;
    676 
    677 { TParserProgram }
     671
     672  ParseUnitInterface(SourceCode.InterfaceSection);
     673  if FNextToken = 'implementation' then
     674    ParseUnitImplementation(SourceCode.ImplementationSection);
     675end;
     676
     677procedure TPascalParser.ParseUnitInterface(SourceCode: TUnitInterface);
     678begin
     679  Expect('interface');
     680  // Uses section
     681  if FNextToken = 'uses' then
     682    ParseUsedModuleList(SourceCode.UsedModules);
     683
     684  ParseCommonBlock(SourceCode.Body, '.');
     685end;
     686
     687procedure TPascalParser.ParseUnitImplementation(SourceCode: TUnitImplementation);
     688begin
     689  Expect('implementation');
     690
     691  // Uses section
     692  if FNextToken = 'uses' then
     693    ParseUsedModuleList(SourceCode.UsedModules);
     694
     695  ParseCommonBlock(SourceCode.Body, '.');
     696end;
    678697
    679698{ TParserCommonBlock }
  • branches/DelphiToC/Forms/UMainForm.lfm

    r54 r55  
    33  Height = 494
    44  Top = 103
    5   Width = 884
     5  Width = 861
    66  Caption = 'Transpascal '
    77  ClientHeight = 494
    8   ClientWidth = 884
     8  ClientWidth = 861
    99  Font.Height = -11
    1010  Font.Name = 'Tahoma'
     
    1616  LCLVersion = '0.9.29'
    1717  object ButtonCompile: TButton
    18     Left = 736
     18    Left = 713
    1919    Height = 22
    2020    Top = 397
     
    2828    TabOrder = 0
    2929  end
    30   inline SynEdit1: TSynEdit
     30  inline SynEditSource: TSynEdit
    3131    Left = 248
    3232    Height = 384
     
    611611      end>
    612612    Lines.Strings = (
    613       'SynEdit1'
     613      'SynEditSource'
    614614    )
    615615    BracketHighlightStyle = sbhsBoth
     
    723723  end
    724724  object ComboBox1: TComboBox
    725     Left = 735
     725    Left = 712
    726726    Height = 21
    727727    Top = 424
    728728    Width = 144
    729     Anchors = [akLeft, akRight, akBottom]
     729    Anchors = [akRight, akBottom]
    730730    ItemHeight = 13
    731731    ItemIndex = 0
     
    741741    Text = 'Pascal'
    742742  end
    743   object ListBox1: TListBox
     743  object ListBoxMessages: TListBox
    744744    Left = 8
    745745    Height = 91
    746746    Top = 398
    747     Width = 720
     747    Width = 697
    748748    Anchors = [akLeft, akRight, akBottom]
    749749    ItemHeight = 0
    750     OnClick = ListBox1Click
     750    OnClick = ListBoxMessagesClick
    751751    TabOrder = 3
    752752  end
     
    755755    Height = 382
    756756    Top = 8
    757     Width = 231
     757    Width = 208
    758758    Anchors = [akTop, akLeft, akRight, akBottom]
    759759    BevelOuter = bvNone
  • branches/DelphiToC/Forms/UMainForm.pas

    r54 r55  
    2020    ButtonCompile: TButton;
    2121    ComboBox1: TComboBox;
    22     ListBox1: TListBox;
     22    ListBoxMessages: TListBox;
    2323    Panel1: TPanel;
    24     SynEdit1: TSynEdit;
     24    SynEditSource: TSynEdit;
    2525    SynPasSyn1: TSynPasSyn;
    2626    TreeViewProject: TTreeView;
     
    3131    procedure FormCreate(Sender: TObject);
    3232    procedure FormDestroy(Sender: TObject);
    33     procedure ListBox1Click(Sender: TObject);
     33    procedure ListBoxMessagesClick(Sender: TObject);
    3434    procedure TreeViewProjectChange(Sender: TObject; Node: TTreeNode);
    3535  private
     
    7979
    8080  // Compile all project files
     81  Compiler.Init;
    8182  for I := 0 to Project.Items.Count - 1 do begin
    82     if TProjectNode(Project.Items[I]) is TProjectFile then begin
    83       Compiler.Compile(TProjectFile(Project.Items[I]).Source,
    84         TProjectFile(Project.Items[I]).ProducedCode);
     83    if TProjectNode(Project.Items[I]) is TProjectFile then
     84    with TProjectFile(Project.Items[I]) do begin
     85      Compiler.Compile(Parent.GetDir + Name, Source, ProducedCode);
    8586    end;
    8687  end;
     
    113114end;
    114115
    115 procedure TMainForm.ListBox1Click(Sender: TObject);
    116 begin
    117   if ListBox1.ItemIndex <> - 1 then begin
    118     SynEdit1.CaretXY := TErrorMessage(Compiler.ErrorMessages[ListBox1.ItemIndex]).Position;
    119     SynEdit1.SetFocus;
     116procedure TMainForm.ListBoxMessagesClick(Sender: TObject);
     117var
     118  ProjectFile: TProjectFile;
     119begin
     120  if ListBoxMessages.ItemIndex <> -1 then
     121  with TErrorMessage(Compiler.ErrorMessages[ListBoxMessages.ItemIndex]) do begin
     122    ProjectFile := Project.SearchFile(fileName);
     123    if Assigned(ProjectFile) then
     124      SynEditSource.Lines.Assign(ProjectFile.Source);
     125    SynEditSource.CaretXY := Position;
     126    SynEditSource.SetFocus;
    120127  end;
    121128end;
     
    125132  I: Integer;
    126133begin
    127   ListBox1.Clear;
     134  ListBoxMessages.Clear;
    128135  for I := 0 to Compiler.ErrorMessages.Count - 1 do
    129136  with TErrorMessage(Compiler.ErrorMessages[I]) do
    130     MainForm.ListBox1.Items.Add('(' + IntToStr(Position.X) +
     137    MainForm.ListBoxMessages.Items.Add(FileName + '(' + IntToStr(Position.X) +
    131138      ',' + IntToStr(Position.Y) + ') ' + Text);
    132139end;
     
    136143  if Assigned(Node) then begin
    137144    if TProjectNode(Node.Data) is TProjectFile then begin
    138       SynEdit1.Lines.Assign(TProjectFile(Node.Data).Source);
     145      SynEditSource.Lines.Assign(TProjectFile(Node.Data).Source);
    139146      if ProducerControl is TMemo then
    140147        TMemo(ProducerControl).Lines.Assign(TProjectFile(Node.Data).ProducedCode);
     
    193200  NewProjectFile: TProjectFile;
    194201begin
     202  Project.RootDir := '../../Project/';
    195203  Project.Name := 'Project';
     204
    196205  NewProjectFile := TProjectFile.Create;
     206  NewProjectFile.Parent := Project;
    197207  NewProjectFile.Name := 'Project.pas';
    198   NewProjectFile.FileName := ProjectDir + 'Project.pas';
    199208  Project.Items.Add(NewProjectFile);
     209
    200210  NewProjectFile := TProjectFile.Create;
     211  NewProjectFile.Parent := Project;
    201212  NewProjectFile.Name := 'System.pas';
    202   NewProjectFile.FileName := ProjectDir + 'System.pas';
    203213  Project.Items.Add(NewProjectFile);
     214
     215  NewProjectFile := TProjectFile.Create;
     216  NewProjectFile.Parent := Project;
     217  NewProjectFile.Name := 'Console.pas';
     218  Project.Items.Add(NewProjectFile);
     219
    204220  Project.Load;
    205221  UpdateProjectTree;
  • branches/DelphiToC/Produce/UProducerC.pas

    r54 r55  
    115115  Emit('#define uint32 unsigned long');
    116116  Emit('');
    117   GenerateUses(Module.UsedModules);
    118   GenerateCommonBlock(Module, '');
     117  if Module is TModuleProgram then begin
     118    GenerateUses(TModuleProgram(Module).UsedModules);
     119    GenerateCommonBlock(TModuleProgram(Module).Body, '');
     120  end;
    119121end;
    120122
  • branches/DelphiToC/Produce/UProducerPascal.pas

    r54 r55  
    8484procedure TProducerPascal.GenerateModule(Module: TModule);
    8585begin
    86   case Module.ModuleType of
    87     mdProgram: Emit('program', False);
    88     mdUnit: Emit('unit', False);
    89     mdLibrary: Emit('library', False);
    90     mdPackage: Emit('package', False);
    91   end;
    92   Emit(' ' + Module.Name + ';');
    93   Emit('');
    94   GenerateUses(Module.UsedModules);
    95   GenerateCommonBlock(Module, '');
    96   Emit('.', False);
     86  if Module is TModuleProgram then
     87  with TModuleProgram(Module) do begin
     88    Emit('program', False);
     89    Emit(' ' + Name + ';');
     90    Emit('');
     91    GenerateUses(UsedModules);
     92    GenerateCommonBlock(Body, '');
     93    Emit('.', False);
     94  end else
     95  if Module is TModuleUnit then Emit('unit', False)
     96  else if Module is TModuleLibrary then Emit('library', False)
     97  else if Module is TModulePackage then Emit('package', False);
    9798end;
    9899
  • branches/DelphiToC/Produce/UProducerTreeView.pas

    r54 r55  
    284284  TypeName: string;
    285285begin
    286   case Module.ModuleType of
    287     mdPackage: TypeName := 'package';
    288     mdProgram: TypeName := 'program';
    289     mdUnit: TypeName := 'unit';
    290     mdLibrary: TypeName := 'library';
    291   end;
    292   NewNode := TreeView.Items.AddChild(Node, TypeName + ' ' + Module.Name);
    293   AddNodeUses(NewNode, Module.UsedModules);
    294   AddNodeMethodList(NewNode, Module.Functions);
    295   AddNodeConstantList(NewNode, Module.Constants);
    296   AddNodeVariableList(NewNode, Module.Variables);
    297   AddNodeTypeList(NewNode, Module.Types);
    298   AddNodeBeginEnd(NewNode, Module.Code);
     286  if Module is TModulePackage then TypeName := 'package'
     287  else if Module is TModuleProgram then
     288  with TModuleProgram(Module) do begin
     289    TypeName := 'program';
     290    NewNode := TreeView.Items.AddChild(Node, TypeName + ' ' + Module.Name);
     291    AddNodeUses(NewNode, UsedModules);
     292    AddNodeMethodList(NewNode, Body.Functions);
     293    AddNodeConstantList(NewNode, Body.Constants);
     294    AddNodeVariableList(NewNode, Body.Variables);
     295    AddNodeTypeList(NewNode, Body.Types);
     296    AddNodeBeginEnd(NewNode, Body.Code);
     297  end else if Module is TModuleUnit then TypeName := 'unit'
     298  else if Module is TModuleLibrary then TypeName := 'library';
     299
    299300end;
    300301
  • branches/DelphiToC/Project/System.pas

    r54 r55  
    11unit System;
     2
     3interface
    24
    35type
     
    1517  String = array of Char;
    1618
     19
    1720procedure Exit; system;
    18 begin
    19 end;
     21procedure Break; system;
     22procedure Continue; system;
    2023
    21 procedure Break; system;
    22 begin
    23 end;
     24implementation
    2425
    25 procedure Continue; system;
    26 begin
    27 end;
    2826
    2927end.
  • branches/DelphiToC/Transpascal.lpi

    r54 r55  
    4141      </Item2>
    4242    </RequiredPackages>
    43     <Units Count="21">
     43    <Units Count="22">
    4444      <Unit0>
    4545        <Filename Value="Transpascal.lpr"/>
     
    6060        <ResourceBaseClass Value="Form"/>
    6161        <UnitName Value="UMainForm"/>
     62        <IsVisibleTab Value="True"/>
    6263        <EditorIndex Value="6"/>
    6364        <WindowIndex Value="0"/>
    64         <TopLine Value="91"/>
    65         <CursorPos X="40" Y="106"/>
     65        <TopLine Value="207"/>
     66        <CursorPos X="10" Y="224"/>
    6667        <UsageCount Value="148"/>
    6768        <Loaded Value="True"/>
     
    8384        <EditorIndex Value="5"/>
    8485        <WindowIndex Value="0"/>
    85         <TopLine Value="1"/>
    86         <CursorPos X="29" Y="14"/>
     86        <TopLine Value="761"/>
     87        <CursorPos X="13" Y="784"/>
    8788        <UsageCount Value="148"/>
    8889        <Loaded Value="True"/>
     
    9293        <IsPartOfProject Value="True"/>
    9394        <UnitName Value="UCompiler"/>
    94         <EditorIndex Value="13"/>
    95         <WindowIndex Value="0"/>
    96         <TopLine Value="37"/>
    97         <CursorPos X="29" Y="50"/>
     95        <EditorIndex Value="14"/>
     96        <WindowIndex Value="0"/>
     97        <TopLine Value="1"/>
     98        <CursorPos X="5" Y="17"/>
    9899        <UsageCount Value="148"/>
    99100        <Loaded Value="True"/>
     
    125126        <IsPartOfProject Value="True"/>
    126127        <UnitName Value="UProducerC"/>
    127         <EditorIndex Value="12"/>
    128         <WindowIndex Value="0"/>
    129         <TopLine Value="121"/>
    130         <CursorPos X="17" Y="125"/>
     128        <EditorIndex Value="13"/>
     129        <WindowIndex Value="0"/>
     130        <TopLine Value="104"/>
     131        <CursorPos X="52" Y="119"/>
    131132        <UsageCount Value="148"/>
    132133        <Loaded Value="True"/>
     
    138139        <EditorIndex Value="0"/>
    139140        <WindowIndex Value="0"/>
    140         <TopLine Value="619"/>
    141         <CursorPos X="1" Y="632"/>
     141        <TopLine Value="680"/>
     142        <CursorPos X="25" Y="689"/>
    142143        <UsageCount Value="148"/>
    143144        <Loaded Value="True"/>
     
    206207        <EditorIndex Value="2"/>
    207208        <WindowIndex Value="0"/>
    208         <TopLine Value="280"/>
    209         <CursorPos X="45" Y="294"/>
     209        <TopLine Value="277"/>
     210        <CursorPos X="26" Y="291"/>
    210211        <UsageCount Value="110"/>
    211212        <Loaded Value="True"/>
     
    230231        <IsPartOfProject Value="True"/>
    231232        <UnitName Value="UProducerPascal"/>
    232         <IsVisibleTab Value="True"/>
    233233        <EditorIndex Value="8"/>
    234234        <WindowIndex Value="0"/>
    235         <TopLine Value="74"/>
    236         <CursorPos X="14" Y="92"/>
     235        <TopLine Value="77"/>
     236        <CursorPos X="34" Y="93"/>
    237237        <UsageCount Value="64"/>
    238238        <Loaded Value="True"/>
     
    244244        <EditorIndex Value="11"/>
    245245        <WindowIndex Value="0"/>
    246         <TopLine Value="24"/>
    247         <CursorPos X="16" Y="37"/>
     246        <TopLine Value="78"/>
     247        <CursorPos X="1" Y="99"/>
    248248        <UsageCount Value="20"/>
    249249        <Loaded Value="True"/>
    250250      </Unit20>
     251      <Unit21>
     252        <Filename Value="E:\Programy\Lazarus\fpc\2.4.0\source\rtl\inc\wstringh.inc"/>
     253        <EditorIndex Value="12"/>
     254        <WindowIndex Value="0"/>
     255        <TopLine Value="17"/>
     256        <CursorPos X="11" Y="30"/>
     257        <UsageCount Value="10"/>
     258        <Loaded Value="True"/>
     259      </Unit21>
    251260    </Units>
    252261    <JumpHistory Count="30" HistoryIndex="29">
    253262      <Position1>
    254         <Filename Value="Produce\UProducerPascal.pas"/>
    255         <Caret Line="149" Column="18" TopLine="144"/>
     263        <Filename Value="Forms\UMainForm.pas"/>
     264        <Caret Line="131" Column="21" TopLine="118"/>
    256265      </Position1>
    257266      <Position2>
    258         <Filename Value="Produce\UProducerPascal.pas"/>
    259         <Caret Line="40" Column="23" TopLine="27"/>
     267        <Filename Value="Forms\UMainForm.pas"/>
     268        <Caret Line="120" Column="40" TopLine="109"/>
    260269      </Position2>
    261270      <Position3>
    262         <Filename Value="Produce\UProducerC.pas"/>
    263         <Caret Line="40" Column="38" TopLine="27"/>
     271        <Filename Value="UProject.pas"/>
     272        <Caret Line="30" Column="58" TopLine="14"/>
    264273      </Position3>
    265274      <Position4>
    266         <Filename Value="Produce\UProducerC.pas"/>
    267         <Caret Line="121" Column="29" TopLine="107"/>
     275        <Filename Value="UProject.pas"/>
     276        <Caret Line="91" Column="49" TopLine="82"/>
    268277      </Position4>
    269278      <Position5>
    270         <Filename Value="Produce\UProducerC.pas"/>
    271         <Caret Line="40" Column="66" TopLine="39"/>
     279        <Filename Value="UProject.pas"/>
     280        <Caret Line="92" Column="49" TopLine="82"/>
    272281      </Position5>
    273282      <Position6>
    274         <Filename Value="UCompiler.pas"/>
    275         <Caret Line="50" Column="1" TopLine="29"/>
     283        <Filename Value="UProject.pas"/>
     284        <Caret Line="44" Column="3" TopLine="19"/>
    276285      </Position6>
    277286      <Position7>
    278         <Filename Value="Produce\UProducerAsm8051.pas"/>
    279         <Caret Line="37" Column="38" TopLine="24"/>
     287        <Filename Value="Forms\UMainForm.pas"/>
     288        <Caret Line="120" Column="40" TopLine="109"/>
    280289      </Position7>
    281290      <Position8>
    282         <Filename Value="Produce\UProducerAsm8051.pas"/>
    283         <Caret Line="191" Column="35" TopLine="171"/>
     291        <Filename Value="Forms\UMainForm.pas"/>
     292        <Caret Line="122" Column="39" TopLine="106"/>
    284293      </Position8>
    285294      <Position9>
    286         <Filename Value="Produce\UProducerAsm8051.pas"/>
    287         <Caret Line="37" Column="66" TopLine="37"/>
     295        <Filename Value="Forms\UMainForm.pas"/>
     296        <Caret Line="121" Column="22" TopLine="108"/>
    288297      </Position9>
    289298      <Position10>
    290         <Filename Value="Produce\UProducerAsm8051.pas"/>
    291         <Caret Line="193" Column="24" TopLine="171"/>
     299        <Filename Value="Forms\UMainForm.pas"/>
     300        <Caret Line="124" Column="52" TopLine="110"/>
    292301      </Position10>
    293302      <Position11>
    294         <Filename Value="Produce\UProducerAsm8051.pas"/>
    295         <Caret Line="35" Column="45" TopLine="24"/>
     303        <Filename Value="Forms\UMainForm.pas"/>
     304        <Caret Line="123" Column="1" TopLine="110"/>
    296305      </Position11>
    297306      <Position12>
    298         <Filename Value="Produce\UProducerAsm8051.pas"/>
    299         <Caret Line="37" Column="15" TopLine="22"/>
     307        <Filename Value="Forms\UMainForm.pas"/>
     308        <Caret Line="125" Column="1" TopLine="110"/>
    300309      </Position12>
    301310      <Position13>
    302         <Filename Value="Produce\UProducerTreeView.pas"/>
    303         <Caret Line="325" Column="1" TopLine="311"/>
     311        <Filename Value="Forms\UMainForm.pas"/>
     312        <Caret Line="122" Column="1" TopLine="110"/>
    304313      </Position13>
    305314      <Position14>
    306         <Filename Value="Produce\UProducerTreeView.pas"/>
    307         <Caret Line="36" Column="23" TopLine="23"/>
     315        <Filename Value="UProject.pas"/>
     316        <Caret Line="86" Column="1" TopLine="74"/>
    308317      </Position14>
    309318      <Position15>
    310         <Filename Value="Produce\UProducerTreeView.pas"/>
    311         <Caret Line="329" Column="13" TopLine="311"/>
     319        <Filename Value="UProject.pas"/>
     320        <Caret Line="87" Column="1" TopLine="74"/>
    312321      </Position15>
    313322      <Position16>
    314         <Filename Value="Analyze\UParser.pas"/>
    315         <Caret Line="635" Column="12" TopLine="630"/>
     323        <Filename Value="UProject.pas"/>
     324        <Caret Line="86" Column="44" TopLine="74"/>
    316325      </Position16>
    317326      <Position17>
    318         <Filename Value="Analyze\UParser.pas"/>
    319         <Caret Line="632" Column="1" TopLine="627"/>
     327        <Filename Value="Forms\UMainForm.pas"/>
     328        <Caret Line="122" Column="1" TopLine="110"/>
    320329      </Position17>
    321330      <Position18>
    322         <Filename Value="Analyze\UParser.pas"/>
    323         <Caret Line="634" Column="1" TopLine="627"/>
     331        <Filename Value="UProject.pas"/>
     332        <Caret Line="86" Column="1" TopLine="74"/>
    324333      </Position18>
    325334      <Position19>
    326         <Filename Value="Analyze\UParser.pas"/>
    327         <Caret Line="635" Column="1" TopLine="627"/>
     335        <Filename Value="UProject.pas"/>
     336        <Caret Line="87" Column="1" TopLine="74"/>
    328337      </Position19>
    329338      <Position20>
    330         <Filename Value="Analyze\UParser.pas"/>
    331         <Caret Line="665" Column="1" TopLine="652"/>
     339        <Filename Value="UProject.pas"/>
     340        <Caret Line="89" Column="1" TopLine="74"/>
    332341      </Position20>
    333342      <Position21>
    334         <Filename Value="Analyze\UParser.pas"/>
    335         <Caret Line="666" Column="1" TopLine="652"/>
     343        <Filename Value="UProject.pas"/>
     344        <Caret Line="90" Column="1" TopLine="74"/>
    336345      </Position21>
    337346      <Position22>
    338         <Filename Value="Analyze\UParser.pas"/>
    339         <Caret Line="669" Column="1" TopLine="652"/>
     347        <Filename Value="UProject.pas"/>
     348        <Caret Line="91" Column="1" TopLine="74"/>
    340349      </Position22>
    341350      <Position23>
    342         <Filename Value="Analyze\UParser.pas"/>
    343         <Caret Line="670" Column="1" TopLine="652"/>
     351        <Filename Value="UProject.pas"/>
     352        <Caret Line="92" Column="1" TopLine="74"/>
    344353      </Position23>
    345354      <Position24>
    346         <Filename Value="Produce\UProducerPascal.pas"/>
    347         <Caret Line="88" Column="25" TopLine="84"/>
     355        <Filename Value="UProject.pas"/>
     356        <Caret Line="93" Column="1" TopLine="74"/>
    348357      </Position24>
    349358      <Position25>
    350         <Filename Value="Produce\UProducerPascal.pas"/>
    351         <Caret Line="86" Column="23" TopLine="74"/>
     359        <Filename Value="UProject.pas"/>
     360        <Caret Line="86" Column="1" TopLine="74"/>
    352361      </Position25>
    353362      <Position26>
    354         <Filename Value="USourceCode.pas"/>
    355         <Caret Line="274" Column="25" TopLine="261"/>
     363        <Filename Value="UProject.pas"/>
     364        <Caret Line="99" Column="1" TopLine="78"/>
    356365      </Position26>
    357366      <Position27>
    358         <Filename Value="Produce\UProducerPascal.pas"/>
    359         <Caret Line="86" Column="23" TopLine="74"/>
     367        <Filename Value="UProject.pas"/>
     368        <Caret Line="86" Column="1" TopLine="78"/>
    360369      </Position27>
    361370      <Position28>
    362         <Filename Value="Produce\UProducerPascal.pas"/>
    363         <Caret Line="89" Column="10" TopLine="74"/>
     371        <Filename Value="UProject.pas"/>
     372        <Caret Line="99" Column="1" TopLine="78"/>
    364373      </Position28>
    365374      <Position29>
    366         <Filename Value="Produce\UProducerPascal.pas"/>
    367         <Caret Line="92" Column="8" TopLine="74"/>
     375        <Filename Value="Forms\UMainForm.pas"/>
     376        <Caret Line="123" Column="1" TopLine="110"/>
    368377      </Position29>
    369378      <Position30>
    370         <Filename Value="Produce\UProducerPascal.pas"/>
    371         <Caret Line="88" Column="23" TopLine="74"/>
     379        <Filename Value="Forms\UMainForm.pas"/>
     380        <Caret Line="124" Column="1" TopLine="110"/>
    372381      </Position30>
    373382    </JumpHistory>
  • branches/DelphiToC/UCompiler.pas

    r54 r55  
    1515    Text: string;
    1616    Position: TPoint;
     17    FileName: string;
    1718  end;
    1819
     
    2223  private
    2324    FOnErrorMessage: TOnErrorMessage;
     25    FFileName: string;
    2426    procedure ErrorMessage(Text: string; Position: TPoint);
    2527  public
     
    3032    constructor Create;
    3133    procedure Init;
    32     procedure Compile(Source: TStringList; ProducedCode: TStringList);
     34    procedure Compile(ModuleName: string; Source: TStringList; ProducedCode: TStringList);
    3335    destructor Destroy; override;
    34     property OnErrorMessage: TOnErrorMessage read FOnErrorMessage write FOnErrorMessage;
     36    property OnErrorMessage: TOnErrorMessage read FOnErrorMessage
     37      write FOnErrorMessage;
    3538  end;
    3639
     
    3942{ TCompiler }
    4043
    41 procedure TCompiler.Compile(Source: TStringList; ProducedCode: TStringList);
     44procedure TCompiler.Compile(ModuleName: string; Source: TStringList; ProducedCode: TStringList);
    4245var
    4346  NewModule: TModule;
    4447begin
     48  FFileName := ModuleName;
    4549  Parser.SourceCodeText := Source;
    4650  Parser.Init;
    47   NewModule := TModule.Create;
    48   ProgramCode.Modules.Add(NewModule);
    49   Parser.ParseModule(NewModule);
     51  ProgramCode.Modules.Add(Parser.ParseModule);
    5052  Producer.Produce(NewModule, ProducedCode);
    5153end;
     
    8183  NewMessage.Text := Text;
    8284  NewMessage.Position := Position;
     85  NewMessage.FileName := FFileName;
    8386  ErrorMessages.Add(NewMessage);
    8487  if Assigned(FOnErrorMessage) then FOnErrorMessage(Text, Position);
  • branches/DelphiToC/UProject.pas

    r54 r55  
    66
    77uses
    8   Classes, SysUtils, Contnrs;
     8  Classes, SysUtils, Contnrs, Dialogs;
    99
    1010type
     
    1313
    1414  TProjectNode = class
     15    Parent: TProjectNode;
    1516    Name: string;
    1617    procedure Load; virtual;
    1718    procedure Save; virtual;
     19    function GetDir(IncludeRoot: Boolean = False): string; virtual;
     20  end;
     21
     22  { TProjectFile }
     23
     24  TProjectFile = class(TProjectNode)
     25    Source: TStringList;
     26    ProducedCode: TStringList;
     27    constructor Create;
     28    destructor Destroy; override;
     29    procedure Load; override;
     30    procedure Save; override;
    1831  end;
    1932
     
    2639    procedure Load; override;
    2740    procedure Save; override;
    28   end;
    29 
    30   { TProjectFile }
    31 
    32   TProjectFile = class(TProjectNode)
    33     Source: TStringList;
    34     ProducedCode: TStringList;
    35     FileName: string;
    36     constructor Create;
    37     destructor Destroy; override;
    38     procedure Load; override;
    39     procedure Save; override;
     41    function SearchFile(FileName: string): TProjectFile;
    4042  end;
    4143
    4244  TProject = class(TProjectGroup)
     45    RootDir: string;
     46    function GetDir(IncludeRoot: Boolean = False): string; override;
    4347  end;
    4448
     
    7680end;
    7781
     82function TProjectGroup.SearchFile(FileName: string): TProjectFile;
     83var
     84  NamePart: string;
     85  I: Integer;
     86begin
     87  if Pos('/', FileName) > 0 then
     88    NamePart := Copy(FileName, 1, Pos('/', FileName))
     89    else NamePart := FileName;
     90  I := 0;
     91  while (I < Items.Count) and (TProjectNode(Items[I]).Name <> NamePart) do Inc(I);
     92  if I < Items.Count then begin
     93    if TProjectNode(Items[I]) is TProjectFile then Result := TProjectFile(Items[I])
     94    else begin
     95      Delete(FileName, 1, Length(FileName) + 1);
     96      TProjectGroup(Items[I]).SearchFile(FileName);
     97    end;
     98  end else Result := nil;
     99end;
     100
    78101{ TProjectFile }
    79102
     
    94117begin
    95118  inherited Load;
    96   Source.LoadFromFile(FileName);
     119  Source.LoadFromFile(Parent.GetDir(True) + Name);
    97120end;
    98121
     
    100123begin
    101124  inherited Save;
    102   Source.SaveToFile(FileName);
     125  Source.SaveToFile(Parent.GetDir(True) + Name);
    103126end;
    104127
     
    115138end;
    116139
     140function TProjectNode.GetDir(IncludeRoot: Boolean = False): string;
     141begin
     142  if Assigned(Parent) then Result := Parent.GetDir(IncludeRoot) + Name + '/'
     143  else Result := Name + '/';
     144end;
     145
     146{ TProject }
     147
     148function TProject.GetDir(IncludeRoot: Boolean): string;
     149begin
     150  if IncludeRoot then Result := RootDir else Result := '';
     151end;
     152
    117153end.
    118154
  • branches/DelphiToC/USourceCode.pas

    r54 r55  
    270270  end;
    271271
    272   TModule = class(TCommonBlock)
     272  TModule = class
    273273  public
    274     ModuleType: TModuleType;
     274    Name: string;
     275    constructor Create;
     276    destructor Destroy; override;
     277  end;
     278
     279  { TModuleProgram }
     280
     281  TModuleProgram = class(TModule)
    275282    UsedModules: TUsedModuleList;
    276     constructor Create; override;
    277     procedure Clear;
    278     destructor Destroy; override;
     283    Body: TCommonBlock;
     284    constructor Create;
     285    destructor Destroy; override;
     286  end;
     287
     288  { TUnitInterface }
     289
     290  TUnitInterface = class
     291    UsedModules: TUsedModuleList;
     292    Body: TCommonBlock;
     293    constructor Create;
     294    destructor Destroy; override;
     295  end;
     296
     297  { TUnitImplementation }
     298
     299  TUnitImplementation = class
     300    UsedModules: TUsedModuleList;
     301    Body: TCommonBlock;
     302    constructor Create;
     303    destructor Destroy; override;
     304  end;
     305
     306  { TModuleUnit }
     307
     308  TModuleUnit = class(TModule)
     309    InterfaceSection: TUnitInterface;
     310    ImplementationSection: TUnitImplementation;
     311    constructor Create;
     312    destructor Destroy; override;
     313  end;
     314
     315  TModulePackage = class(TModule)
     316
     317  end;
     318
     319  TModuleLibrary = class(TModule)
    279320  end;
    280321
     
    362403{ TModule }
    363404
    364 procedure TModule.Clear;
    365 begin
    366   Variables.Clear;
    367   Constants.Clear;
    368   Functions.Clear;
    369   Code.Clear;
    370 end;
    371 
    372405constructor TModule.Create;
    373406begin
    374407  inherited;
    375   UsedModules := TUsedModuleList.Create;
    376408end;
    377409
    378410destructor TModule.Destroy;
    379411begin
    380   UsedModules.Destroy;
    381412  inherited;
    382413end;
     
    694725end;
    695726
     727{ TModuleProgram }
     728
     729constructor TModuleProgram.Create;
     730begin
     731  inherited;
     732  UsedModules := TUsedModuleList.Create;
     733  Body := TCommonBlock.Create;
     734end;
     735
     736destructor TModuleProgram.Destroy;
     737begin
     738  UsedModules.Free;
     739  Body.Free;
     740  inherited Destroy;
     741end;
     742
     743{ TModuleUnit }
     744
     745constructor TModuleUnit.Create;
     746begin
     747  ImplementationSection := TUnitImplementation.Create;
     748  InterfaceSection := TUnitInterface.Create;
     749end;
     750
     751destructor TModuleUnit.Destroy;
     752begin
     753  ImplementationSection.Free;
     754  InterfaceSection.Free;
     755  inherited Destroy;
     756end;
     757
     758{ TUnitImplementation }
     759
     760constructor TUnitImplementation.Create;
     761begin
     762  UsedModules := TUsedModuleList.Create;
     763  Body := TCommonBlock.Create;
     764end;
     765
     766destructor TUnitImplementation.Destroy;
     767begin
     768  UsedModules.Free;
     769  Body.Free;
     770  inherited Destroy;
     771end;
     772
     773{ TUnitInterface }
     774
     775constructor TUnitInterface.Create;
     776begin
     777  UsedModules := TUsedModuleList.Create;
     778  Body := TCommonBlock.Create;
     779end;
     780
     781destructor TUnitInterface.Destroy;
     782begin
     783  UsedModules.Free;
     784  Body.Free;
     785  inherited Destroy;
     786end;
     787
    696788end.
    697789
Note: See TracChangeset for help on using the changeset viewer.