From fd1f5093305cee37ad817d62ccbbe434aab18405 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 13 Jul 2009 20:45:15 +0000 Subject: [PATCH] Skeleton for source language abstraction. There's SourceLanguage with several subclasses, though they don't do much yet. SourceCode is now associated with a SourceLanguage. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31544 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/debugger/Jamfile | 10 ++++ .../debugger/arch/x86/ArchitectureX86.cpp | 11 +++- src/apps/debugger/arch/x86/ArchitectureX86.h | 4 ++ .../debug_info/DebuggerImageDebugInfo.cpp | 8 +++ .../debug_info/DebuggerImageDebugInfo.h | 3 ++ .../debug_info/DwarfImageDebugInfo.cpp | 37 +++++++++++++ .../debugger/debug_info/DwarfImageDebugInfo.h | 3 ++ .../debug_info/SpecificImageDebugInfo.h | 4 ++ .../debugger/debug_info/TeamDebugInfo.cpp | 24 ++++++++- src/apps/debugger/dwarf/DebugInfoEntries.h | 2 + src/apps/debugger/model/DisassembledCode.cpp | 14 ++++- src/apps/debugger/model/DisassembledCode.h | 5 +- src/apps/debugger/model/FileSourceCode.cpp | 16 +++++- src/apps/debugger/model/FileSourceCode.h | 6 ++- src/apps/debugger/model/SourceCode.h | 3 ++ .../debugger/source_language/CLanguage.cpp | 24 +++++++++ src/apps/debugger/source_language/CLanguage.h | 21 ++++++++ .../source_language/CLanguageFamily.cpp | 24 +++++++++ .../source_language/CLanguageFamily.h | 21 ++++++++ .../debugger/source_language/CppLanguage.cpp | 24 +++++++++ .../debugger/source_language/CppLanguage.h | 21 ++++++++ .../source_language/SourceLanguage.cpp | 19 +++++++ .../debugger/source_language/SourceLanguage.h | 27 ++++++++++ .../source_language/SyntaxHighlighter.cpp | 31 +++++++++++ .../source_language/SyntaxHighlighter.h | 54 +++++++++++++++++++ .../source_language/UnsupportedLanguage.cpp | 14 +++++ .../source_language/UnsupportedLanguage.h | 18 +++++++ .../source_language/X86AssemblyLanguage.cpp | 32 +++++++++++ .../source_language/X86AssemblyLanguage.h | 23 ++++++++ 29 files changed, 495 insertions(+), 8 deletions(-) create mode 100644 src/apps/debugger/source_language/CLanguage.cpp create mode 100644 src/apps/debugger/source_language/CLanguage.h create mode 100644 src/apps/debugger/source_language/CLanguageFamily.cpp create mode 100644 src/apps/debugger/source_language/CLanguageFamily.h create mode 100644 src/apps/debugger/source_language/CppLanguage.cpp create mode 100644 src/apps/debugger/source_language/CppLanguage.h create mode 100644 src/apps/debugger/source_language/SourceLanguage.cpp create mode 100644 src/apps/debugger/source_language/SourceLanguage.h create mode 100644 src/apps/debugger/source_language/SyntaxHighlighter.cpp create mode 100644 src/apps/debugger/source_language/SyntaxHighlighter.h create mode 100644 src/apps/debugger/source_language/UnsupportedLanguage.cpp create mode 100644 src/apps/debugger/source_language/UnsupportedLanguage.h create mode 100644 src/apps/debugger/source_language/X86AssemblyLanguage.cpp create mode 100644 src/apps/debugger/source_language/X86AssemblyLanguage.h diff --git a/src/apps/debugger/Jamfile b/src/apps/debugger/Jamfile index 082cfd0922..72c68e71b9 100644 --- a/src/apps/debugger/Jamfile +++ b/src/apps/debugger/Jamfile @@ -14,6 +14,7 @@ SEARCH_SOURCE += [ FDirName $(SUBDIR) elf ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) files ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) gui team_window ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) model ] ; +SEARCH_SOURCE += [ FDirName $(SUBDIR) source_language ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) types ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) util ] ; @@ -107,6 +108,15 @@ Application Debugger : Thread.cpp ThreadInfo.cpp + # source_language + CLanguage.cpp + CLanguageFamily.cpp + CppLanguage.cpp + SourceLanguage.cpp + SyntaxHighlighter.cpp + UnsupportedLanguage.cpp + X86AssemblyLanguage.cpp + # types TargetAddressRangeList.cpp diff --git a/src/apps/debugger/arch/x86/ArchitectureX86.cpp b/src/apps/debugger/arch/x86/ArchitectureX86.cpp index 6785a4ad29..2d3df2be52 100644 --- a/src/apps/debugger/arch/x86/ArchitectureX86.cpp +++ b/src/apps/debugger/arch/x86/ArchitectureX86.cpp @@ -20,6 +20,7 @@ #include "StackFrame.h" #include "Statement.h" #include "TeamMemory.h" +#include "X86AssemblyLanguage.h" #include "disasm/DisassemblerX86.h" @@ -104,6 +105,7 @@ struct ArchitectureX86::FromDwarfRegisterMap : RegisterMap { ArchitectureX86::ArchitectureX86(TeamMemory* teamMemory) : Architecture(teamMemory), + fAssemblyLanguage(NULL), fToDwarfRegisterMap(NULL), fFromDwarfRegisterMap(NULL) { @@ -116,12 +118,18 @@ ArchitectureX86::~ArchitectureX86() fToDwarfRegisterMap->ReleaseReference(); if (fFromDwarfRegisterMap != NULL) fFromDwarfRegisterMap->ReleaseReference(); + if (fAssemblyLanguage != NULL) + fAssemblyLanguage->ReleaseReference(); } status_t ArchitectureX86::Init() { + fAssemblyLanguage = new(std::nothrow) X86AssemblyLanguage; + if (fAssemblyLanguage == NULL) + return B_NO_MEMORY; + try { _AddIntegerRegister(X86_REGISTER_EIP, "eip", B_UINT32_TYPE, REGISTER_TYPE_INSTRUCTION_POINTER, false); @@ -450,7 +458,8 @@ status_t ArchitectureX86::DisassembleCode(FunctionDebugInfo* function, const void* buffer, size_t bufferSize, DisassembledCode*& _sourceCode) { - DisassembledCode* source = new(std::nothrow) DisassembledCode; + DisassembledCode* source = new(std::nothrow) DisassembledCode( + fAssemblyLanguage); if (source == NULL) return B_NO_MEMORY; Reference sourceReference(source, true); diff --git a/src/apps/debugger/arch/x86/ArchitectureX86.h b/src/apps/debugger/arch/x86/ArchitectureX86.h index f55c8da486..5a85d523c3 100644 --- a/src/apps/debugger/arch/x86/ArchitectureX86.h +++ b/src/apps/debugger/arch/x86/ArchitectureX86.h @@ -11,6 +11,9 @@ #include "Register.h" +class SourceLanguage; + + class ArchitectureX86 : public Architecture { public: ArchitectureX86(TeamMemory* teamMemory); @@ -67,6 +70,7 @@ private: private: Array fRegisters; + SourceLanguage* fAssemblyLanguage; ToDwarfRegisterMap* fToDwarfRegisterMap; FromDwarfRegisterMap* fFromDwarfRegisterMap; }; diff --git a/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp b/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp index c37c228717..a494dee146 100644 --- a/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp +++ b/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp @@ -104,6 +104,14 @@ DebuggerImageDebugInfo::GetStatementAtSourceLocation( } +status_t +DebuggerImageDebugInfo::GetSourceLanguage(FunctionDebugInfo* function, + SourceLanguage*& _language) +{ + return B_UNSUPPORTED; +} + + ssize_t DebuggerImageDebugInfo::ReadCode(target_addr_t address, void* buffer, size_t size) diff --git a/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h b/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h index c8ca8e5dbc..37196661d2 100644 --- a/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h +++ b/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h @@ -39,6 +39,9 @@ public: const SourceLocation& sourceLocation, Statement*& _statement); + virtual status_t GetSourceLanguage(FunctionDebugInfo* function, + SourceLanguage*& _language); + virtual ssize_t ReadCode(target_addr_t address, void* buffer, size_t size); diff --git a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp index 203e9dddc4..cf2e3c4b62 100644 --- a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp +++ b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp @@ -17,7 +17,9 @@ #include #include "Architecture.h" +#include "CLanguage.h" #include "CompilationUnit.h" +#include "CppLanguage.h" #include "CpuState.h" #include "DebugInfoEntries.h" #include "Dwarf.h" @@ -36,6 +38,7 @@ #include "Statement.h" #include "StringUtils.h" #include "TeamMemory.h" +#include "UnsupportedLanguage.h" // #pragma mark - UnwindTargetInterface @@ -525,6 +528,40 @@ printf(" -> found statement!\n"); } +status_t +DwarfImageDebugInfo::GetSourceLanguage(FunctionDebugInfo* _function, + SourceLanguage*& _language) +{ + DwarfFunctionDebugInfo* function + = dynamic_cast(_function); + if (function == NULL) + return B_BAD_VALUE; + + SourceLanguage* language; + CompilationUnit* unit = function->GetCompilationUnit(); + switch (unit->UnitEntry()->Language()) { + case DW_LANG_C89: + case DW_LANG_C: + case DW_LANG_C99: + language = new(std::nothrow) CLanguage; + break; + case DW_LANG_C_plus_plus: + language = new(std::nothrow) CppLanguage; + break; + case 0: + default: + language = new(std::nothrow) UnsupportedLanguage; + break; + } + + if (language == NULL) + return B_NO_MEMORY; + + _language = language; + return B_OK; +} + + ssize_t DwarfImageDebugInfo::ReadCode(target_addr_t address, void* buffer, size_t size) { diff --git a/src/apps/debugger/debug_info/DwarfImageDebugInfo.h b/src/apps/debugger/debug_info/DwarfImageDebugInfo.h index f723273851..9667ff2604 100644 --- a/src/apps/debugger/debug_info/DwarfImageDebugInfo.h +++ b/src/apps/debugger/debug_info/DwarfImageDebugInfo.h @@ -53,6 +53,9 @@ public: const SourceLocation& sourceLocation, Statement*& _statement); + virtual status_t GetSourceLanguage(FunctionDebugInfo* function, + SourceLanguage*& _language); + virtual ssize_t ReadCode(target_addr_t address, void* buffer, size_t size); diff --git a/src/apps/debugger/debug_info/SpecificImageDebugInfo.h b/src/apps/debugger/debug_info/SpecificImageDebugInfo.h index 012b328ef8..04998efe9d 100644 --- a/src/apps/debugger/debug_info/SpecificImageDebugInfo.h +++ b/src/apps/debugger/debug_info/SpecificImageDebugInfo.h @@ -18,6 +18,7 @@ class FileSourceCode; class FunctionDebugInfo; class Image; class LocatableFile; +class SourceLanguage; class SourceLocation; class StackFrame; class Statement; @@ -50,6 +51,9 @@ public: Statement*& _statement) = 0; // returns reference + virtual status_t GetSourceLanguage(FunctionDebugInfo* function, + SourceLanguage*& _language) = 0; + virtual ssize_t ReadCode(target_addr_t address, void* buffer, size_t size) = 0; diff --git a/src/apps/debugger/debug_info/TeamDebugInfo.cpp b/src/apps/debugger/debug_info/TeamDebugInfo.cpp index c2de541746..1ee389c097 100644 --- a/src/apps/debugger/debug_info/TeamDebugInfo.cpp +++ b/src/apps/debugger/debug_info/TeamDebugInfo.cpp @@ -24,6 +24,7 @@ #include "ImageDebugInfo.h" #include "LocatableFile.h" #include "SourceFile.h" +#include "SourceLanguage.h" #include "SpecificImageDebugInfo.h" #include "StringUtils.h" @@ -163,6 +164,11 @@ struct TeamDebugInfo::SourceFileEntry : public HashTableLink { return fFunctions.ItemAt(index - 1); } + Function* FunctionAt(int32 index) const + { + return fFunctions.ItemAt(index); + } + private: typedef BObjectList FunctionList; @@ -378,6 +384,20 @@ TeamDebugInfo::LoadSourceCode(LocatableFile* file, FileSourceCode*& _sourceCode) return B_OK; } + // get the source language from some function's image debug info + Function* function = entry->FunctionAt(0); + if (function == NULL) + return B_ENTRY_NOT_FOUND; + + FunctionDebugInfo* functionDebugInfo + = function->FirstInstance()->GetFunctionDebugInfo(); + SourceLanguage* language; + status_t error = functionDebugInfo->GetSpecificImageDebugInfo() + ->GetSourceLanguage(functionDebugInfo, language); + if (error != B_OK) + return error; + Reference languageReference(language, true); + // no source code yet // locker.Unlock(); // TODO: It would be nice to unlock here, but we need to iterate through @@ -387,12 +407,12 @@ TeamDebugInfo::LoadSourceCode(LocatableFile* file, FileSourceCode*& _sourceCode) // load the source file SourceFile* sourceFile; - status_t error = fFileManager->LoadSourceFile(file, sourceFile); + error = fFileManager->LoadSourceFile(file, sourceFile); if (error != B_OK) return error; // create the source code - sourceCode = new(std::nothrow) FileSourceCode(file, sourceFile); + sourceCode = new(std::nothrow) FileSourceCode(file, sourceFile, language); sourceFile->ReleaseReference(); if (sourceCode == NULL) return B_NO_MEMORY; diff --git a/src/apps/debugger/dwarf/DebugInfoEntries.h b/src/apps/debugger/dwarf/DebugInfoEntries.h index f0cdf645a7..04ef0fc22a 100644 --- a/src/apps/debugger/dwarf/DebugInfoEntries.h +++ b/src/apps/debugger/dwarf/DebugInfoEntries.h @@ -146,6 +146,8 @@ public: const char* CompilationDir() const { return fCompilationDir; } + uint16 Language() const { return fLanguage; } + const DebugInfoEntryList& Types() const { return fTypes; } const DebugInfoEntryList& OtherChildren() const { return fOtherChildren; } diff --git a/src/apps/debugger/model/DisassembledCode.cpp b/src/apps/debugger/model/DisassembledCode.cpp index 599f9a43c4..9f6ebdf65a 100644 --- a/src/apps/debugger/model/DisassembledCode.cpp +++ b/src/apps/debugger/model/DisassembledCode.cpp @@ -13,6 +13,7 @@ #include +#include "SourceLanguage.h" #include "Statement.h" @@ -29,10 +30,12 @@ struct DisassembledCode::Line { }; -DisassembledCode::DisassembledCode() +DisassembledCode::DisassembledCode(SourceLanguage* language) : + fLanguage(language), fLines(20, true) { + fLanguage->AcquireReference(); } @@ -40,6 +43,8 @@ DisassembledCode::~DisassembledCode() { for (int32 i = 0; Statement* statement = fStatements.ItemAt(i); i++) statement->RemoveReference(); + + fLanguage->ReleaseReference(); } @@ -57,6 +62,13 @@ DisassembledCode::Unlock() } +SourceLanguage* +DisassembledCode::GetSourceLanguage() const +{ + return fLanguage; +} + + int32 DisassembledCode::CountLines() const { diff --git a/src/apps/debugger/model/DisassembledCode.h b/src/apps/debugger/model/DisassembledCode.h index 9afd21757e..85da92df4b 100644 --- a/src/apps/debugger/model/DisassembledCode.h +++ b/src/apps/debugger/model/DisassembledCode.h @@ -17,12 +17,14 @@ class ContiguousStatement; class DisassembledCode : public SourceCode { public: - DisassembledCode(); + DisassembledCode(SourceLanguage* language); ~DisassembledCode(); virtual bool Lock(); virtual void Unlock(); + virtual SourceLanguage* GetSourceLanguage() const; + virtual int32 CountLines() const; virtual const char* LineAt(int32 index) const; @@ -59,6 +61,7 @@ private: const ContiguousStatement* statement); private: + SourceLanguage* fLanguage; LineList fLines; StatementList fStatements; }; diff --git a/src/apps/debugger/model/FileSourceCode.cpp b/src/apps/debugger/model/FileSourceCode.cpp index 327222af7c..87732e3ac3 100644 --- a/src/apps/debugger/model/FileSourceCode.cpp +++ b/src/apps/debugger/model/FileSourceCode.cpp @@ -10,22 +10,27 @@ #include "LocatableFile.h" #include "SourceFile.h" +#include "SourceLanguage.h" #include "SourceLocation.h" -FileSourceCode::FileSourceCode(LocatableFile* file, SourceFile* sourceFile) +FileSourceCode::FileSourceCode(LocatableFile* file, SourceFile* sourceFile, + SourceLanguage* language) : fLock("source code"), fFile(file), - fSourceFile(sourceFile) + fSourceFile(sourceFile), + fLanguage(language) { fFile->AcquireReference(); fSourceFile->AcquireReference(); + fLanguage->AcquireReference(); } FileSourceCode::~FileSourceCode() { + fLanguage->ReleaseReference(); fSourceFile->ReleaseReference(); fFile->ReleaseReference(); } @@ -65,6 +70,13 @@ FileSourceCode::Unlock() } +SourceLanguage* +FileSourceCode::GetSourceLanguage() const +{ + return fLanguage; +} + + int32 FileSourceCode::CountLines() const { diff --git a/src/apps/debugger/model/FileSourceCode.h b/src/apps/debugger/model/FileSourceCode.h index 9a56ec7034..03c0d05255 100644 --- a/src/apps/debugger/model/FileSourceCode.h +++ b/src/apps/debugger/model/FileSourceCode.h @@ -20,7 +20,8 @@ class SourceFile; class FileSourceCode : public SourceCode { public: FileSourceCode(LocatableFile* file, - SourceFile* sourceFile); + SourceFile* sourceFile, + SourceLanguage* language); virtual ~FileSourceCode(); status_t Init(); @@ -30,6 +31,8 @@ public: virtual bool Lock(); virtual void Unlock(); + virtual SourceLanguage* GetSourceLanguage() const; + virtual int32 CountLines() const; virtual const char* LineAt(int32 index) const; @@ -49,6 +52,7 @@ private: BLocker fLock; LocatableFile* fFile; SourceFile* fSourceFile; + SourceLanguage* fLanguage; Array fSourceLocations; }; diff --git a/src/apps/debugger/model/SourceCode.h b/src/apps/debugger/model/SourceCode.h index 965828cc8d..aa17d2e93f 100644 --- a/src/apps/debugger/model/SourceCode.h +++ b/src/apps/debugger/model/SourceCode.h @@ -12,6 +12,7 @@ class LocatableFile; +class SourceLanguage; class SourceLocation; class Statement; @@ -25,6 +26,8 @@ public: virtual bool Lock() = 0; virtual void Unlock() = 0; + virtual SourceLanguage* GetSourceLanguage() const = 0; + virtual int32 CountLines() const = 0; virtual const char* LineAt(int32 index) const = 0; diff --git a/src/apps/debugger/source_language/CLanguage.cpp b/src/apps/debugger/source_language/CLanguage.cpp new file mode 100644 index 0000000000..0114bf4ae3 --- /dev/null +++ b/src/apps/debugger/source_language/CLanguage.cpp @@ -0,0 +1,24 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + + +#include "CLanguage.h" + + +CLanguage::CLanguage() +{ +} + + +CLanguage::~CLanguage() +{ +} + + +const char* +CLanguage::Name() const +{ + return "C"; +} diff --git a/src/apps/debugger/source_language/CLanguage.h b/src/apps/debugger/source_language/CLanguage.h new file mode 100644 index 0000000000..f0b27ed828 --- /dev/null +++ b/src/apps/debugger/source_language/CLanguage.h @@ -0,0 +1,21 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef C_LANGUAGE_H +#define C_LANGUAGE_H + + +#include "CLanguageFamily.h" + + +class CLanguage : public CLanguageFamily { +public: + CLanguage(); + virtual ~CLanguage(); + + virtual const char* Name() const; +}; + + +#endif // C_LANGUAGE_H diff --git a/src/apps/debugger/source_language/CLanguageFamily.cpp b/src/apps/debugger/source_language/CLanguageFamily.cpp new file mode 100644 index 0000000000..0eb45b2cb3 --- /dev/null +++ b/src/apps/debugger/source_language/CLanguageFamily.cpp @@ -0,0 +1,24 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include "CLanguageFamily.h" + + +CLanguageFamily::CLanguageFamily() +{ +} + + +CLanguageFamily::~CLanguageFamily() +{ +} + + +SyntaxHighlighter* +CLanguageFamily::GetSyntaxHighlighter() const +{ + // TODO:... + return NULL; +} diff --git a/src/apps/debugger/source_language/CLanguageFamily.h b/src/apps/debugger/source_language/CLanguageFamily.h new file mode 100644 index 0000000000..6703a380ca --- /dev/null +++ b/src/apps/debugger/source_language/CLanguageFamily.h @@ -0,0 +1,21 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef C_LANGUAGE_FAMILY_H +#define C_LANGUAGE_FAMILY_H + + +#include "SourceLanguage.h" + + +class CLanguageFamily : public SourceLanguage { +public: + CLanguageFamily(); + virtual ~CLanguageFamily(); + + virtual SyntaxHighlighter* GetSyntaxHighlighter() const; +}; + + +#endif // C_LANGUAGE_FAMILY_H diff --git a/src/apps/debugger/source_language/CppLanguage.cpp b/src/apps/debugger/source_language/CppLanguage.cpp new file mode 100644 index 0000000000..451a567e10 --- /dev/null +++ b/src/apps/debugger/source_language/CppLanguage.cpp @@ -0,0 +1,24 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + + +#include "CppLanguage.h" + + +CppLanguage::CppLanguage() +{ +} + + +CppLanguage::~CppLanguage() +{ +} + + +const char* +CppLanguage::Name() const +{ + return "C++"; +} diff --git a/src/apps/debugger/source_language/CppLanguage.h b/src/apps/debugger/source_language/CppLanguage.h new file mode 100644 index 0000000000..d163ed15d6 --- /dev/null +++ b/src/apps/debugger/source_language/CppLanguage.h @@ -0,0 +1,21 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef CPP_LANGUAGE_H +#define CPP_LANGUAGE_H + + +#include "CLanguageFamily.h" + + +class CppLanguage : public CLanguageFamily { +public: + CppLanguage(); + virtual ~CppLanguage(); + + virtual const char* Name() const; +}; + + +#endif // CPP_LANGUAGE_H diff --git a/src/apps/debugger/source_language/SourceLanguage.cpp b/src/apps/debugger/source_language/SourceLanguage.cpp new file mode 100644 index 0000000000..b6c04b374b --- /dev/null +++ b/src/apps/debugger/source_language/SourceLanguage.cpp @@ -0,0 +1,19 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + + +#include "SourceLanguage.h" + + +SourceLanguage::~SourceLanguage() +{ +} + + +SyntaxHighlighter* +SourceLanguage::GetSyntaxHighlighter() const +{ + return NULL; +} diff --git a/src/apps/debugger/source_language/SourceLanguage.h b/src/apps/debugger/source_language/SourceLanguage.h new file mode 100644 index 0000000000..286399e663 --- /dev/null +++ b/src/apps/debugger/source_language/SourceLanguage.h @@ -0,0 +1,27 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef SOURCE_LANGUAGE_H +#define SOURCE_LANGUAGE_H + + +#include + + +class SyntaxHighlighter; + + +class SourceLanguage : public Referenceable { +public: + virtual ~SourceLanguage(); + + virtual const char* Name() const = 0; + + virtual SyntaxHighlighter* GetSyntaxHighlighter() const; + // returns a reference, + // may return NULL, if not available +}; + + +#endif // SOURCE_LANGUAGE_H diff --git a/src/apps/debugger/source_language/SyntaxHighlighter.cpp b/src/apps/debugger/source_language/SyntaxHighlighter.cpp new file mode 100644 index 0000000000..52fbacb417 --- /dev/null +++ b/src/apps/debugger/source_language/SyntaxHighlighter.cpp @@ -0,0 +1,31 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + + +#include "SyntaxHighlighter.h" + + +// #pragma mark - SyntaxHighlightSource + + +SyntaxHighlightSource::~SyntaxHighlightSource() +{ +} + + +// #pragma mark - SyntaxHighlightInfo + + +SyntaxHighlightInfo::~SyntaxHighlightInfo() +{ +} + + +// #pragma mark - SyntaxHighlighter + + +SyntaxHighlighter::~SyntaxHighlighter() +{ +} diff --git a/src/apps/debugger/source_language/SyntaxHighlighter.h b/src/apps/debugger/source_language/SyntaxHighlighter.h new file mode 100644 index 0000000000..3f9f86ded5 --- /dev/null +++ b/src/apps/debugger/source_language/SyntaxHighlighter.h @@ -0,0 +1,54 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef SYNTAX_HIGHLIGHTER_H +#define SYNTAX_HIGHLIGHTER_H + + +#include + +#include + + +enum syntax_highlight_type { + SYNTAX_HIGHLIGHT_NONE, + SYNTAX_HIGHLIGHT_KEYWORD + // TODO:... +}; + + +class SyntaxHighlightSource : public Referenceable { + virtual ~SyntaxHighlightSource(); + + virtual int32 CountLines() const = 0; + virtual void GetLineAt(int32 index, BString& _line) const + = 0; +}; + + +class SyntaxHighlightInfo { + virtual ~SyntaxHighlightInfo(); + + virtual int32 GetLineHighlightRanges(int32 line, + int32* _columns, + syntax_highlight_type* _types, + int32 maxCount) = 0; + // Returns number of filled in + // (column, type) pairs. + // Default is (0, SYNTAX_HIGHLIGHT_NONE) + // and can be omitted. +}; + + +class SyntaxHighlighter : public Referenceable { +public: + virtual ~SyntaxHighlighter(); + + virtual status_t ParseText(SyntaxHighlightSource* source, + SyntaxHighlightInfo*& _info) = 0; + // caller owns the returned info +}; + + +#endif // SYNTAX_HIGHLIGHTER_H diff --git a/src/apps/debugger/source_language/UnsupportedLanguage.cpp b/src/apps/debugger/source_language/UnsupportedLanguage.cpp new file mode 100644 index 0000000000..61413b3804 --- /dev/null +++ b/src/apps/debugger/source_language/UnsupportedLanguage.cpp @@ -0,0 +1,14 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + + +#include "UnsupportedLanguage.h" + + +const char* +UnsupportedLanguage::Name() const +{ + return "unsupported"; +} diff --git a/src/apps/debugger/source_language/UnsupportedLanguage.h b/src/apps/debugger/source_language/UnsupportedLanguage.h new file mode 100644 index 0000000000..f18414e0df --- /dev/null +++ b/src/apps/debugger/source_language/UnsupportedLanguage.h @@ -0,0 +1,18 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef UNSUPPORTED_LANGUAGE_H +#define UNSUPPORTED_LANGUAGE_H + + +#include "SourceLanguage.h" + + +class UnsupportedLanguage : public SourceLanguage { +public: + virtual const char* Name() const; +}; + + +#endif // UNSUPPORTED_LANGUAGE_H diff --git a/src/apps/debugger/source_language/X86AssemblyLanguage.cpp b/src/apps/debugger/source_language/X86AssemblyLanguage.cpp new file mode 100644 index 0000000000..8c29032e7e --- /dev/null +++ b/src/apps/debugger/source_language/X86AssemblyLanguage.cpp @@ -0,0 +1,32 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + + +#include "X86AssemblyLanguage.h" + + +X86AssemblyLanguage::X86AssemblyLanguage() +{ +} + + +X86AssemblyLanguage::~X86AssemblyLanguage() +{ +} + + +const char* +X86AssemblyLanguage::Name() const +{ + return "x86 assembly"; +} + + +SyntaxHighlighter* +X86AssemblyLanguage::GetSyntaxHighlighter() const +{ + // none available yet + return NULL; +} diff --git a/src/apps/debugger/source_language/X86AssemblyLanguage.h b/src/apps/debugger/source_language/X86AssemblyLanguage.h new file mode 100644 index 0000000000..61ea2c72bf --- /dev/null +++ b/src/apps/debugger/source_language/X86AssemblyLanguage.h @@ -0,0 +1,23 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef X86_ASSEMBLY_LANGUAGE_H +#define X86_ASSEMBLY_LANGUAGE_H + + +#include "SourceLanguage.h" + + +class X86AssemblyLanguage : public SourceLanguage { +public: + X86AssemblyLanguage(); + virtual ~X86AssemblyLanguage(); + + virtual const char* Name() const; + + virtual SyntaxHighlighter* GetSyntaxHighlighter() const; +}; + + +#endif // X86_ASSEMBLY_LANGUAGE_H