aboutsummaryrefslogtreecommitdiff
path: root/src-self-hosted/module.zig
diff options
context:
space:
mode:
authortgschultz <tgschultz@gmail.com>2018-05-11 21:36:02 -0500
committerGitHub <noreply@github.com>2018-05-11 21:36:02 -0500
commit8c1872543c8cf76215cc4bf3ced4637bb1065a4e (patch)
tree72dfebb643ab61579e3fb8dd58cd4610ffe876fa /src-self-hosted/module.zig
parent7186e92c86982950d0aa7c0c2deef9ef96bc1264 (diff)
parent6e821078f625a03eb8b7794c983da0f7793366ab (diff)
downloadzig-8c1872543c8cf76215cc4bf3ced4637bb1065a4e.tar.gz
zig-8c1872543c8cf76215cc4bf3ced4637bb1065a4e.zip
Merge pull request #1 from zig-lang/master
Sync with zig-lang/zig master
Diffstat (limited to 'src-self-hosted/module.zig')
-rw-r--r--src-self-hosted/module.zig46
1 files changed, 25 insertions, 21 deletions
diff --git a/src-self-hosted/module.zig b/src-self-hosted/module.zig
index 464737bbbb..ccbd683bdc 100644
--- a/src-self-hosted/module.zig
+++ b/src-self-hosted/module.zig
@@ -8,9 +8,7 @@ const c = @import("c.zig");
const builtin = @import("builtin");
const Target = @import("target.zig").Target;
const warn = std.debug.warn;
-const Tokenizer = std.zig.Tokenizer;
const Token = std.zig.Token;
-const Parser = std.zig.Parser;
const ArrayList = std.ArrayList;
pub const Module = struct {
@@ -109,6 +107,29 @@ pub const Module = struct {
LlvmIr,
};
+ pub const CliPkg = struct {
+ name: []const u8,
+ path: []const u8,
+ children: ArrayList(&CliPkg),
+ parent: ?&CliPkg,
+
+ pub fn init(allocator: &mem.Allocator, name: []const u8, path: []const u8, parent: ?&CliPkg) !&CliPkg {
+ var pkg = try allocator.create(CliPkg);
+ pkg.name = name;
+ pkg.path = path;
+ pkg.children = ArrayList(&CliPkg).init(allocator);
+ pkg.parent = parent;
+ return pkg;
+ }
+
+ pub fn deinit(self: &CliPkg) void {
+ for (self.children.toSliceConst()) |child| {
+ child.deinit();
+ }
+ self.children.deinit();
+ }
+ };
+
pub fn create(allocator: &mem.Allocator, name: []const u8, root_src_path: ?[]const u8, target: &const Target,
kind: Kind, build_mode: builtin.Mode, zig_lib_dir: []const u8, cache_dir: []const u8) !&Module
{
@@ -223,34 +244,17 @@ pub const Module = struct {
warn("{}", source_code);
- warn("====tokenization:====\n");
- {
- var tokenizer = Tokenizer.init(source_code);
- while (true) {
- const token = tokenizer.next();
- tokenizer.dump(token);
- if (token.id == Token.Id.Eof) {
- break;
- }
- }
- }
-
warn("====parse:====\n");
- var tokenizer = Tokenizer.init(source_code);
- var parser = Parser.init(&tokenizer, self.allocator, root_src_real_path);
- defer parser.deinit();
-
- var tree = try parser.parse();
+ var tree = try std.zig.parse(self.allocator, source_code);
defer tree.deinit();
var stderr_file = try std.io.getStdErr();
var stderr_file_out_stream = std.io.FileOutStream.init(&stderr_file);
const out_stream = &stderr_file_out_stream.stream;
- try parser.renderAst(out_stream, tree.root_node);
warn("====fmt:====\n");
- try parser.renderSource(out_stream, tree.root_node);
+ try std.zig.render(self.allocator, out_stream, &tree);
warn("====ir:====\n");
warn("TODO\n\n");