Skip to content

Commit

Permalink
use smart pointer in node struct, start with parser
Browse files Browse the repository at this point in the history
  • Loading branch information
marcj committed May 27, 2022
1 parent 171766d commit 66dacb3
Show file tree
Hide file tree
Showing 9 changed files with 1,690 additions and 1,464 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ add_definitions(-DTRACY_ENABLE)
add_subdirectory(tests)

#add_library(typescript parser.cpp scanner.cpp utf.cpp syntax_cursor.cpp syntax_cursor.h ast.h parser2.h)
add_library(typescript scanner.cpp utf.cpp syntax_cursor.cpp syntax_cursor.h ast.h parser2.h types.cpp factory.h node_test.h)
add_library(typescript scanner.cpp utf.cpp syntax_cursor.cpp syntax_cursor.h ast.h parser2.h types.cpp factory.h node_test.h path.h)
#add_library(typescript scanner.cpp utf.cpp syntax_cursor.cpp syntax_cursor.h ast.h)
27 changes: 27 additions & 0 deletions src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,33 @@
namespace ts {
using namespace std;

unsigned constexpr const_hash(char const *input) {
return *input ?
static_cast<unsigned int>(*input) + 33 * const_hash(input + 1) :
5381;
}

unsigned constexpr const_hash(const string &input) {
return const_hash(input.c_str());
}

constexpr unsigned operator "" _hash(const char *s, size_t) {
return const_hash(s);
}

/**
* shared_ptr has optional semantic already built-in, so we use it instead of std::optional,
* but instead of using shared_ptr directly, we use opt<T> to make it clear that it can be empty.
*/
template<typename T>
using sharedOpt = shared_ptr<T>;

/**
* Because shared_ptr<T> is ugly.
*/
template<typename T>
using shared = shared_ptr<T>;

//
// template<class T>
// using Optional = optional<reference_wrapper<const T>>;
Expand Down
Loading

0 comments on commit 66dacb3

Please sign in to comment.