From 2c9bdad3462f356f4c2ed2442f2cd6de80b9805b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 5 Sep 2017 22:55:03 -0400 Subject: [PATCH] rename parseh to parsec --- CMakeLists.txt | 2 +- build.zig | 2 +- ci/travis_linux_script | 2 +- src/analyze.cpp | 9 ++----- src/codegen.cpp | 4 +-- src/codegen.hpp | 2 +- src/ir.cpp | 2 +- src/main.cpp | 22 +++++++-------- src/{parseh.cpp => parsec.cpp} | 8 +++--- src/{parseh.hpp => parsec.hpp} | 4 +-- test/{parseh.zig => parsec.zig} | 2 +- test/tests.zig | 48 ++++++++++++++++----------------- 12 files changed, 51 insertions(+), 56 deletions(-) rename src/{parseh.cpp => parsec.cpp} (99%) rename src/{parseh.hpp => parsec.hpp} (90%) rename test/{parseh.zig => parsec.zig} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index f942fcd33..9524411e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -193,7 +193,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/parseh.cpp" + "${CMAKE_SOURCE_DIR}/src/parsec.cpp" "${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp" ) diff --git a/build.zig b/build.zig index 8ee49b35b..adc0d439d 100644 --- a/build.zig +++ b/build.zig @@ -19,5 +19,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.addParseHTests(b, test_filter)); + test_step.dependOn(tests.addParseCTests(b, test_filter)); } diff --git a/ci/travis_linux_script b/ci/travis_linux_script index 61e3d1044..fed101e07 100755 --- a/ci/travis_linux_script +++ b/ci/travis_linux_script @@ -15,4 +15,4 @@ make install # we have to skip cross compiling OSX tests because apt.llvm.org has an old version # of llvm for the version of ubuntu that travis is running on. ./zig build --build-file ../build.zig test-behavior test-std test-compiler-rt -Dtest-filter=linux -./zig build --build-file ../build.zig test-compare-output test-build-examples test-compile-errors test-asm-link test-debug-safety test-parseh +./zig build --build-file ../build.zig test-compare-output test-build-examples test-compile-errors test-asm-link test-debug-safety test-parsec diff --git a/src/analyze.cpp b/src/analyze.cpp index 322bb2f4b..fe705dfce 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -26,7 +26,7 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type); static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type); ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) { - // if this assert fails, then parseh generated code that + // if this assert fails, then parsec generated code that // failed semantic analysis, which isn't supposed to happen assert(!node->owner->c_import_node); @@ -38,7 +38,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 this assert fails, then parseh generated code that + // if this assert fails, then parsec generated code that // failed semantic analysis, which isn't supposed to happen assert(!node->owner->c_import_node); @@ -1265,7 +1265,6 @@ TypeTableEntry *create_enum_tag_type(CodeGen *g, TypeTableEntry *enum_type, Type } static void resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) { - // if you change this logic you likely must also change similar logic in parseh.cpp assert(enum_type->id == TypeTableEntryIdEnum); if (enum_type->data.enumeration.complete) @@ -1578,8 +1577,6 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f } static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) { - // if you change the logic of this function likely you must make a similar change in - // parseh.cpp assert(struct_type->id == TypeTableEntryIdStruct); if (struct_type->data.structure.complete) @@ -3079,8 +3076,6 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode * continue; } - // Note: target_tld->name is not necessarily equal to entry->key because - // of aliases that parseh uses. Buf *target_tld_name = entry->key; auto existing_entry = dst_use_node->owner->decls_scope->decl_table.put_unique(target_tld_name, target_tld); diff --git a/src/codegen.cpp b/src/codegen.cpp index eacb30395..15eac3368 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -15,7 +15,7 @@ #include "ir.hpp" #include "link.hpp" #include "os.hpp" -#include "parseh.hpp" +#include "parsec.hpp" #include "target.hpp" #include "zig_llvm.hpp" @@ -5001,7 +5001,7 @@ static void init(CodeGen *g) { define_builtin_compile_vars(g); } -void codegen_parseh(CodeGen *g, Buf *full_path) { +void codegen_parsec(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 4947d1a4d..5e266dfe1 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -54,7 +54,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_parseh(CodeGen *g, Buf *path); +void codegen_parsec(CodeGen *g, Buf *path); #endif diff --git a/src/ir.cpp b/src/ir.cpp index 800b013d5..9e15bb182 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -11,7 +11,7 @@ #include "ir.hpp" #include "ir_print.hpp" #include "os.hpp" -#include "parseh.hpp" +#include "parsec.hpp" #include "quadmath.hpp" #include "range_set.hpp" diff --git a/src/main.cpp b/src/main.cpp index f4fc58104..d6912ab6f 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" - " parseh [source] convert a c header file to zig extern declarations\n" + " parsec [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" @@ -132,7 +132,7 @@ enum Cmd { CmdTest, CmdVersion, CmdZen, - CmdParseH, + CmdParseC, CmdTargets, }; @@ -470,8 +470,8 @@ int main(int argc, char **argv) { cmd = CmdVersion; } else if (strcmp(arg, "zen") == 0) { cmd = CmdZen; - } else if (strcmp(arg, "parseh") == 0) { - cmd = CmdParseH; + } else if (strcmp(arg, "parsec") == 0) { + cmd = CmdParseC; } else if (strcmp(arg, "test") == 0) { cmd = CmdTest; out_type = OutTypeExe; @@ -484,7 +484,7 @@ int main(int argc, char **argv) { } else { switch (cmd) { case CmdBuild: - case CmdParseH: + case CmdParseC: case CmdTest: if (!in_file) { in_file = arg; @@ -541,13 +541,13 @@ int main(int argc, char **argv) { switch (cmd) { case CmdBuild: - case CmdParseH: + case CmdParseC: 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 == CmdParseH || cmd == CmdTest) && !in_file) { + } else if ((cmd == CmdParseC || cmd == CmdTest) && !in_file) { fprintf(stderr, "Expected source file argument.\n"); return usage(arg0); } else if (cmd == CmdBuild && out_type == OutTypeObj && objects.length != 0) { @@ -557,7 +557,7 @@ int main(int argc, char **argv) { assert(cmd != CmdBuild || out_type != OutTypeUnknown); - bool need_name = (cmd == CmdBuild || cmd == CmdParseH); + bool need_name = (cmd == CmdBuild || cmd == CmdParseC); Buf *in_file_buf = nullptr; @@ -580,7 +580,7 @@ int main(int argc, char **argv) { return usage(arg0); } - Buf *zig_root_source_file = (cmd == CmdParseH) ? nullptr : in_file_buf; + Buf *zig_root_source_file = (cmd == CmdParseC) ? nullptr : in_file_buf; Buf *full_cache_dir = buf_alloc(); os_path_resolve(buf_create_from_str("."), @@ -668,8 +668,8 @@ int main(int argc, char **argv) { if (timing_info) codegen_print_timing_report(g, stdout); return EXIT_SUCCESS; - } else if (cmd == CmdParseH) { - codegen_parseh(g, in_file_buf); + } else if (cmd == CmdParseC) { + codegen_parsec(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/parseh.cpp b/src/parsec.cpp similarity index 99% rename from src/parseh.cpp rename to src/parsec.cpp index f7e0b909c..fd39c8fc7 100644 --- a/src/parseh.cpp +++ b/src/parsec.cpp @@ -12,7 +12,7 @@ #include "error.hpp" #include "ir.hpp" #include "os.hpp" -#include "parseh.hpp" +#include "parsec.hpp" #include "parser.hpp" @@ -2250,10 +2250,10 @@ int parse_h_file(ImportTableEntry *import, ZigList *errors, const ch clang_argv.append("c"); if (c->codegen->is_native_target) { - char *ZIG_PARSEH_CFLAGS = getenv("ZIG_NATIVE_PARSEH_CFLAGS"); - if (ZIG_PARSEH_CFLAGS) { + char *ZIG_PARSEC_CFLAGS = getenv("ZIG_NATIVE_PARSEC_CFLAGS"); + if (ZIG_PARSEC_CFLAGS) { Buf tmp_buf = BUF_INIT; - char *start = ZIG_PARSEH_CFLAGS; + char *start = ZIG_PARSEC_CFLAGS; char *space = strstr(start, " "); while (space) { if (space - start > 0) { diff --git a/src/parseh.hpp b/src/parsec.hpp similarity index 90% rename from src/parseh.hpp rename to src/parsec.hpp index 3efaafcfa..62e150f43 100644 --- a/src/parseh.hpp +++ b/src/parsec.hpp @@ -6,8 +6,8 @@ */ -#ifndef ZIG_PARSEH_HPP -#define ZIG_PARSEH_HPP +#ifndef ZIG_PARSEC_HPP +#define ZIG_PARSEC_HPP #include "all_types.hpp" diff --git a/test/parseh.zig b/test/parsec.zig similarity index 99% rename from test/parseh.zig rename to test/parsec.zig index d71758bed..c0e7689bb 100644 --- a/test/parseh.zig +++ b/test/parsec.zig @@ -1,6 +1,6 @@ const tests = @import("tests.zig"); -pub fn addCases(cases: &tests.ParseHContext) { +pub fn addCases(cases: &tests.ParseCContext) { cases.addAllowWarnings("simple data types", \\#include \\int foo(char a, unsigned char b, signed char c); diff --git a/test/tests.zig b/test/tests.zig index 6e9ad014b..1a69ac055 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -17,7 +17,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 parseh = @import("parseh.zig"); +const parsec = @import("parsec.zig"); const TestTarget = struct { os: builtin.Os, @@ -115,16 +115,16 @@ pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> & return cases.step; } -pub fn addParseHTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { - const cases = %%b.allocator.create(ParseHContext); - *cases = ParseHContext { +pub fn addParseCTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { + const cases = %%b.allocator.create(ParseCContext); + *cases = ParseCContext { .b = b, - .step = b.step("test-parseh", "Run the C header file parsing tests"), + .step = b.step("test-parsec", "Run the C header file parsing tests"), .test_index = 0, .test_filter = test_filter, }; - parseh.addCases(cases); + parsec.addCases(cases); return cases.step; } @@ -752,7 +752,7 @@ pub const BuildExamplesContext = struct { } }; -pub const ParseHContext = struct { +pub const ParseCContext = struct { b: &build.Builder, step: &build.Step, test_index: usize, @@ -781,18 +781,18 @@ pub const ParseHContext = struct { } }; - const ParseHCmpOutputStep = struct { + const ParseCCmpOutputStep = struct { step: build.Step, - context: &ParseHContext, + context: &ParseCContext, name: []const u8, test_index: usize, case: &const TestCase, - pub fn create(context: &ParseHContext, name: []const u8, case: &const TestCase) -> &ParseHCmpOutputStep { + pub fn create(context: &ParseCContext, name: []const u8, case: &const TestCase) -> &ParseCCmpOutputStep { const allocator = context.b.allocator; - const ptr = %%allocator.create(ParseHCmpOutputStep); - *ptr = ParseHCmpOutputStep { - .step = build.Step.init("ParseHCmpOutput", allocator, make), + const ptr = %%allocator.create(ParseCCmpOutputStep); + *ptr = ParseCCmpOutputStep { + .step = build.Step.init("ParseCCmpOutput", allocator, make), .context = context, .name = name, .test_index = context.test_index, @@ -803,13 +803,13 @@ pub const ParseHContext = struct { } fn make(step: &build.Step) -> %void { - const self = @fieldParentPtr(ParseHCmpOutputStep, "step", step); + const self = @fieldParentPtr(ParseCCmpOutputStep, "step", step); const b = self.context.b; const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename); var zig_args = ArrayList([]const u8).init(b.allocator); - %%zig_args.append("parseh"); + %%zig_args.append("parsec"); %%zig_args.append(b.pathFromRoot(root_src)); %%io.stderr.printf("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name); @@ -855,7 +855,7 @@ pub const ParseHContext = struct { if (stderr.len != 0 and !self.case.allow_warnings) { %%io.stderr.printf( - \\====== parseh emitted warnings: ============ + \\====== parsec emitted warnings: ============ \\{} \\============================================ \\ @@ -888,7 +888,7 @@ pub const ParseHContext = struct { %%io.stderr.printf("\n"); } - pub fn create(self: &ParseHContext, allow_warnings: bool, name: []const u8, + pub fn create(self: &ParseCContext, allow_warnings: bool, name: []const u8, source: []const u8, expected_lines: ...) -> &TestCase { const tc = %%self.b.allocator.create(TestCase); @@ -906,32 +906,32 @@ pub const ParseHContext = struct { return tc; } - pub fn add(self: &ParseHContext, name: []const u8, source: []const u8, expected_lines: ...) { + pub fn add(self: &ParseCContext, name: []const u8, source: []const u8, expected_lines: ...) { const tc = self.create(false, name, source, expected_lines); self.addCase(tc); } - pub fn addAllowWarnings(self: &ParseHContext, name: []const u8, source: []const u8, expected_lines: ...) { + pub fn addAllowWarnings(self: &ParseCContext, name: []const u8, source: []const u8, expected_lines: ...) { const tc = self.create(true, name, source, expected_lines); self.addCase(tc); } - pub fn addCase(self: &ParseHContext, case: &const TestCase) { + pub fn addCase(self: &ParseCContext, case: &const TestCase) { const b = self.b; - const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "parseh {}", case.name); + const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "parsec {}", case.name); if (self.test_filter) |filter| { if (mem.indexOf(u8, annotated_case_name, filter) == null) return; } - const parseh_and_cmp = ParseHCmpOutputStep.create(self, annotated_case_name, case); - self.step.dependOn(&parseh_and_cmp.step); + const parsec_and_cmp = ParseCCmpOutputStep.create(self, annotated_case_name, case); + self.step.dependOn(&parsec_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); - parseh_and_cmp.step.dependOn(&write_src.step); + parsec_and_cmp.step.dependOn(&write_src.step); } } };