| 1 | unit Core;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, FileUtil, LastOpenedList, Project, ApplicationInfo,
|
|---|
| 7 | Compiler, Registry, RegistryEx, DebugLog, Translator, Target,
|
|---|
| 8 | SourceCodePascal, ModularSystem;
|
|---|
| 9 |
|
|---|
| 10 | type
|
|---|
| 11 | { TCustomCompiler }
|
|---|
| 12 |
|
|---|
| 13 | TCustomCompiler = class(TCompiler)
|
|---|
| 14 | private
|
|---|
| 15 | procedure InitSystemModule;
|
|---|
| 16 | public
|
|---|
| 17 | StartTime: TDateTime;
|
|---|
| 18 | SourceFiles: TSourceFileManager;
|
|---|
| 19 | TargetFiles: TSourceFileManager;
|
|---|
| 20 | procedure Init; override;
|
|---|
| 21 | function ElapsedTime: TDateTime;
|
|---|
| 22 | procedure LoadFromRegistry(Root: HKEY; const Key: string);
|
|---|
| 23 | procedure SaveToRegistry(Root: HKEY; const Key: string);
|
|---|
| 24 | constructor Create; override;
|
|---|
| 25 | destructor Destroy; override;
|
|---|
| 26 | end;
|
|---|
| 27 |
|
|---|
| 28 | { TCore }
|
|---|
| 29 |
|
|---|
| 30 | TCore = class(TDataModule)
|
|---|
| 31 | ApplicationInfo: TApplicationInfo;
|
|---|
| 32 | Translator1: TTranslator;
|
|---|
| 33 | DebugLog1: TDebugLog;
|
|---|
| 34 | LastOpenedFiles: TLastOpenedList;
|
|---|
| 35 | ModuleManager1: TModuleManager;
|
|---|
| 36 | procedure DataModuleCreate(Sender: TObject);
|
|---|
| 37 | procedure DataModuleDestroy(Sender: TObject);
|
|---|
| 38 | procedure LastOpenedFilesChange(Sender: TObject);
|
|---|
| 39 | private
|
|---|
| 40 | procedure ProjectChange(Sender: TObject);
|
|---|
| 41 | function LoadSourceFile(FileName: string; var Content: string): Boolean;
|
|---|
| 42 | function SaveSourceFile(FileName: string; const Content: string): Boolean;
|
|---|
| 43 | public
|
|---|
| 44 | ReopenLastOpenedFile: Boolean;
|
|---|
| 45 | LogParsing: Boolean;
|
|---|
| 46 | Project: TProject;
|
|---|
| 47 | ProjectTemplates: TProjectTemplates;
|
|---|
| 48 | TargetProject: TProject;
|
|---|
| 49 | Compiler: TCustomCompiler;
|
|---|
| 50 | ModuleManager: TModuleManager;
|
|---|
| 51 | procedure ProjectTemplatesInit;
|
|---|
| 52 | procedure ProjectOpen(FileName: string);
|
|---|
| 53 | procedure ProjectNew;
|
|---|
| 54 | procedure CompilerDebugLog(Text: string);
|
|---|
| 55 | procedure LoadFromRegistry(Root: HKEY; const Key: string);
|
|---|
| 56 | procedure SaveToRegistry(Root: HKEY; const Key: string);
|
|---|
| 57 | procedure RegisterIDEModules;
|
|---|
| 58 | procedure RegisterCompilerModules;
|
|---|
| 59 | end;
|
|---|
| 60 |
|
|---|
| 61 | var
|
|---|
| 62 | Core: TCore;
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 | implementation
|
|---|
| 66 |
|
|---|
| 67 | {$R *.lfm}
|
|---|
| 68 |
|
|---|
| 69 | uses
|
|---|
| 70 | FormMain, ProjectTemplates, IDEModulePascal, ModulePascal, ModuleGCC,
|
|---|
| 71 | ModuleInterpretter, ModuleDelphi, ModulePHP, ModuleJava, ModuleASM8051,
|
|---|
| 72 | ModuleXML, ModuleNASM;
|
|---|
| 73 |
|
|---|
| 74 | { TCore }
|
|---|
| 75 |
|
|---|
| 76 | procedure TCore.ProjectOpen(FileName: string);
|
|---|
| 77 | begin
|
|---|
| 78 | ProjectNew;
|
|---|
| 79 | Project.LoadFromFile(FileName);
|
|---|
| 80 | LastOpenedFiles.AddItem(FileName);
|
|---|
| 81 | FormMain.FormMain.UpdateInterface;
|
|---|
| 82 | end;
|
|---|
| 83 |
|
|---|
| 84 | procedure TCore.ProjectNew;
|
|---|
| 85 | begin
|
|---|
| 86 | if Assigned(Project) then FreeAndNil(Project);
|
|---|
| 87 | Project := TProject.Create;
|
|---|
| 88 | Project.FileName := SNewProject;
|
|---|
| 89 | Project.OnChange := ProjectChange;
|
|---|
| 90 | end;
|
|---|
| 91 |
|
|---|
| 92 | procedure TCore.CompilerDebugLog(Text: string);
|
|---|
| 93 | begin
|
|---|
| 94 | DebugLog1.Add('', Text);
|
|---|
| 95 | end;
|
|---|
| 96 |
|
|---|
| 97 | procedure TCore.DataModuleCreate(Sender: TObject);
|
|---|
| 98 | begin
|
|---|
| 99 | DeleteFile(DebugLog1.FileName);
|
|---|
| 100 | Compiler := TCustomCompiler.Create;
|
|---|
| 101 | //Compiler.OnLoadSource := LoadSourceFile;
|
|---|
| 102 | //Compiler.OnSaveTarget := SaveSourceFile;
|
|---|
| 103 | Project := TProject.Create;
|
|---|
| 104 | ProjectTemplates := TProjectTemplates.Create;
|
|---|
| 105 | TargetProject := TProject.Create;
|
|---|
| 106 | LastOpenedFiles := TLastOpenedList.Create(nil);
|
|---|
| 107 | LastOpenedFiles.OnChange := LastOpenedFilesChange;
|
|---|
| 108 |
|
|---|
| 109 | ReopenLastOpenedFile := True;
|
|---|
| 110 | LogParsing := False;
|
|---|
| 111 |
|
|---|
| 112 | ModuleManager := TModuleManager.Create(nil);
|
|---|
| 113 | RegisterIDEModules;
|
|---|
| 114 |
|
|---|
| 115 | RegisterCompilerModules;
|
|---|
| 116 | end;
|
|---|
| 117 |
|
|---|
| 118 | procedure TCore.DataModuleDestroy(Sender: TObject);
|
|---|
| 119 | begin
|
|---|
| 120 | FreeAndNil(ModuleManager);
|
|---|
| 121 | FreeAndNil(ProjectTemplates);
|
|---|
| 122 | FreeAndNil(LastOpenedFiles);
|
|---|
| 123 | FreeAndNil(TargetProject);
|
|---|
| 124 | FreeAndNil(Project);
|
|---|
| 125 | FreeAndNil(Compiler);
|
|---|
| 126 | end;
|
|---|
| 127 |
|
|---|
| 128 | procedure TCore.ProjectTemplatesInit;
|
|---|
| 129 | begin
|
|---|
| 130 | ProjectTemplates.AddTemplate(TProjectTemplateConsoleApp.Create);
|
|---|
| 131 | ProjectTemplates.AddTemplate(TProjectTemplateGUIApp.Create);
|
|---|
| 132 | ProjectTemplates.AddTemplate(TProjectTemplatePackage.Create);
|
|---|
| 133 | ProjectTemplates.AddTemplate(TProjectTemplateUnit.Create);
|
|---|
| 134 | end;
|
|---|
| 135 |
|
|---|
| 136 | procedure TCore.LastOpenedFilesChange(Sender: TObject);
|
|---|
| 137 | begin
|
|---|
| 138 | LastOpenedFiles.LoadToMenuItem(FormMain.FormMain.MenuItemOpenRecent,
|
|---|
| 139 | FormMain.FormMain.OpenRecentClick);
|
|---|
| 140 | LastOpenedFiles.LoadToMenuItem(FormMain.FormMain.PopupMenu1.Items,
|
|---|
| 141 | FormMain.FormMain.OpenRecentClick);
|
|---|
| 142 | end;
|
|---|
| 143 |
|
|---|
| 144 | procedure TCore.ProjectChange(Sender: TObject);
|
|---|
| 145 | begin
|
|---|
| 146 | FormMain.FormMain.UpdateInterface;
|
|---|
| 147 | end;
|
|---|
| 148 |
|
|---|
| 149 | function TCore.LoadSourceFile(FileName: string; var Content: string): Boolean;
|
|---|
| 150 | begin
|
|---|
| 151 | end;
|
|---|
| 152 |
|
|---|
| 153 | function TCore.SaveSourceFile(FileName: string; const Content: string): Boolean;
|
|---|
| 154 | begin
|
|---|
| 155 | end;
|
|---|
| 156 |
|
|---|
| 157 | procedure TCore.LoadFromRegistry(Root: HKEY; const Key: string);
|
|---|
| 158 | begin
|
|---|
| 159 | with TRegistryEx.Create do
|
|---|
| 160 | try
|
|---|
| 161 | RootKey := Root;
|
|---|
| 162 | OpenKey(Key, True);
|
|---|
| 163 | if ValueExists('ReopenLastOpenedFile') then
|
|---|
| 164 | ReopenLastOpenedFile := ReadBool('ReopenLastOpenedFile')
|
|---|
| 165 | else ReopenLastOpenedFile := True;
|
|---|
| 166 | if ValueExists('TargetName') then
|
|---|
| 167 | Compiler.Target := Compiler.Targets.SearchBySysName(ReadString('TargetName'))
|
|---|
| 168 | else Compiler.Target := nil;
|
|---|
| 169 | if ValueExists('LogParsing') then
|
|---|
| 170 | LogParsing := ReadBool('LogParsing')
|
|---|
| 171 | else LogParsing := False;
|
|---|
| 172 | if ValueExists('LanguageCode') then
|
|---|
| 173 | Translator1.Language := Translator1.Languages.SearchByCode(ReadString('LanguageCode'))
|
|---|
| 174 | else Translator1.Language := Translator1.Languages.SearchByCode('');
|
|---|
| 175 | finally
|
|---|
| 176 | Free;
|
|---|
| 177 | end;
|
|---|
| 178 | LastOpenedFiles.LoadFromRegistry(TRegistryContext.Create(Root, Key + '\LastOpenedFiles')); //Root, Key + '\LastOpenedFiles');
|
|---|
| 179 | Compiler.LoadFromRegistry(Root, Key + '\Compiler');
|
|---|
| 180 | FormMain.FormMain.LoadFromRegistry(Root, Key);
|
|---|
| 181 | end;
|
|---|
| 182 |
|
|---|
| 183 | procedure TCore.SaveToRegistry(Root: HKEY; const Key: string);
|
|---|
| 184 | begin
|
|---|
| 185 | with TRegistryEx.Create do
|
|---|
| 186 | try
|
|---|
| 187 | RootKey := Root;
|
|---|
| 188 | OpenKey(Key, True);
|
|---|
| 189 | WriteBool('ReopenLastOpenedFile', ReopenLastOpenedFile);
|
|---|
| 190 | if Assigned(Compiler.Target) then
|
|---|
| 191 | WriteString('TargetName', Compiler.Target.SysName)
|
|---|
| 192 | else WriteString('TargetName', '');
|
|---|
| 193 | WriteBool('LogParsing', LogParsing);
|
|---|
| 194 | if Assigned(Translator1.Language) and (Translator1.Language.Code <> '') then
|
|---|
| 195 | WriteString('LanguageCode', Translator1.Language.Code)
|
|---|
| 196 | else WriteString('LanguageCode', '');
|
|---|
| 197 | finally
|
|---|
| 198 | Free;
|
|---|
| 199 | end;
|
|---|
| 200 | LastOpenedFiles.SaveToRegistry(TRegistryContext.Create(Root, Key + '\LastOpenedFiles'));
|
|---|
| 201 | Compiler.SaveToRegistry(Root, Key + '\Compiler');
|
|---|
| 202 | FormMain.FormMain.SaveToRegistry(Root, Key);
|
|---|
| 203 | end;
|
|---|
| 204 |
|
|---|
| 205 | procedure TCore.RegisterIDEModules;
|
|---|
| 206 | begin
|
|---|
| 207 | ModuleManager.RegisterModule(TIDEModulePascal.Create(nil));
|
|---|
| 208 | end;
|
|---|
| 209 |
|
|---|
| 210 | procedure TCore.RegisterCompilerModules;
|
|---|
| 211 | begin
|
|---|
| 212 | with Compiler.ModuleManager do begin
|
|---|
| 213 | RegisterModule(TModulePascal.Create(nil));
|
|---|
| 214 | RegisterModule(TModuleGCC.Create(nil));
|
|---|
| 215 | RegisterModule(TModuleInterpretter.Create(nil));
|
|---|
| 216 | RegisterModule(TModuleDelphi.Create(nil));
|
|---|
| 217 | RegisterModule(TModulePHP.Create(nil));
|
|---|
| 218 | RegisterModule(TModuleJava.Create(nil));
|
|---|
| 219 | RegisterModule(TModuleASM8051.Create(nil));
|
|---|
| 220 | RegisterModule(TModuleXML.Create(nil));
|
|---|
| 221 | RegisterModule(TModuleNASM.Create(nil));
|
|---|
| 222 | Modules.Perform(maEnable);
|
|---|
| 223 | Modules.Perform(maStart);
|
|---|
| 224 | end;
|
|---|
| 225 | end;
|
|---|
| 226 |
|
|---|
| 227 | { TCustomCompiler }
|
|---|
| 228 |
|
|---|
| 229 | procedure TCustomCompiler.InitSystemModule;
|
|---|
| 230 | var
|
|---|
| 231 | SystemModule: TSourceModule;
|
|---|
| 232 | begin
|
|---|
| 233 | SystemModule := TSourceModule.Create;
|
|---|
| 234 | with SystemModule do begin
|
|---|
| 235 | Name := 'System';
|
|---|
| 236 | Internal := True;
|
|---|
| 237 | with Body.Types.AddNew do begin
|
|---|
| 238 | Name := 'Byte';
|
|---|
| 239 | Size := 1;
|
|---|
| 240 | Internal := True;
|
|---|
| 241 | end;
|
|---|
| 242 | with Body.Types.AddNew do begin
|
|---|
| 243 | Name := 'ShortInt';
|
|---|
| 244 | Size := 1;
|
|---|
| 245 | Internal := True;
|
|---|
| 246 | end;
|
|---|
| 247 | with Body.Types.AddNew do begin
|
|---|
| 248 | Name := 'Word';
|
|---|
| 249 | Size := 2;
|
|---|
| 250 | Internal := True;
|
|---|
| 251 | end;
|
|---|
| 252 | with Body.Types.AddNew do begin
|
|---|
| 253 | Name := 'SmallInt';
|
|---|
| 254 | Size := 2;
|
|---|
| 255 | Internal := True;
|
|---|
| 256 | end;
|
|---|
| 257 | with Body.Types.AddNew do begin
|
|---|
| 258 | Name := 'Cardinal';
|
|---|
| 259 | Size := 4;
|
|---|
| 260 | Internal := True;
|
|---|
| 261 | end;
|
|---|
| 262 | with Body.Types.AddNew do begin
|
|---|
| 263 | Name := 'Integer';
|
|---|
| 264 | Size := 4;
|
|---|
| 265 | Internal := True;
|
|---|
| 266 | end;
|
|---|
| 267 | with Body.Types.AddNew do begin
|
|---|
| 268 | Name := 'UInt64';
|
|---|
| 269 | Size := 8;
|
|---|
| 270 | Internal := True;
|
|---|
| 271 | end;
|
|---|
| 272 | with Body.Types.AddNew do begin
|
|---|
| 273 | Name := 'Int64';
|
|---|
| 274 | Size := 8;
|
|---|
| 275 | Internal := True;
|
|---|
| 276 | end;
|
|---|
| 277 | with Body.Functions.AddNew do begin
|
|---|
| 278 | Name := 'WriteLn';
|
|---|
| 279 | Internal := True;
|
|---|
| 280 | end;
|
|---|
| 281 | ParentProgram := AbstractCode;
|
|---|
| 282 | end;
|
|---|
| 283 | AbstractCode.Modules.Add(SystemModule);
|
|---|
| 284 | end;
|
|---|
| 285 |
|
|---|
| 286 | procedure TCustomCompiler.Init;
|
|---|
| 287 | begin
|
|---|
| 288 | inherited;
|
|---|
| 289 | StartTime := Now;
|
|---|
| 290 | InitSystemModule;
|
|---|
| 291 | end;
|
|---|
| 292 |
|
|---|
| 293 | function TCustomCompiler.ElapsedTime: TDateTime;
|
|---|
| 294 | begin
|
|---|
| 295 | Result := Now - StartTime;
|
|---|
| 296 | end;
|
|---|
| 297 |
|
|---|
| 298 | procedure TCustomCompiler.LoadFromRegistry(Root: HKEY; const Key: string);
|
|---|
| 299 | var
|
|---|
| 300 | I: Integer;
|
|---|
| 301 | begin
|
|---|
| 302 | with TRegistryEx.Create do
|
|---|
| 303 | try
|
|---|
| 304 | RootKey := Root;
|
|---|
| 305 | for I := 0 to Targets.Count - 1 do
|
|---|
| 306 | with TTarget(Targets[I]) do begin
|
|---|
| 307 | OpenKey(Key + '\Targets\' + Name, True);
|
|---|
| 308 | if ValueExists('CompilerPath') then
|
|---|
| 309 | Producer.CompilerPath := ReadString('CompilerPath');
|
|---|
| 310 | end;
|
|---|
| 311 | OpenKey(Key, True);
|
|---|
| 312 | if ValueExists('SelectedTarget') then
|
|---|
| 313 | Target := Targets.SearchBySysName(ReadString('SelectedTarget'))
|
|---|
| 314 | else Target := nil;
|
|---|
| 315 | finally
|
|---|
| 316 | Free;
|
|---|
| 317 | end;
|
|---|
| 318 | end;
|
|---|
| 319 |
|
|---|
| 320 | procedure TCustomCompiler.SaveToRegistry(Root: HKEY; const Key: string);
|
|---|
| 321 | var
|
|---|
| 322 | I: Integer;
|
|---|
| 323 | begin
|
|---|
| 324 | with TRegistryEx.Create do
|
|---|
| 325 | try
|
|---|
| 326 | RootKey := Root;
|
|---|
| 327 | for I := 0 to Targets.Count - 1 do
|
|---|
| 328 | with TTarget(Targets[I]) do begin
|
|---|
| 329 | OpenKey(Key + '\Targets\' + Name, True);
|
|---|
| 330 | if Assigned(Producer) then begin
|
|---|
| 331 | if Producer.CompilerPath <> '' then WriteString('CompilerPath', Producer.CompilerPath)
|
|---|
| 332 | else WriteString('CompilerPath', '');
|
|---|
| 333 | end;
|
|---|
| 334 | end;
|
|---|
| 335 | OpenKey(Key, True);
|
|---|
| 336 | if Assigned(Target) then WriteString('SelectedTarget', Target.SysName)
|
|---|
| 337 | else WriteString('SelectedTarget', '');
|
|---|
| 338 | finally
|
|---|
| 339 | Free;
|
|---|
| 340 | end;
|
|---|
| 341 | end;
|
|---|
| 342 |
|
|---|
| 343 | constructor TCustomCompiler.Create;
|
|---|
| 344 | begin
|
|---|
| 345 | inherited Create;
|
|---|
| 346 | SourceFiles := TSourceFileManager.Create;
|
|---|
| 347 | TargetFiles := TSourceFileManager.Create;
|
|---|
| 348 | OnLoadSource := SourceFiles.GetFileContent;
|
|---|
| 349 | OnSaveTarget := TargetFiles.SetFileContent;
|
|---|
| 350 | end;
|
|---|
| 351 |
|
|---|
| 352 | destructor TCustomCompiler.Destroy;
|
|---|
| 353 | begin
|
|---|
| 354 | FreeAndNil(TargetFiles);
|
|---|
| 355 | FreeAndNil(SourceFiles);
|
|---|
| 356 | inherited;
|
|---|
| 357 | end;
|
|---|
| 358 |
|
|---|
| 359 | end.
|
|---|
| 360 |
|
|---|