diff options
Diffstat (limited to 'include/CompilerKit/AST.h')
| -rw-r--r-- | include/CompilerKit/AST.h | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/include/CompilerKit/AST.h b/include/CompilerKit/AST.h index 3987f13..2cefed7 100644 --- a/include/CompilerKit/AST.h +++ b/include/CompilerKit/AST.h @@ -8,15 +8,16 @@ #include <CompilerKit/CodeGenerator.h> #include <vector> +#include "CompilerKit/Detail/Config.h" -#define CK_COMPILER_FRONTEND : public ::CompilerKit::CompilerFrontendInterface +#define CK_COMPILER_FRONTEND : public ::CompilerKit::ICompilerFrontend namespace CompilerKit { inline static auto kInvalidFrontend = "(null)"; struct SyntaxLeafList; struct SyntaxLeafList; -struct CompilerKeyword; +struct SyntaxKeyword; /// =========================================================== /// /// @note we want to do that to separate keywords. @@ -59,34 +60,40 @@ enum KeywordKind { kKeywordKindGreaterEq, kKeywordKindLessEq, kKeywordKindPtr, + kKeywordKindClassStart, + kKeywordKindClassEnd, + kKeywordKindMethodStart, + kKeywordKindMethodEnd, kKeywordKindCount = kKeywordKindPtr - kKeywordKindNamespace + 1, }; /// =========================================================== /// /// \brief Compiler keyword information struct. /// =========================================================== /// -struct CompilerKeyword { - CompilerKeyword(STLString name, KeywordKind kind) : keyword_name(name), keyword_kind(kind) {} +struct SyntaxKeyword { + SyntaxKeyword(STLString name, KeywordKind kind) : fKeywordName(name), fKeywordKind(kind) {} - STLString keyword_name{""}; - KeywordKind keyword_kind{kKeywordKindInvalid}; + STLString fKeywordName{""}; + KeywordKind fKeywordKind{kKeywordKindInvalid}; }; struct SyntaxLeafList final { struct SyntaxLeaf final { - Int32 fUserType{0U}; - CompilerKeyword fUserData{"", kKeywordKindInvalid}; + Int32 fUserType{0U}; + SyntaxKeyword fUserData{"", kKeywordKindInvalid}; STLString fUserValue{""}; struct SyntaxLeaf* fNext{nullptr}; }; - std::vector<SyntaxLeaf> fLeafList; - SizeType fNumLeafs{0}; + using ArrayType = std::vector<SyntaxLeaf>; - SizeType SizeOf() { return fNumLeafs; } - std::vector<SyntaxLeaf>& Get() { return fLeafList; } - SyntaxLeaf& At(SizeType index) { return fLeafList[index]; } + ArrayType fLeafList; + SizeType fNumLeafs{0}; + + SizeType NumLeafs() { return fNumLeafs; } + ArrayType& Get() { return fLeafList; } + SyntaxLeaf& At(const SizeType& index) { return fLeafList[index]; } }; /// =========================================================== /// @@ -95,7 +102,7 @@ struct SyntaxLeafList final { /// \param needle the string we search for. /// \return if we found it or not. /// =========================================================== /// -bool find_word(STLString haystack, STLString needle) noexcept; +bool ast_find_needle(STLString haystack, STLString needle) noexcept; /// =========================================================== /// /// find a word within strict conditions and returns a range of it. @@ -103,30 +110,29 @@ bool find_word(STLString haystack, STLString needle) noexcept; /// \param needle /// \return position of needle. /// =========================================================== /// -SizeType find_word_range(STLString haystack, STLString needle) noexcept; +SizeType ast_find_needle_range(STLString haystack, STLString needle) noexcept; /// =========================================================== /// /// @brief Compiler backend, implements a frontend, such as C, C++... /// See Toolchain, for some examples. /// =========================================================== /// -class CompilerFrontendInterface { +class ICompilerFrontend { public: - explicit CompilerFrontendInterface() = default; - virtual ~CompilerFrontendInterface() = default; + explicit ICompilerFrontend() = default; + virtual ~ICompilerFrontend() = default; - NECTI_COPY_DEFAULT(CompilerFrontendInterface); + NECTI_COPY_DEFAULT(ICompilerFrontend) /// =========================================================== /// - // NOTE: cast this to your user defined ast. + /// NOTE: cast this to your user defined ast. /// =========================================================== /// - typedef VoidPtr AstType; + using AstType = VoidPtr; /// =========================================================== /// //! @brief Compile a syntax tree ouf of the text. //! Also takes the source file name for metadata. /// =========================================================== /// - - virtual CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) = 0; + virtual SyntaxLeafList::SyntaxLeaf Compile(STLString text, STLString file) = 0; /// =========================================================== /// //! @brief What language are we dealing with? |
