From 5a25505668bac9aed0ad8f3b23fe81c6aff29b71 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 24 Nov 2017 14:56:05 -0500 Subject: [PATCH] rename "parsec" to "translate-c" --- CMakeLists.txt | 2 +- build.zig | 2 +- ci/travis_osx_script | 2 +- src-self-hosted/main.zig | 2 +- src/analyze.cpp | 4 +-- src/codegen.cpp | 4 +-- src/codegen.hpp | 2 +- src/ir.cpp | 2 +- src/main.cpp | 22 ++++++------- src/{parsec.cpp => translate_c.cpp} | 2 +- src/{parsec.hpp => translate_c.hpp} | 0 test/tests.zig | 48 ++++++++++++++-------------- test/{parsec.zig => translate_c.zig} | 2 +- 13 files changed, 47 insertions(+), 47 deletions(-) rename src/{parsec.cpp => translate_c.cpp} (99%) rename src/{parsec.hpp => translate_c.hpp} (100%) rename test/{parsec.zig => translate_c.zig} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8906798c69..72c480cd40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -339,7 +339,7 @@ set(ZIG_SOURCES "${CMAKE_SOURCE_DIR}/src/target.cpp" "${CMAKE_SOURCE_DIR}/src/tokenizer.cpp" "${CMAKE_SOURCE_DIR}/src/util.cpp" - "${CMAKE_SOURCE_DIR}/src/parsec.cpp" + "${CMAKE_SOURCE_DIR}/src/translate_c.cpp" "${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp" ) diff --git a/build.zig b/build.zig index 79fefd5c7a..1c1d4f832e 100644 --- a/build.zig +++ b/build.zig @@ -58,5 +58,5 @@ pub fn build(b: &Builder) { test_step.dependOn(tests.addCompileErrorTests(b, test_filter)); test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter)); test_step.dependOn(tests.addDebugSafetyTests(b, test_filter)); - test_step.dependOn(tests.addParseCTests(b, test_filter)); + test_step.dependOn(tests.addTranslateCTests(b, test_filter)); } diff --git a/ci/travis_osx_script b/ci/travis_osx_script index 1f345c9c50..a55132395b 100755 --- a/ci/travis_osx_script +++ b/ci/travis_osx_script @@ -22,4 +22,4 @@ make install ./zig build --build-file ../build.zig test-compile-errors --verbose ./zig build --build-file ../build.zig test-asm-link --verbose ./zig build --build-file ../build.zig test-debug-safety --verbose -./zig build --build-file ../build.zig test-parsec --verbose +./zig build --build-file ../build.zig test-translate-c --verbose diff --git a/src-self-hosted/main.zig b/src-self-hosted/main.zig index 0716ad433b..71180b2001 100644 --- a/src-self-hosted/main.zig +++ b/src-self-hosted/main.zig @@ -208,7 +208,7 @@ fn printUsage(outstream: &io.OutStream) -> %void { \\ build-exe [source] create executable from source or object files \\ build-lib [source] create library from source or object files \\ build-obj [source] create object from source or assembly - \\ parsec [source] convert c code to zig code + \\ translate-c [source] convert c code to zig code \\ targets list available compilation targets \\ test [source] create and run a test build \\ version print version number and exit diff --git a/src/analyze.cpp b/src/analyze.cpp index ebad9fe0cb..7a9df874d4 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -28,7 +28,7 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type); ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) { if (node->owner->c_import_node != nullptr) { - // if this happens, then parsec generated code that + // if this happens, then translate_c generated code that // failed semantic analysis, which isn't supposed to happen ErrorMsg *err = add_node_error(g, node->owner->c_import_node, buf_sprintf("compiler bug: @cImport generated invalid zig code")); @@ -48,7 +48,7 @@ ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) { ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg) { if (node->owner->c_import_node != nullptr) { - // if this happens, then parsec generated code that + // if this happens, then translate_c generated code that // failed semantic analysis, which isn't supposed to happen Buf *note_path = buf_create_from_str("?.c"); diff --git a/src/codegen.cpp b/src/codegen.cpp index 680f5a9e35..24d24a91e5 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -15,7 +15,7 @@ #include "ir.hpp" #include "link.hpp" #include "os.hpp" -#include "parsec.hpp" +#include "translate_c.hpp" #include "target.hpp" #include "zig_llvm.hpp" @@ -5353,7 +5353,7 @@ static void init(CodeGen *g) { define_builtin_compile_vars(g); } -void codegen_parsec(CodeGen *g, Buf *full_path) { +void codegen_translate_c(CodeGen *g, Buf *full_path) { find_libc_include_path(g); Buf *src_basename = buf_alloc(); diff --git a/src/codegen.hpp b/src/codegen.hpp index b71a7fa651..b29cadee55 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -56,7 +56,7 @@ PackageTableEntry *codegen_create_package(CodeGen *g, const char *root_src_dir, void codegen_add_assembly(CodeGen *g, Buf *path); void codegen_add_object(CodeGen *g, Buf *object_path); -void codegen_parsec(CodeGen *g, Buf *path); +void codegen_translate_c(CodeGen *g, Buf *path); #endif diff --git a/src/ir.cpp b/src/ir.cpp index fa59aa03f2..c81de7fa7a 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -11,7 +11,7 @@ #include "ir.hpp" #include "ir_print.hpp" #include "os.hpp" -#include "parsec.hpp" +#include "translate_c.hpp" #include "range_set.hpp" #include "softfloat.hpp" diff --git a/src/main.cpp b/src/main.cpp index 13da71f9e8..60d2750bde 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,7 @@ static int usage(const char *arg0) { " build-exe [source] create executable from source or object files\n" " build-lib [source] create library from source or object files\n" " build-obj [source] create object from source or assembly\n" - " parsec [source] convert c code to zig code\n" + " translate-c [source] convert c code to zig code\n" " targets list available compilation targets\n" " test [source] create and run a test build\n" " version print version number and exit\n" @@ -229,7 +229,7 @@ enum Cmd { CmdTest, CmdVersion, CmdZen, - CmdParseC, + CmdTranslateC, CmdTargets, }; @@ -632,8 +632,8 @@ int main(int argc, char **argv) { cmd = CmdVersion; } else if (strcmp(arg, "zen") == 0) { cmd = CmdZen; - } else if (strcmp(arg, "parsec") == 0) { - cmd = CmdParseC; + } else if (strcmp(arg, "translate-c") == 0) { + cmd = CmdTranslateC; } else if (strcmp(arg, "test") == 0) { cmd = CmdTest; out_type = OutTypeExe; @@ -646,7 +646,7 @@ int main(int argc, char **argv) { } else { switch (cmd) { case CmdBuild: - case CmdParseC: + case CmdTranslateC: case CmdTest: if (!in_file) { in_file = arg; @@ -703,13 +703,13 @@ int main(int argc, char **argv) { switch (cmd) { case CmdBuild: - case CmdParseC: + case CmdTranslateC: case CmdTest: { if (cmd == CmdBuild && !in_file && objects.length == 0 && asm_files.length == 0) { fprintf(stderr, "Expected source file argument or at least one --object or --assembly argument.\n"); return usage(arg0); - } else if ((cmd == CmdParseC || cmd == CmdTest) && !in_file) { + } else if ((cmd == CmdTranslateC || cmd == CmdTest) && !in_file) { fprintf(stderr, "Expected source file argument.\n"); return usage(arg0); } else if (cmd == CmdBuild && out_type == OutTypeObj && objects.length != 0) { @@ -719,7 +719,7 @@ int main(int argc, char **argv) { assert(cmd != CmdBuild || out_type != OutTypeUnknown); - bool need_name = (cmd == CmdBuild || cmd == CmdParseC); + bool need_name = (cmd == CmdBuild || cmd == CmdTranslateC); Buf *in_file_buf = nullptr; @@ -742,7 +742,7 @@ int main(int argc, char **argv) { return usage(arg0); } - Buf *zig_root_source_file = (cmd == CmdParseC) ? nullptr : in_file_buf; + Buf *zig_root_source_file = (cmd == CmdTranslateC) ? nullptr : in_file_buf; Buf *full_cache_dir = buf_alloc(); os_path_resolve(buf_create_from_str("."), @@ -841,8 +841,8 @@ int main(int argc, char **argv) { if (timing_info) codegen_print_timing_report(g, stdout); return EXIT_SUCCESS; - } else if (cmd == CmdParseC) { - codegen_parsec(g, in_file_buf); + } else if (cmd == CmdTranslateC) { + codegen_translate_c(g, in_file_buf); ast_render(g, stdout, g->root_import->root, 4); if (timing_info) codegen_print_timing_report(g, stdout); diff --git a/src/parsec.cpp b/src/translate_c.cpp similarity index 99% rename from src/parsec.cpp rename to src/translate_c.cpp index 79ba2ab990..a76432fa57 100644 --- a/src/parsec.cpp +++ b/src/translate_c.cpp @@ -11,7 +11,7 @@ #include "error.hpp" #include "ir.hpp" #include "os.hpp" -#include "parsec.hpp" +#include "translate_c.hpp" #include "parser.hpp" diff --git a/src/parsec.hpp b/src/translate_c.hpp similarity index 100% rename from src/parsec.hpp rename to src/translate_c.hpp diff --git a/test/tests.zig b/test/tests.zig index 20b57c7573..73d9646552 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -18,7 +18,7 @@ const build_examples = @import("build_examples.zig"); const compile_errors = @import("compile_errors.zig"); const assemble_and_link = @import("assemble_and_link.zig"); const debug_safety = @import("debug_safety.zig"); -const parsec = @import("parsec.zig"); +const translate_c = @import("translate_c.zig"); const TestTarget = struct { os: builtin.Os, @@ -123,16 +123,16 @@ pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> & return cases.step; } -pub fn addParseCTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { - const cases = %%b.allocator.create(ParseCContext); - *cases = ParseCContext { +pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { + const cases = %%b.allocator.create(TranslateCContext); + *cases = TranslateCContext { .b = b, - .step = b.step("test-parsec", "Run the C header file parsing tests"), + .step = b.step("test-translate-c", "Run the C header file parsing tests"), .test_index = 0, .test_filter = test_filter, }; - parsec.addCases(cases); + translate_c.addCases(cases); return cases.step; } @@ -770,7 +770,7 @@ pub const BuildExamplesContext = struct { } }; -pub const ParseCContext = struct { +pub const TranslateCContext = struct { b: &build.Builder, step: &build.Step, test_index: usize, @@ -799,17 +799,17 @@ pub const ParseCContext = struct { } }; - const ParseCCmpOutputStep = struct { + const TranslateCCmpOutputStep = struct { step: build.Step, - context: &ParseCContext, + context: &TranslateCContext, name: []const u8, test_index: usize, case: &const TestCase, - pub fn create(context: &ParseCContext, name: []const u8, case: &const TestCase) -> &ParseCCmpOutputStep { + pub fn create(context: &TranslateCContext, name: []const u8, case: &const TestCase) -> &TranslateCCmpOutputStep { const allocator = context.b.allocator; - const ptr = %%allocator.create(ParseCCmpOutputStep); - *ptr = ParseCCmpOutputStep { + const ptr = %%allocator.create(TranslateCCmpOutputStep); + *ptr = TranslateCCmpOutputStep { .step = build.Step.init("ParseCCmpOutput", allocator, make), .context = context, .name = name, @@ -821,7 +821,7 @@ pub const ParseCContext = struct { } fn make(step: &build.Step) -> %void { - const self = @fieldParentPtr(ParseCCmpOutputStep, "step", step); + const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step); const b = self.context.b; const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename); @@ -829,7 +829,7 @@ pub const ParseCContext = struct { var zig_args = ArrayList([]const u8).init(b.allocator); %%zig_args.append(b.zig_exe); - %%zig_args.append("parsec"); + %%zig_args.append("translate-c"); %%zig_args.append(b.pathFromRoot(root_src)); warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name); @@ -882,7 +882,7 @@ pub const ParseCContext = struct { if (stderr.len != 0 and !self.case.allow_warnings) { warn( - \\====== parsec emitted warnings: ============ + \\====== translate-c emitted warnings: ======= \\{} \\============================================ \\ @@ -914,7 +914,7 @@ pub const ParseCContext = struct { warn("\n"); } - pub fn create(self: &ParseCContext, allow_warnings: bool, filename: []const u8, name: []const u8, + pub fn create(self: &TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) -> &TestCase { const tc = %%self.b.allocator.create(TestCase); @@ -932,37 +932,37 @@ pub const ParseCContext = struct { return tc; } - pub fn add(self: &ParseCContext, name: []const u8, source: []const u8, expected_lines: ...) { + pub fn add(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) { const tc = self.create(false, "source.h", name, source, expected_lines); self.addCase(tc); } - pub fn addC(self: &ParseCContext, name: []const u8, source: []const u8, expected_lines: ...) { + pub fn addC(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) { const tc = self.create(false, "source.c", name, source, expected_lines); self.addCase(tc); } - pub fn addAllowWarnings(self: &ParseCContext, name: []const u8, source: []const u8, expected_lines: ...) { + pub fn addAllowWarnings(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) { const tc = self.create(true, "source.h", name, source, expected_lines); self.addCase(tc); } - pub fn addCase(self: &ParseCContext, case: &const TestCase) { + pub fn addCase(self: &TranslateCContext, case: &const TestCase) { const b = self.b; - const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "parsec {}", case.name); + const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "translate-c {}", case.name); if (self.test_filter) |filter| { if (mem.indexOf(u8, annotated_case_name, filter) == null) return; } - const parsec_and_cmp = ParseCCmpOutputStep.create(self, annotated_case_name, case); - self.step.dependOn(&parsec_and_cmp.step); + const translate_c_and_cmp = TranslateCCmpOutputStep.create(self, annotated_case_name, case); + self.step.dependOn(&translate_c_and_cmp.step); for (case.sources.toSliceConst()) |src_file| { const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename); const write_src = b.addWriteFile(expanded_src_path, src_file.source); - parsec_and_cmp.step.dependOn(&write_src.step); + translate_c_and_cmp.step.dependOn(&write_src.step); } } }; diff --git a/test/parsec.zig b/test/translate_c.zig similarity index 99% rename from test/parsec.zig rename to test/translate_c.zig index f830131262..6394950fd0 100644 --- a/test/parsec.zig +++ b/test/translate_c.zig @@ -1,6 +1,6 @@ const tests = @import("tests.zig"); -pub fn addCases(cases: &tests.ParseCContext) { +pub fn addCases(cases: &tests.TranslateCContext) { cases.addAllowWarnings("simple data types", \\#include \\int foo(char a, unsigned char b, signed char c);