Changeset 38


Ignore:
Timestamp:
Feb 25, 2012, 6:04:21 PM (13 years ago)
Author:
chronos
Message:
  • Modified: Compiler now require source file list which should be composed of project files and project dependency packages files.
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Compiler/TranspascalCompiler.lpk

    r26 r38  
    11<?xml version="1.0"?>
    22<CONFIG>
    3   <Package Version="3">
     3  <Package Version="4">
    44    <PathDelim Value="\"/>
    55    <Name Value="TranspascalCompiler"/>
     6    <AddToProjectUsesSection Value="True"/>
    67    <CompilerOptions>
    7       <Version Value="9"/>
     8      <Version Value="11"/>
    89      <PathDelim Value="\"/>
    910      <SearchPaths>
     
    3839      </Item4>
    3940      <Item5>
     41        <Filename Value="Produce\UProducers.pas"/>
     42        <UnitName Value="UProducers"/>
     43      </Item5>
     44      <Item6>
    4045        <Filename Value="Produce\UProducerAsm8051.pas"/>
    4146        <UnitName Value="UProducerAsm8051"/>
    42       </Item5>
    43       <Item6>
     47      </Item6>
     48      <Item7>
    4449        <Filename Value="Produce\UProducerDynamicC.pas"/>
    4550        <UnitName Value="UProducerDynamicC"/>
    46       </Item6>
    47       <Item7>
     51      </Item7>
     52      <Item8>
    4853        <Filename Value="Produce\UProducerPascal.pas"/>
    4954        <UnitName Value="UProducerPascal"/>
    50       </Item7>
    51       <Item8>
     55      </Item8>
     56      <Item9>
     57        <Filename Value="Produce\UProducerGCCC.pas"/>
     58        <UnitName Value="UProducerGCCC"/>
     59      </Item9>
     60      <Item10>
    5261        <Filename Value="Analyze\UAnalyzer.pas"/>
    5362        <UnitName Value="UAnalyzer"/>
    54       </Item8>
    55       <Item9>
    56         <Filename Value="Analyze\UAnalyzerPascal.pas"/>
    57         <UnitName Value="UAnalyzerPascal"/>
    58       </Item9>
    59       <Item10>
    60         <Filename Value="Produce\UProducerGCCC.pas"/>
    61         <UnitName Value="UProducerGCCC"/>
    6263      </Item10>
    6364      <Item11>
     
    6667      </Item11>
    6768      <Item12>
    68         <Filename Value="Produce\UProducers.pas"/>
    69         <UnitName Value="UProducers"/>
     69        <Filename Value="Analyze\UAnalyzerPascal.pas"/>
     70        <UnitName Value="UAnalyzerPascal"/>
    7071      </Item12>
    7172    </Files>
  • trunk/Compiler/TranspascalCompiler.pas

    r12 r38  
    33 }
    44
    5 unit TranspascalCompiler; 
     5unit TranspascalCompiler;
    66
    77interface
    88
    99uses
    10     UCompiler, USourceCode, UProducerTreeView, UProducer, UProducerAsm8051,
    11   UProducerDynamicC, UProducerPascal, UAnalyzer, UAnalyzerPascal,
    12   UProducerGCCC, UAnalyzers, UProducers, LazarusPackageIntf;
     10  UCompiler, USourceCode, UProducerTreeView, UProducer, UProducers,
     11  UProducerAsm8051, UProducerDynamicC, UProducerPascal, UProducerGCCC,
     12  UAnalyzer, UAnalyzers, UAnalyzerPascal, LazarusPackageIntf;
    1313
    1414implementation
    1515
    16 procedure Register; 
     16procedure Register;
    1717begin
    18 end; 
     18end;
    1919
    2020initialization
    21   RegisterPackage('TranspascalCompiler', @Register); 
     21  RegisterPackage('TranspascalCompiler', @Register);
    2222end.
  • trunk/Compiler/UCompiler.pas

    r20 r38  
    66
    77uses
    8   SysUtils, Variants, Classes, Contnrs, UAnalyzers, UProducers,
    9   Dialogs, USourceCode, UProducer, UAnalyzer;
     8  SysUtils, Variants, Classes, Contnrs, UAnalyzers, UProducers, FileUtil,
     9  Dialogs, USourceCode, UProducer, UAnalyzer, SpecializedList;
    1010
    1111type
     
    3636    FOnErrorMessage: TErrorMessageEvent;
    3737    FProducerType: TProducerType;
     38    FProducer: TProducer;
     39    function GetSource(Name: string; var SourceCode: string): Boolean;
    3840    procedure ErrorMessage(Text: string; Position: TPoint; FileName: string);
    3941    procedure SetAnalyzer(const AValue: TAnalyzer);
     42    procedure SetProducer(AValue: TProducer);
     43    procedure AnalyzeAll;
     44    procedure ProduceAll;
    4045  public
    41     ProgramCode: TProgram;
    42     Producer: TProducer;
    43     ErrorMessages: TObjectList;
     46    AbstractCode: TProgram;
     47    ErrorMessages: TListObject;
    4448    CompiledFolder: string;
    4549    SupportedTargets: TCompilerTargetList;
     
    4852    Producers: TListProducer;
    4953    Analyzers: TListAnalyzer;
     54    SourceFiles: TListString;
    5055    constructor Create;
    5156    destructor Destroy; override;
    5257    procedure Init;
    53     procedure Compile(ModuleName: string; Source: TStringList);
     58    procedure Compile;
    5459    property OnErrorMessage: TErrorMessageEvent read FOnErrorMessage
    5560      write FOnErrorMessage;
    5661    property Analyzer: TAnalyzer read FAnalyzer write SetAnalyzer;
     62    property Producer: TProducer read FProducer write SetProducer;
    5763  end;
    5864
    5965implementation
    6066
     67resourcestring
     68  SNothingToAnalyze = 'Nothing to analyze';
     69
    6170{ TCompiler }
    6271
    63 procedure TCompiler.Compile(ModuleName: string; Source: TStringList);
    64 var
    65   NewModule: TModule;
    66   ProducedCode: TStringList;
    67   I: Integer;
    68   TargetFileName: string;
    69 begin
    70   try
    71     ProducedCode := TStringList.Create;
    72     Analyzer.FileName := ModuleName;
    73     Analyzer.SourceCode := Source.Text;
    74     Analyzer.Process;
    75     //ShowMessage(IntToHex(Integer(Addr(Analyzer.OnGetSource)), 8));
    76     Analyzer.ParseModule(ProgramCode);
    77     with ProgramCode do
    78     for I := 0 to Modules.Count - 1 do begin
    79       Producer.Produce(TModule(Modules[I]));
    80       Producer.AssignToStringList(ProducedCode);
    81       TargetFileName := TargetFolder + DirectorySeparator +
    82         CompiledFolder + DirectorySeparator + Producer.Name +
    83         DirectorySeparator + TModule(Modules[I]).TargetFile;
    84       ForceDirectories(ExtractFileDir(TargetFileName));
    85       ProducedCode.SaveToFile(TargetFileName);
    86     end;
    87   finally
    88     ProducedCode.Free;
    89   end;
     72procedure TCompiler.Compile;
     73begin
     74  AnalyzeAll;
     75  ProduceAll;
    9076end;
    9177
     
    9480  Analyzers := TListAnalyzer.Create;
    9581  Producers := TListProducer.Create;
     82  SourceFiles := TListString.Create;
    9683
    9784  RegisterAnalyzers(Self);
     
    10693  SupportedTargets.Add('Dallas', 'DS89C450', '8052');
    10794
    108   ProgramCode := TProgram.Create;
     95  AbstractCode := TProgram.Create;
    10996  Producer := nil;
    11097  Analyzer := nil;
    111   ErrorMessages := TObjectList.Create;
     98  ErrorMessages := TListObject.Create;
    11299  CompiledFolder := 'Compiled';
    113100end;
     
    116103begin
    117104  ErrorMessages.Clear;
    118   ProgramCode.Modules.Clear;
     105  AbstractCode.Modules.Clear;
    119106end;
    120107
    121108destructor TCompiler.Destroy;
    122109begin
    123   ProgramCode.Free;
     110  AbstractCode.Free;
    124111  Analyzers.Free;
    125112  Producers.Free;
    126113  ErrorMessages.Free;
    127114  SupportedTargets.Free;
     115  SourceFiles.Free;
     116end;
     117
     118function TCompiler.GetSource(Name: string; var SourceCode: string): Boolean;
     119var
     120  I: Integer;
     121  F: TFileStream;
     122begin
     123  I := 0;
     124  while (I < SourceFiles.Count) and (ExtractFileNameOnly(SourceFiles[I]) <> Name) do Inc(I);
     125  if I < SourceFiles.Count then begin
     126    if FileExistsUTF8(SourceFiles[I]) then
     127      try
     128        F := TFileStream.Create(UTF8Decode(SourceFiles[I]), fmOpenRead);
     129        SetLength(SourceCode, F.Size);
     130        if F.Size > 0 then
     131          F.Read(SourceCode[1], F.Size);
     132        Result := True;
     133      finally
     134        F.Free;
     135      end else Result := False;
     136  end else Result := False;
    128137end;
    129138
     
    144153  if FAnalyzer = AValue then exit;
    145154  FAnalyzer := AValue;
    146   if Assigned(Analyzer) then
     155  if Assigned(Analyzer) then begin
    147156    Analyzer.OnErrorMessage := ErrorMessage;
     157    Analyzer.OnGetSource := GetSource;
     158  end;
     159end;
     160
     161procedure TCompiler.SetProducer(AValue: TProducer);
     162begin
     163  if FProducer = AValue then Exit;
     164  FProducer := AValue;
     165end;
     166
     167procedure TCompiler.AnalyzeAll;
     168begin
     169  if SourceFiles.Count > 0 then begin
     170    Analyzer.FileName := SourceFiles[0];
     171    Analyzer.OnGetSource(ExtractFileNameOnly(Analyzer.FileName), Analyzer.SourceCode);
     172    Analyzer.Process;
     173    //ShowMessage(IntToHex(Integer(Addr(Analyzer.OnGetSource)), 8));
     174    Analyzer.ParseModule(AbstractCode);
     175  end else raise Exception.Create(SNothingToAnalyze);
     176end;
     177
     178procedure TCompiler.ProduceAll;
     179var
     180  NewModule: TModule;
     181  ProducedCode: TStringList;
     182  I: Integer;
     183  TargetFileName: string;
     184begin
     185  try
     186    ProducedCode := TStringList.Create;
     187    with AbstractCode do
     188    for I := 0 to Modules.Count - 1 do begin
     189      Producer.Produce(TModule(Modules[I]));
     190      Producer.AssignToStringList(ProducedCode);
     191      TargetFileName := TargetFolder + DirectorySeparator +
     192        CompiledFolder + DirectorySeparator + Producer.Name +
     193        DirectorySeparator + TModule(Modules[I]).TargetFile;
     194      ForceDirectoriesUTF8(ExtractFileDir(TargetFileName));
     195      ProducedCode.SaveToFile(TargetFileName);
     196    end;
     197  finally
     198    ProducedCode.Free;
     199  end;
    148200end;
    149201
  • trunk/IDE

    • Property svn:ignore
      •  

        old new  
        55Transpascal.exe
        66heaptrclog.trc
         7Transpascal
  • trunk/IDE/Forms/UMainForm.lfm

    r37 r38  
    55  Width = 695
    66  Caption = 'Transpascal IDE'
    7   ClientHeight = 482
     7  ClientHeight = 476
    88  ClientWidth = 695
    99  Font.Height = -11
     
    2020    Left = 0
    2121    Height = 5
    22     Top = 477
     22    Top = 471
    2323    Width = 695
    2424    Align = alBottom
     
    2727  object DockPanel: TPanel
    2828    Left = 0
    29     Height = 345
     29    Height = 339
    3030    Top = 26
    3131    Width = 490
     
    8787  object Splitter1: TSplitter
    8888    Left = 490
    89     Height = 345
     89    Height = 339
    9090    Top = 26
    9191    Width = 5
     
    9595  object PageControlRight: TPageControl
    9696    Left = 495
    97     Height = 345
     97    Height = 339
    9898    Top = 26
    9999    Width = 200
     
    113113    Left = 0
    114114    Height = 101
    115     Top = 376
     115    Top = 370
    116116    Width = 695
    117117    ActivePage = TabSheet4
     
    131131    Left = 0
    132132    Height = 5
    133     Top = 371
     133    Top = 365
    134134    Width = 695
    135135    Align = alBottom
  • trunk/IDE/Forms/UMainForm.pas

    r37 r38  
    138138    LogParsing: Boolean;
    139139    Project: TProject;
     140    TargetProject: TProject;
    140141    Compiler: TCustomCompiler;
    141142    function GetSource(Name: string; var SourceCode: string): Boolean;
     
    203204    Compiler.Producer := TProducer(Compiler.Producers[SelectedProducerIndex]);
    204205    Compiler.Analyzer := TAnalyzer(Compiler.Analyzers[SelectedAnalyzerIndex]);
    205     Compiler.Analyzer.OnGetSource := GetSource;
    206206    Compiler.Init;
    207207
     
    212212    if Project.Items.Count > 0 then
    213213    with TProjectFile(Project.Items[0]) do begin
     214      Compiler.SourceFiles.Clear;
     215      Project.DumpFileList(Compiler.SourceFiles);
    214216      Compiler.TargetFolder := Project.RootDir;
    215       Compiler.Compile(Parent.GetDir + ExtractFileNameOnly(Name), Source);
     217      Compiler.Compile;
    216218    end;
    217219    ProjectManager.TreeViewProjectChange(Self, ProjectManager.TreeViewProject.Selected);
     
    453455  Compiler := TCustomCompiler.Create;
    454456  Project := TProject.Create;
     457  TargetProject := TProject.Create;
    455458  LastOpenedFiles := TLastOpenedList.Create;
    456459  LastOpenedFiles.MenuItem := MenuItemOpenRecent;
     
    461464begin
    462465  LastOpenedFiles.Free;
     466  TargetProject.Free;
    463467  Project.Free;
    464468  Compiler.Free;
  • trunk/IDE/Forms/UProjectManager.pas

    r37 r38  
    2929
    3030uses
    31   UMainForm, UCodeForm, UCompiledForm, UCodeTreeForm, UProducerTreeView;
     31  UMainForm, UCodeForm, UCompiledForm, UCodeTreeForm;
    3232
    3333{ TProjectManager }
  • trunk/IDE/Transpascal.lpi

    r37 r38  
    8989      <Item3>
    9090        <PackageName Value="LCLBase"/>
    91         <MinVersion Major="1" Valid="True" Release="1"/>
     91        <MinVersion Major="1" Release="1" Valid="True"/>
    9292      </Item3>
    9393      <Item4>
  • trunk/IDE/Transpascal.lpr

    r37 r38  
    99  Forms, Interfaces, SysUtils,
    1010  UMainForm in 'UMainForm.pas' {MainForm},
    11   UTextSource, UProject, UApplicationInfo, URegistry, ULastOpenedList,
    12   UDebugLog, TranspascalCompiler, UProjectManager, UCodeForm, UMessagesForm,
     11  UTextSource, UProject, UApplicationInfo, TranspascalCompiler, UProjectManager, UCodeForm, UMessagesForm,
    1312  UCompiledForm, UCodeTreeForm, TemplateGenerics, Common, CoolTranslator,
    1413  UAboutForm, UFormOptions, UCompilersForm, UCompilerSettingsForm;
  • trunk/IDE/UApplicationInfo.pas

    r37 r38  
    5555  Name := 'Transpascal IDE';
    5656  Identification := 1;
    57   ReleaseDate := EncodeDate(2012, 2, 14);
     57  ReleaseDate := EncodeDate(2012, 2, 25);
    5858  MajorVersion := 0;
    5959  MinorVersion := 1;
  • trunk/IDE/UProject.pas

    r37 r38  
    5353  TProjectGroup = class(TProjectNode)
    5454    Items: TListProjectNode;
     55    procedure DumpFileList(Files: TListString);
    5556    constructor Create;
    5657    destructor Destroy; override;
     
    8889{ TProjectGroup }
    8990
     91procedure TProjectGroup.DumpFileList(Files: TListString);
     92var
     93  I: Integer;
     94begin
     95  for I := 0 to Items.Count - 1 do
     96  if TProjectNode(Items[I]) is TProjectGroup then
     97    TProjectGroup(Items[I]).DumpFileList(Files)
     98    else Files.Add(GetDir(True) + TProjectFile(Items[I]).Name);
     99end;
     100
    90101constructor TProjectGroup.Create;
    91102begin
     
    230241function TProjectNode.GetDir(IncludeRoot: Boolean = False): string;
    231242begin
    232   if Assigned(Parent) then Result := Parent.GetDir(IncludeRoot) + Name + '/'
    233   else Result := Name + '/';
     243  if Assigned(Parent) then Result := Parent.GetDir(IncludeRoot) + Name + DirectorySeparator
     244  else Result := Name + DirectorySeparator;
    234245end;
    235246
Note: See TracChangeset for help on using the changeset viewer.