Changeset 49 for trunk/Compiler/UCompiler.pas
- Timestamp:
- Mar 4, 2012, 5:26:20 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Compiler/UCompiler.pas
r47 r49 21 21 private 22 22 FAnalyzer: TAnalyzer; 23 FTarget: TTarget; 23 24 FOnErrorMessage: TErrorMessageEvent; 24 25 function GetSource(Name: string; var SourceCode: string): Boolean; 26 function WriteTarget(Name: string; TargetCode: string): Boolean; 25 27 procedure ErrorMessage(Text: string; Position: TPoint; FileName: string); 26 28 procedure SetAnalyzer(const AValue: TAnalyzer); 27 29 procedure AnalyzeAll; 28 30 procedure ProduceAll; 31 procedure SetTarget(AValue: TTarget); 29 32 public 30 33 AbstractCode: TProgram; 31 34 ErrorMessages: TListObject; 32 35 CompiledFolder: string; 33 Target: TTarget; 36 34 37 TargetFolder: string; 35 38 Targets: TListTarget; … … 43 46 write FOnErrorMessage; 44 47 property Analyzer: TAnalyzer read FAnalyzer write SetAnalyzer; 48 property Target: TTarget read FTarget write SetTarget; 45 49 end; 46 50 … … 53 57 resourcestring 54 58 SNothingToAnalyze = 'Nothing to analyze'; 59 SRewritingExistedTarget = 'Reqriting existing target file %s'; 55 60 56 61 { TCompiler } … … 113 118 end; 114 119 120 function TCompiler.WriteTarget(Name: string; TargetCode: string): Boolean; 121 var 122 I: Integer; 123 F: TFileStream; 124 begin 125 I := 0; 126 while (I < TargetFiles.Count) and (ExtractFileNameOnly(TargetFiles[I]) <> Name) do Inc(I); 127 if I >= TargetFiles.Count then begin 128 try 129 ForceDirectoriesUTF8(ExtractFileDir(Name)); 130 if FileExistsUTF8(Name) then 131 F := TFileStream.Create(UTF8Decode(Name), fmOpenWrite) 132 else F := TFileStream.Create(UTF8Decode(Name), fmCreate); 133 F.Size := 0; 134 if Length(TargetCode) > 0 then 135 F.Write(TargetCode[1], Length(TargetCode)); 136 Result := True; 137 TargetFiles.Add(Name); 138 finally 139 F.Free; 140 end; 141 end else begin 142 Result := False; 143 ErrorMessage(Format(SRewritingExistedTarget, [Name]), Point(0, 0), ''); 144 end; 145 end; 146 115 147 procedure TCompiler.ErrorMessage(Text: string; Position: TPoint; FileName: string); 116 148 var … … 160 192 Target.Producer.Produce(TModule(Modules[I])); 161 193 Target.Producer.AssignToStringList(ProducedCode); 162 TargetFileName := TargetFolder + DirectorySeparator + 163 CompiledFolder + DirectorySeparator + Target.Name + 164 DirectorySeparator + TModule(Modules[I]).TargetFile; 165 ForceDirectoriesUTF8(ExtractFileDir(TargetFileName)); 166 ProducedCode.SaveToFile(TargetFileName); 194 TargetFileName := TargetFolder + DirectorySeparator + TModule(Modules[I]).TargetFile; 195 if Assigned(Target.Producer.OnWriteTarget) then 196 Target.Producer.OnWriteTarget(TargetFileName, ProducedCode.Text); 167 197 end; 168 198 finally … … 171 201 end; 172 202 203 procedure TCompiler.SetTarget(AValue: TTarget); 204 begin 205 if FTarget = AValue then Exit; 206 FTarget := AValue; 207 FTarget.Producer.OnWriteTarget := WriteTarget; 208 end; 209 173 210 end.
Note:
See TracChangeset
for help on using the changeset viewer.