From 69ede706f06dae8e4c0a3eae885d354bd77f9cbd Mon Sep 17 00:00:00 2001 From: yhirose Date: Mon, 30 Nov 2015 17:26:06 -0500 Subject: [PATCH] Fixed build errors. Switched to CMake build system completely. --- CMakeLists.txt | 26 +++++--------------------- example/CMakeLists.txt | 12 ++++++++++++ example/Makefile | 21 --------------------- language/culebra/culebra.h | 8 ++++---- language/culebra/main.cc | 23 +++++++++++------------ lint/CMakeLists.txt | 5 +++++ lint/Makefile | 15 --------------- peglib.h | 14 ++++++-------- test/CMakeLists.txt | 6 ++++++ test/Makefile | 16 ---------------- 10 files changed, 49 insertions(+), 97 deletions(-) create mode 100644 example/CMakeLists.txt delete mode 100644 example/Makefile create mode 100644 lint/CMakeLists.txt delete mode 100644 lint/Makefile create mode 100644 test/CMakeLists.txt delete mode 100644 test/Makefile diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d0ae5a..463aae9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,24 +1,8 @@ cmake_minimum_required(VERSION 3.0) -include_directories(.) add_definitions("-std=c++1y") -add_executable(peglint lint/peglint.cc lint/server.cc) -target_link_libraries(peglint pthread) - -add_executable(test-main test/test.cc) -target_link_libraries(test-main pthread) - -add_executable(calc example/calc.cc) -target_link_libraries(calc pthread) - -add_executable(calc2 example/calc2.cc) -target_link_libraries(calc2 pthread) - -add_executable(calc3 example/calc3.cc) -target_link_libraries(calc3 pthread) - -add_executable(pl0 language/pl0/pl0.cc) -target_link_libraries(pl0 pthread) - -add_executable(culebra language/culebra/main.cc) -target_link_libraries(culebra pthread) +add_subdirectory(lint) +add_subdirectory(test) +add_subdirectory(example) +add_subdirectory(language/pl0) +add_subdirectory(language/culebra) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt new file mode 100644 index 0000000..b421ee7 --- /dev/null +++ b/example/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.0) +include_directories(..) +add_definitions("-std=c++1y") + +add_executable(calc calc.cc) +target_link_libraries(calc pthread) + +add_executable(calc2 calc2.cc) +target_link_libraries(calc2 pthread) + +add_executable(calc3 calc3.cc) +target_link_libraries(calc3 pthread) diff --git a/example/Makefile b/example/Makefile deleted file mode 100644 index 10237a9..0000000 --- a/example/Makefile +++ /dev/null @@ -1,21 +0,0 @@ - -USE_CLANG = 1 - -ifdef USE_CLANG -CC = clang++ -CFLAGS = -std=c++1y -stdlib=libc++ -g -else -CC = g++ -CFLAGS = -std=c++1y -g -endif - -all: calc calc2 calc3 - -calc : calc.cc ../peglib.h - $(CC) -o calc $(CFLAGS) -I.. calc.cc - -calc2 : calc2.cc ../peglib.h - $(CC) -o calc2 $(CFLAGS) -I.. calc2.cc - -calc3 : calc3.cc ../peglib.h - $(CC) -o calc3 $(CFLAGS) -I.. calc3.cc diff --git a/language/culebra/culebra.h b/language/culebra/culebra.h index 1606cb3..213167f 100644 --- a/language/culebra/culebra.h +++ b/language/culebra/culebra.h @@ -141,21 +141,21 @@ struct FunctionValue { }; struct ObjectValue { + ObjectValue() : properties(std::make_shared>()) {} bool has(const std::string& name) const; const Value& get(const std::string& name) const; void assign(const std::string& name, const Value& val); void initialize(const std::string& name, const Value& val, bool mut); virtual std::map& builtins(); - std::shared_ptr> properties = - std::make_shared>(); + std::shared_ptr> properties; }; struct ArrayValue : public ObjectValue { + ArrayValue() : values(std::make_shared>()) {} std::map& builtins() override; - std::shared_ptr> values = - std::make_shared>(); + std::shared_ptr> values; }; struct Value diff --git a/language/culebra/main.cc b/language/culebra/main.cc index dab97ed..5f962c3 100644 --- a/language/culebra/main.cc +++ b/language/culebra/main.cc @@ -5,7 +5,6 @@ #include #include -using namespace culebra; using namespace peg; using namespace std; @@ -28,7 +27,7 @@ bool read_file(const char* path, vector& buff) struct CommandLineDebugger { - void operator()(const Ast& ast, Environment& env, bool force_to_break) { + void operator()(const Ast& ast, culebra::Environment& env, bool force_to_break) { if (quit) { return; } @@ -130,7 +129,7 @@ struct CommandLineDebugger } } - void print(const Ast& ast, Environment& env, const string& symbol) { + void print(const Ast& ast, culebra::Environment& env, const string& symbol) { if (symbol.empty()) { print_all(ast, env); } else if (env.has(symbol)) { @@ -140,14 +139,14 @@ struct CommandLineDebugger } } - void print_all(const Ast& ast, Environment& env) { + void print_all(const Ast& ast, culebra::Environment& env) { auto node = find_function_node(ast); set references; enum_identifiers(*node, references); for (const auto& symbol: references) { if (env.has(symbol)) { const auto& val = env.get(symbol); - if (val.type != Value::Function) { + if (val.type != culebra::Value::Function) { cout << symbol << ": " << val.str() << endl; } } @@ -212,7 +211,7 @@ struct CommandLineDebugger map> sources_; }; -int repl(shared_ptr env, bool print_ast) +int repl(shared_ptr env, bool print_ast) { for (;;) { auto line = linenoise::Readline("cul> "); @@ -223,13 +222,13 @@ int repl(shared_ptr env, bool print_ast) if (!line.empty()) { vector msgs; - auto ast = parse("(repl)", line.data(), line.size(), msgs); + auto ast = culebra::parse("(repl)", line.data(), line.size(), msgs); if (ast) { if (print_ast) { cout << peg::ast_to_s(ast); } - Value val; + culebra::Value val; if (interpret(ast, env, val, msgs)) { cout << val << endl; linenoise::AddHistory(line.c_str()); @@ -272,7 +271,7 @@ int main(int argc, const char** argv) } try { - auto env = make_shared(); + auto env = make_shared(); setup_built_in_functions(*env); for (auto path: path_list) { @@ -283,14 +282,14 @@ int main(int argc, const char** argv) } vector msgs; - auto ast = parse(path, buff.data(), buff.size(), msgs); + auto ast = culebra::parse(path, buff.data(), buff.size(), msgs); if (ast) { if (print_ast) { cout << peg::ast_to_s(ast); } - Value val; - auto dbg = debug ? CommandLineDebugger() : Debugger(); + culebra::Value val; + auto dbg = debug ? CommandLineDebugger() : culebra::Debugger(); if (interpret(ast, env, val, msgs, dbg)) { return 0; } diff --git a/lint/CMakeLists.txt b/lint/CMakeLists.txt new file mode 100644 index 0000000..45f9d69 --- /dev/null +++ b/lint/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.0) +include_directories(..) +add_definitions("-std=c++1y") + +add_executable(peglint peglint.cc server.cc) diff --git a/lint/Makefile b/lint/Makefile deleted file mode 100644 index 9e63b0c..0000000 --- a/lint/Makefile +++ /dev/null @@ -1,15 +0,0 @@ - -USE_CLANG = 1 - -ifdef USE_CLANG -CC = clang++ -CFLAGS = -std=c++1y -stdlib=libc++ -g -else -CC = g++ -CFLAGS = -std=c++1y -g -endif - -all: peglint - -peglint : peglint.cc server.cc ../peglib.h - $(CC) -o peglint $(CFLAGS) -I.. peglint.cc server.cc diff --git a/peglib.h b/peglib.h index e4ff52d..26f78d8 100644 --- a/peglib.h +++ b/peglib.h @@ -158,7 +158,7 @@ private: * scope_exit *---------------------------------------------------------------------------*/ -// This is from "http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4189". +// This is based on "http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4189". template struct scope_exit @@ -173,7 +173,7 @@ struct scope_exit rhs.release(); } - ~scope_exit() noexcept(noexcept(this->exit_function())) { + ~scope_exit() noexcept { if (execute_on_destruction) { this->exit_function(); } @@ -2232,14 +2232,12 @@ void ast_to_s(const std::shared_ptr& ptr, std::string& s, int level = 0) { std::string name; if (ast.name == ast.original_name) { name = ast.name; - } - else { - name = ast.original_name + " (" + ast.name + ")"; + } else { + name = ast.original_name + "[" + ast.name + "]"; } if (ast.is_token) { - s += "- " + name + "(" + ast.token + ")\n"; - } - else { + s += "- " + name + " (" + ast.token + ")\n"; + } else { s += "+ " + name + "\n"; } for (auto node : ast.nodes) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..134e994 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.0) +include_directories(..) +add_definitions("-std=c++1y") + +add_executable(test-main test.cc) +target_link_libraries(test-main pthread) diff --git a/test/Makefile b/test/Makefile deleted file mode 100644 index 5ade22d..0000000 --- a/test/Makefile +++ /dev/null @@ -1,16 +0,0 @@ - -USE_CLANG = 1 - -ifdef USE_CLANG -CC = clang++ -CCFLAGS = -std=c++1y -stdlib=libc++ -g -else -CC = g++ -CCFLAGS = -std=c++1y -g -endif - -all : test - ./test - -test : test.cc ../peglib.h - $(CC) -o test $(CCFLAGS) -I.. -I. test.cc