From 2c56612650feda34019b5e8ad3951045e3a33004 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 18 Feb 2014 09:07:00 -0800 Subject: [PATCH] Get makefile working --- Makefile | 49 ++++++++----------- .../build_tables/rule_can_be_blank_spec.cpp | 2 +- .../build_tables/rule_transitions_spec.cpp | 2 +- spec/compiler/rules/character_set_spec.cpp | 2 +- spec/compiler/rules/pattern_spec.cpp | 4 +- spec/compiler/rules/rules_spec.cpp | 2 +- spec/runtime/arithmetic_spec.cpp | 1 - spec/runtime/json_spec.cpp | 1 - spec/runtime/tree_spec.cpp | 1 - spec/spec_helper.cpp | 4 +- spec/spec_helper.h | 1 + src/compiler/build_tables/first_set.h | 2 +- src/compiler/build_tables/follow_sets.h | 2 +- src/compiler/build_tables/item.h | 2 +- src/compiler/build_tables/merge_transitions.h | 4 +- src/compiler/build_tables/perform.cpp | 31 ++++++------ src/compiler/build_tables/rule_transitions.h | 4 +- src/compiler/generate_code/c_code.cpp | 2 +- src/compiler/grammar.cpp | 10 ++-- src/compiler/lex_table.cpp | 4 +- src/compiler/lex_table.h | 4 +- src/compiler/parse_table.cpp | 2 +- src/compiler/parse_table.h | 4 +- .../prepare_grammar/search_for_symbols.cpp | 6 +-- .../prepare_grammar/search_for_symbols.h | 2 +- src/compiler/rules/pattern.cpp | 4 +- src/compiler/rules/rules.cpp | 18 +++---- src/runtime/document.c | 2 +- src/runtime/error.cpp | 2 +- src/runtime/tree.c | 2 +- tree_sitter.xcodeproj/project.pbxproj | 6 ++- .../xcschemes/compiler_specs.xcscheme | 2 +- 32 files changed, 87 insertions(+), 97 deletions(-) diff --git a/Makefile b/Makefile index 5e686623..7c6c8152 100644 --- a/Makefile +++ b/Makefile @@ -1,48 +1,40 @@ -.PHONY: all clean install install-dev test test-c test-scm valgrind +.PHONY: all clean test debug valgrind ### install configuration ### CPP = c++ +CC = cc RM ?= rm -f -INSTALL ?= install MKDIR ?= $(INSTALL) -d SYMLINK ?= ln -s -PREFIX ?= /usr/local -BINDIR ?= $(PREFIX)/bin -LIBDIR ?= $(PREFIX)/lib -SOLIBDIR ?= $(PREFIX)/lib -INCDIR ?= $(PREFIX)/include -MODDIR ?= $(PREFIX)/share -BINMODDIR ?= $(PREFIX)/lib -MANDIR ?= $(PREFIX)/share/man/man1 - ### library configuration ### -LIB_NAME = tree_sitter -DIR = $(shell pwd) -HEADERS = $(wildcard include/*.h) -SOURCES = $(wildcard src/*.cpp) -TESTS = $(wildcard spec/*.cpp) -OBJECTS = $(foreach file, $(C_SOURCES), $(basename $(file)).o) -LIB_FILE = lib$(LIB_NAME)$(SO) -TEST_BIN = spec/run.out +LIB_NAME = tree_sitter +DIR = $(shell pwd) +SOURCES = $(shell find src -name '*.cpp' -or -name '*.c') +TESTS = $(shell find spec -name '*.cpp') $(shell find examples -name '*.c') +SRC_OBJECTS = $(foreach file, $(SOURCES), $(basename $(file)).o) +TEST_OBJECTS = $(foreach file, $(TESTS), $(basename $(file)).o) +LIB_FILE = lib$(LIB_NAME)$(SO) +TEST_BIN = spec/run.out ### build configuration ### -CFLAGS ?= -Wall -std=c++11 -stdlib=libc++ -g -m64 +CFLAGS ?= -Wall -g -m64 +CPPFLAGS ?= -Wall -std=c++11 -stdlib=libc++ -g -m64 ### targets ### all: $(LIB_FILE) -src/%.o: src/%.cpp - $(CPP) $(CFLAGS) -c $< -o $@ +%.o: %.c + $(CC) $(CFLAGS) -Iinclude -Isrc/runtime -c $< -o $@ + +%.o: %.cpp + $(CPP) $(CPPFLAGS) -Iinclude -Isrc/compiler -Isrc/runtime -Iexternals/bandit -Ispec -c $< -o $@ test: $(TEST_BIN) ./$< -$(TEST_BIN): $(TESTS) $(SOURCES) - $(CPP) $(CFLAGS) -Ispec/externals/igloo -Isrc -L. $^ -o $@ - -# $(TEST_BIN): $(LIB_FILE) $(C_TESTS) - # $(CPP) $(CFLAGS) -Ispec/externals/igloo -Isrc -L. -l$(LIB_NAME) test/c/_runner.cc -o $@ +$(TEST_BIN): $(TEST_OBJECTS) $(SRC_OBJECTS) + $(CPP) $(CPPFLAGS) $(TEST_OBJECTS) $(SRC_OBJECTS) -o $@ debug: $(TEST_BIN) gdb $< @@ -51,5 +43,4 @@ valgrind: $(TEST_BIN) valgrind --track-origins=yes $(TEST_BIN) clean: - $(RM) $(OBJECTS) $(LIB_FILE) $(TEST_BIN) - + $(RM) $(SRC_OBJECTS) $(TEST_OBJECTS) $(LIB_FILE) $(TEST_BIN) diff --git a/spec/compiler/build_tables/rule_can_be_blank_spec.cpp b/spec/compiler/build_tables/rule_can_be_blank_spec.cpp index 312abf39..ae40ca2c 100644 --- a/spec/compiler/build_tables/rule_can_be_blank_spec.cpp +++ b/spec/compiler/build_tables/rule_can_be_blank_spec.cpp @@ -1,5 +1,5 @@ #include "spec_helper.h" -#include "rule_can_be_blank.h" +#include "build_tables/rule_can_be_blank.h" using namespace rules; using build_tables::rule_can_be_blank; diff --git a/spec/compiler/build_tables/rule_transitions_spec.cpp b/spec/compiler/build_tables/rule_transitions_spec.cpp index 6df19872..c032b95e 100644 --- a/spec/compiler/build_tables/rule_transitions_spec.cpp +++ b/spec/compiler/build_tables/rule_transitions_spec.cpp @@ -1,5 +1,5 @@ #include "spec_helper.h" -#include "rule_transitions.h" +#include "build_tables/rule_transitions.h" using namespace rules; using namespace build_tables; diff --git a/spec/compiler/rules/character_set_spec.cpp b/spec/compiler/rules/character_set_spec.cpp index 206e27e7..b92e35c0 100644 --- a/spec/compiler/rules/character_set_spec.cpp +++ b/spec/compiler/rules/character_set_spec.cpp @@ -1,5 +1,5 @@ #include "spec_helper.h" -#include "character_set.h" +#include "rules/character_set.h" using namespace rules; diff --git a/spec/compiler/rules/pattern_spec.cpp b/spec/compiler/rules/pattern_spec.cpp index 432aead0..acda7700 100644 --- a/spec/compiler/rules/pattern_spec.cpp +++ b/spec/compiler/rules/pattern_spec.cpp @@ -1,6 +1,6 @@ #include "spec_helper.h" -#include "pattern.h" -#include "character_set.h" +#include "rules/pattern.h" +#include "rules/character_set.h" using namespace rules; diff --git a/spec/compiler/rules/rules_spec.cpp b/spec/compiler/rules/rules_spec.cpp index 457c0d45..0fec228d 100644 --- a/spec/compiler/rules/rules_spec.cpp +++ b/spec/compiler/rules/rules_spec.cpp @@ -1,5 +1,5 @@ #include "spec_helper.h" -#include "rule.h" +#include "rules/rule.h" using namespace rules; diff --git a/spec/runtime/arithmetic_spec.cpp b/spec/runtime/arithmetic_spec.cpp index 8a29852c..561f1e77 100644 --- a/spec/runtime/arithmetic_spec.cpp +++ b/spec/runtime/arithmetic_spec.cpp @@ -1,5 +1,4 @@ #include "spec_helper.h" -#include "runtime.h" extern TSParseConfig ts_parse_config_arithmetic; diff --git a/spec/runtime/json_spec.cpp b/spec/runtime/json_spec.cpp index 5d86c5fc..6860d81c 100644 --- a/spec/runtime/json_spec.cpp +++ b/spec/runtime/json_spec.cpp @@ -1,5 +1,4 @@ #include "spec_helper.h" -#include "runtime.h" extern TSParseConfig ts_parse_config_json; diff --git a/spec/runtime/tree_spec.cpp b/spec/runtime/tree_spec.cpp index 15dba00d..2bcddaff 100644 --- a/spec/runtime/tree_spec.cpp +++ b/spec/runtime/tree_spec.cpp @@ -1,5 +1,4 @@ #include "spec_helper.h" -#include "runtime.h" START_TEST diff --git a/spec/spec_helper.cpp b/spec/spec_helper.cpp index 858c9b18..dae44a92 100644 --- a/spec/spec_helper.cpp +++ b/spec/spec_helper.cpp @@ -1,5 +1,7 @@ #include "spec_helper.h" string src_dir() { - return string(getenv("TREESITTER_SRC_DIR")); + const char * dir = getenv("TREESITTER_DIR"); + if (!dir) dir = getenv("PWD"); + return dir; } \ No newline at end of file diff --git a/spec/spec_helper.h b/spec/spec_helper.h index 2b9698f1..8deb0e52 100644 --- a/spec/spec_helper.h +++ b/spec/spec_helper.h @@ -5,6 +5,7 @@ #include "helpers/stream_methods.h" #include "helpers/equals_pointer.h" #include "tree_sitter/compiler.h" +#include "tree_sitter/runtime.h" using namespace tree_sitter; using namespace std; diff --git a/src/compiler/build_tables/first_set.h b/src/compiler/build_tables/first_set.h index cf0038e1..c7af3352 100644 --- a/src/compiler/build_tables/first_set.h +++ b/src/compiler/build_tables/first_set.h @@ -1,7 +1,7 @@ #ifndef __tree_sitter__first_set__ #define __tree_sitter__first_set__ -#include "symbol.h" +#include "rules/symbol.h" #include namespace tree_sitter { diff --git a/src/compiler/build_tables/follow_sets.h b/src/compiler/build_tables/follow_sets.h index cc9184b3..b5609e98 100644 --- a/src/compiler/build_tables/follow_sets.h +++ b/src/compiler/build_tables/follow_sets.h @@ -2,7 +2,7 @@ #define __tree_sitter__follow_sets__ #include "item.h" -#include "symbol.h" +#include "rules/symbol.h" #include #include diff --git a/src/compiler/build_tables/item.h b/src/compiler/build_tables/item.h index 206d0422..8826cec2 100644 --- a/src/compiler/build_tables/item.h +++ b/src/compiler/build_tables/item.h @@ -1,7 +1,7 @@ #ifndef __tree_sitter__item__ #define __tree_sitter__item__ -#include "symbol.h" +#include "rules/symbol.h" #include #include #include diff --git a/src/compiler/build_tables/merge_transitions.h b/src/compiler/build_tables/merge_transitions.h index e2394d55..0d6c3e61 100644 --- a/src/compiler/build_tables/merge_transitions.h +++ b/src/compiler/build_tables/merge_transitions.h @@ -1,8 +1,8 @@ #ifndef __tree_sitter__merge_transitions__ #define __tree_sitter__merge_transitions__ -#include "character_set.h" -#include "symbol.h" +#include "rules/character_set.h" +#include "rules/symbol.h" #include namespace tree_sitter { diff --git a/src/compiler/build_tables/perform.cpp b/src/compiler/build_tables/perform.cpp index 9e1531dd..c09d9121 100644 --- a/src/compiler/build_tables/perform.cpp +++ b/src/compiler/build_tables/perform.cpp @@ -4,8 +4,6 @@ #include "item_set_transitions.h" #include "tree_sitter/compiler.h" -#include "stream_methods.h" - namespace tree_sitter { using std::pair; using std::string; @@ -111,21 +109,20 @@ namespace tree_sitter { return state_index; } - // TODO - remove - void dump_item_sets() { - std::vector item_sets(parse_state_indices.size()); - for (auto &pair : parse_state_indices) - item_sets[pair.second] = &pair.first; - - for (int i = 0; i < item_sets.size(); i++) { - std:cout << "\n\n" << i; - for (auto &item : *item_sets[i]) { - cout << "\n" << item.lhs; - cout << "\n " << item.rule; - cout << "\n " << item.lookahead_sym.name; - } - } - } +// void dump_item_sets() { +// std::vector item_sets(parse_state_indices.size()); +// for (auto &pair : parse_state_indices) +// item_sets[pair.second] = &pair.first; +// +// for (int i = 0; i < item_sets.size(); i++) { +// std:cout << "\n\n" << i; +// for (auto &item : *item_sets[i]) { +// cout << "\n" << item.lhs; +// cout << "\n " << item.rule; +// cout << "\n " << item.lookahead_sym.name; +// } +// } +// } public: diff --git a/src/compiler/build_tables/rule_transitions.h b/src/compiler/build_tables/rule_transitions.h index 2f810f38..a6450994 100644 --- a/src/compiler/build_tables/rule_transitions.h +++ b/src/compiler/build_tables/rule_transitions.h @@ -1,8 +1,8 @@ #ifndef __tree_sitter__transitions__ #define __tree_sitter__transitions__ -#include "character_set.h" -#include "symbol.h" +#include "rules/character_set.h" +#include "rules/symbol.h" #include namespace tree_sitter { diff --git a/src/compiler/generate_code/c_code.cpp b/src/compiler/generate_code/c_code.cpp index 09c118c3..ce4ddf26 100644 --- a/src/compiler/generate_code/c_code.cpp +++ b/src/compiler/generate_code/c_code.cpp @@ -74,9 +74,9 @@ namespace tree_sitter { } class CCodeGenerator { + const string name; const ParseTable parse_table; const LexTable lex_table; - const string name; public: CCodeGenerator(string name, const ParseTable &parse_table, const LexTable &lex_table) : name(name), diff --git a/src/compiler/grammar.cpp b/src/compiler/grammar.cpp index 7f454694..d4bb1d1d 100644 --- a/src/compiler/grammar.cpp +++ b/src/compiler/grammar.cpp @@ -1,5 +1,5 @@ #include "tree_sitter/compiler.h" -#include "symbol.h" +#include "rules/symbol.h" namespace tree_sitter { using std::vector; @@ -13,15 +13,15 @@ namespace tree_sitter { Grammar::Grammar(std::string start_rule_name, const std::map &rules) : - rules(rules), - start_rule_name(start_rule_name) {} + start_rule_name(start_rule_name), + rules(rules) {} Grammar::Grammar(std::string start_rule_name, const map &rules, const map &aux_rules) : + start_rule_name(start_rule_name), rules(rules), - aux_rules(aux_rules), - start_rule_name(start_rule_name) {} + aux_rules(aux_rules) {} const rule_ptr Grammar::rule(const Symbol &symbol) const { auto map = symbol.is_auxiliary ? aux_rules : rules; diff --git a/src/compiler/lex_table.cpp b/src/compiler/lex_table.cpp index 8a91725f..4e2df4d3 100644 --- a/src/compiler/lex_table.cpp +++ b/src/compiler/lex_table.cpp @@ -10,8 +10,8 @@ namespace tree_sitter { LexAction::LexAction(LexActionType type, size_t state_index, Symbol symbol) : type(type), - state_index(state_index), - symbol(symbol) {} + symbol(symbol), + state_index(state_index) {} LexAction LexAction::Error() { return LexAction(LexActionTypeError, -1, Symbol("")); diff --git a/src/compiler/lex_table.h b/src/compiler/lex_table.h index fb0eafff..527fb836 100644 --- a/src/compiler/lex_table.h +++ b/src/compiler/lex_table.h @@ -5,8 +5,8 @@ #include #include #include -#include "symbol.h" -#include "character_set.h" +#include "rules/symbol.h" +#include "rules/character_set.h" namespace tree_sitter { typedef enum { diff --git a/src/compiler/parse_table.cpp b/src/compiler/parse_table.cpp index 0950c8a5..36fc3008 100644 --- a/src/compiler/parse_table.cpp +++ b/src/compiler/parse_table.cpp @@ -10,8 +10,8 @@ namespace tree_sitter { ParseAction::ParseAction(ParseActionType type, size_t state_index, Symbol symbol, const vector &child_flags) : type(type), - state_index(state_index), symbol(symbol), + state_index(state_index), child_flags(child_flags) {}; ParseAction ParseAction::Error() { diff --git a/src/compiler/parse_table.h b/src/compiler/parse_table.h index dcef2f18..823d36fd 100644 --- a/src/compiler/parse_table.h +++ b/src/compiler/parse_table.h @@ -4,7 +4,7 @@ #include #include #include -#include "symbol.h" +#include "rules/symbol.h" namespace tree_sitter { typedef enum { @@ -25,9 +25,9 @@ namespace tree_sitter { bool operator<(const ParseAction &action) const; ParseActionType type; - std::vector child_flags; rules::Symbol symbol; size_t state_index; + std::vector child_flags; }; std::ostream& operator<<(std::ostream &stream, const ParseAction &item); diff --git a/src/compiler/prepare_grammar/search_for_symbols.cpp b/src/compiler/prepare_grammar/search_for_symbols.cpp index 302d4da6..66869afa 100644 --- a/src/compiler/prepare_grammar/search_for_symbols.cpp +++ b/src/compiler/prepare_grammar/search_for_symbols.cpp @@ -1,8 +1,8 @@ #include "search_for_symbols.h" #include "rules/visitor.h" -#include "choice.h" -#include "seq.h" -#include "repeat.h" +#include "rules/choice.h" +#include "rules/seq.h" +#include "rules/repeat.h" namespace tree_sitter { using namespace rules; diff --git a/src/compiler/prepare_grammar/search_for_symbols.h b/src/compiler/prepare_grammar/search_for_symbols.h index 14d53a3a..6023e556 100644 --- a/src/compiler/prepare_grammar/search_for_symbols.h +++ b/src/compiler/prepare_grammar/search_for_symbols.h @@ -1,7 +1,7 @@ #ifndef __tree_sitter__search_for_symbols__ #define __tree_sitter__search_for_symbols__ -#include "rule.h" +#include "tree_sitter/compiler.h" namespace tree_sitter { namespace prepare_grammar { diff --git a/src/compiler/rules/pattern.cpp b/src/compiler/rules/pattern.cpp index fb5a8d2f..4a878b9e 100644 --- a/src/compiler/rules/pattern.cpp +++ b/src/compiler/rules/pattern.cpp @@ -17,8 +17,8 @@ namespace tree_sitter { public: PatternParser(const string &input) : input(input), - position(0), - length(input.length()) {} + length(input.length()), + position(0) {} rule_ptr rule() { auto result = term(); diff --git a/src/compiler/rules/rules.cpp b/src/compiler/rules/rules.cpp index a7390efe..eeb3f12c 100644 --- a/src/compiler/rules/rules.cpp +++ b/src/compiler/rules/rules.cpp @@ -1,13 +1,13 @@ #include "tree_sitter/compiler.h" -#include "rule.h" -#include "blank.h" -#include "symbol.h" -#include "choice.h" -#include "seq.h" -#include "string.h" -#include "pattern.h" -#include "character_set.h" -#include "repeat.h" +#include "./rule.h" +#include "./blank.h" +#include "./symbol.h" +#include "./choice.h" +#include "./seq.h" +#include "./string.h" +#include "./pattern.h" +#include "./character_set.h" +#include "./repeat.h" namespace tree_sitter { using std::make_shared; diff --git a/src/runtime/document.c b/src/runtime/document.c index f124aa74..19c2a6e0 100644 --- a/src/runtime/document.c +++ b/src/runtime/document.c @@ -1,4 +1,4 @@ -#include "runtime.h" +#include "tree_sitter/runtime.h" struct TSDocument { TSParseFn *parse_fn; diff --git a/src/runtime/error.cpp b/src/runtime/error.cpp index 055dffac..52afb688 100644 --- a/src/runtime/error.cpp +++ b/src/runtime/error.cpp @@ -1,4 +1,4 @@ -#include "runtime.h" +#include "tree_sitter/runtime.h" #include using std::string; diff --git a/src/runtime/tree.c b/src/runtime/tree.c index 94c44e0d..7ee2033e 100644 --- a/src/runtime/tree.c +++ b/src/runtime/tree.c @@ -1,4 +1,4 @@ -#include "runtime.h" +#include "tree_sitter/runtime.h" #include #include diff --git a/tree_sitter.xcodeproj/project.pbxproj b/tree_sitter.xcodeproj/project.pbxproj index 5b726b5e..7a5b8db3 100644 --- a/tree_sitter.xcodeproj/project.pbxproj +++ b/tree_sitter.xcodeproj/project.pbxproj @@ -100,6 +100,7 @@ 1236A7C318B287DC00593ABB /* character_range.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = character_range.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; 1236A7C918B2A79F00593ABB /* rule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rule.h; sourceTree = ""; }; 1236A7CA18B2ABB900593ABB /* equals_pointer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = equals_pointer.h; sourceTree = ""; }; + 1236A7CC18B2B4F000593ABB /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = ""; }; 1251209A1830145300C9B56A /* rule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rule.cpp; sourceTree = ""; }; 125120A3183083BD00C9B56A /* arithmetic.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; lineEnding = 0; path = arithmetic.hpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; 12661BF318A1505A00A259FB /* character_set_spec.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = character_set_spec.cpp; path = spec/compiler/rules/character_set_spec.cpp; sourceTree = SOURCE_ROOT; }; @@ -294,9 +295,10 @@ 12E716F9181D010E0051A649 = { isa = PBXGroup; children = ( - 12E71795181D02A80051A649 /* Products */, - 12FD40D3185FED630041A84E /* include */, 12FD40AF185EE81D0041A84E /* examples */, + 12FD40D3185FED630041A84E /* include */, + 1236A7CC18B2B4F000593ABB /* Makefile */, + 12E71795181D02A80051A649 /* Products */, 12E71796181D02A80051A649 /* spec */, 12E71701181D01890051A649 /* src */, 12D1369E18342088005F3369 /* todo.md */, diff --git a/tree_sitter.xcodeproj/xcshareddata/xcschemes/compiler_specs.xcscheme b/tree_sitter.xcodeproj/xcshareddata/xcschemes/compiler_specs.xcscheme index bb3f74a4..9ad6bf79 100644 --- a/tree_sitter.xcodeproj/xcshareddata/xcschemes/compiler_specs.xcscheme +++ b/tree_sitter.xcodeproj/xcshareddata/xcschemes/compiler_specs.xcscheme @@ -59,7 +59,7 @@