aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-12-31 16:55:41 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-12-31 16:55:41 -0500
commit39ee3bc0ecdfde43e6fa98ee454a0115b3cb7390 (patch)
treefbf0005f5e8840006d6ce7c6bde29cd050dd42fe /lib
parentc8c65b0168ae18f8bd8bf8f38590109a30df73a8 (diff)
parent950eb81304dedc01ef1500dd2da1458694306b00 (diff)
downloadzig-39ee3bc0ecdfde43e6fa98ee454a0115b3cb7390.tar.gz
zig-39ee3bc0ecdfde43e6fa98ee454a0115b3cb7390.zip
Merge branch 'stage-2-cimport' of https://github.com/Vexu/zig into Vexu-stage-2-cimport
Diffstat (limited to 'lib')
-rw-r--r--lib/std/zig/ast.zig95
-rw-r--r--lib/std/zig/render.zig2
2 files changed, 50 insertions, 47 deletions
diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig
index 349ae914c4..adbcef165e 100644
--- a/lib/std/zig/ast.zig
+++ b/lib/std/zig/ast.zig
@@ -13,6 +13,7 @@ pub const Tree = struct {
root_node: *Node.Root,
arena_allocator: std.heap.ArenaAllocator,
errors: ErrorList,
+ generated: bool = false,
pub const TokenList = SegmentedList(Token, 64);
pub const ErrorList = SegmentedList(Error, 0);
@@ -58,6 +59,8 @@ pub const Tree = struct {
.line_start = start_index,
.line_end = self.source.len,
};
+ if (self.generated)
+ return loc;
const token_start = token.start;
for (self.source[start_index..]) |c, i| {
if (i + start_index == token_start) {
@@ -581,7 +584,7 @@ pub const Node = struct {
}
pub const Root = struct {
- base: Node = Node {.id = .Root},
+ base: Node = Node{ .id = .Root },
decls: DeclList,
eof_token: TokenIndex,
@@ -604,7 +607,7 @@ pub const Node = struct {
};
pub const VarDecl = struct {
- base: Node = Node {.id = .VarDecl},
+ base: Node = Node{ .id = .VarDecl },
doc_comments: ?*DocComment,
visib_token: ?TokenIndex,
thread_local_token: ?TokenIndex,
@@ -661,7 +664,7 @@ pub const Node = struct {
};
pub const Use = struct {
- base: Node = Node {.id = .Use},
+ base: Node = Node{ .id = .Use },
doc_comments: ?*DocComment,
visib_token: ?TokenIndex,
use_token: TokenIndex,
@@ -688,7 +691,7 @@ pub const Node = struct {
};
pub const ErrorSetDecl = struct {
- base: Node = Node {.id = .ErrorSetDecl},
+ base: Node = Node{ .id = .ErrorSetDecl },
error_token: TokenIndex,
decls: DeclList,
rbrace_token: TokenIndex,
@@ -714,7 +717,7 @@ pub const Node = struct {
};
pub const ContainerDecl = struct {
- base: Node = Node {.id = .ContainerDecl},
+ base: Node = Node{ .id = .ContainerDecl },
layout_token: ?TokenIndex,
kind_token: TokenIndex,
init_arg_expr: InitArg,
@@ -801,7 +804,7 @@ pub const Node = struct {
};
pub const ErrorTag = struct {
- base: Node = Node {.id = .ErrorTag},
+ base: Node = Node{ .id = .ErrorTag },
doc_comments: ?*DocComment,
name_token: TokenIndex,
@@ -826,7 +829,7 @@ pub const Node = struct {
};
pub const Identifier = struct {
- base: Node = Node {.id = .Identifier},
+ base: Node = Node{ .id = .Identifier },
token: TokenIndex,
pub fn iterate(self: *Identifier, index: usize) ?*Node {
@@ -843,7 +846,7 @@ pub const Node = struct {
};
pub const FnProto = struct {
- base: Node = Node {.id = .FnProto},
+ base: Node = Node{ .id = .FnProto },
doc_comments: ?*DocComment,
visib_token: ?TokenIndex,
fn_token: TokenIndex,
@@ -925,7 +928,7 @@ pub const Node = struct {
};
pub const AnyFrameType = struct {
- base: Node = Node {.id = .AnyFrameType},
+ base: Node = Node{ .id = .AnyFrameType },
anyframe_token: TokenIndex,
result: ?Result,
@@ -956,7 +959,7 @@ pub const Node = struct {
};
pub const ParamDecl = struct {
- base: Node = Node {.id = .ParamDecl},
+ base: Node = Node{ .id = .ParamDecl },
doc_comments: ?*DocComment,
comptime_token: ?TokenIndex,
noalias_token: ?TokenIndex,
@@ -989,7 +992,7 @@ pub const Node = struct {
};
pub const Block = struct {
- base: Node = Node {.id = .Block},
+ base: Node = Node{ .id = .Block },
label: ?TokenIndex,
lbrace: TokenIndex,
statements: StatementList,
@@ -1020,7 +1023,7 @@ pub const Node = struct {
};
pub const Defer = struct {
- base: Node = Node {.id = .Defer},
+ base: Node = Node{ .id = .Defer },
defer_token: TokenIndex,
expr: *Node,
@@ -1043,7 +1046,7 @@ pub const Node = struct {
};
pub const Comptime = struct {
- base: Node = Node {.id = .Comptime},
+ base: Node = Node{ .id = .Comptime },
doc_comments: ?*DocComment,
comptime_token: TokenIndex,
expr: *Node,
@@ -1067,7 +1070,7 @@ pub const Node = struct {
};
pub const Payload = struct {
- base: Node = Node {.id = .Payload},
+ base: Node = Node{ .id = .Payload },
lpipe: TokenIndex,
error_symbol: *Node,
rpipe: TokenIndex,
@@ -1091,7 +1094,7 @@ pub const Node = struct {
};
pub const PointerPayload = struct {
- base: Node = Node {.id = .PointerPayload},
+ base: Node = Node{ .id = .PointerPayload },
lpipe: TokenIndex,
ptr_token: ?TokenIndex,
value_symbol: *Node,
@@ -1116,7 +1119,7 @@ pub const Node = struct {
};
pub const PointerIndexPayload = struct {
- base: Node = Node {.id = .PointerIndexPayload},
+ base: Node = Node{ .id = .PointerIndexPayload },
lpipe: TokenIndex,
ptr_token: ?TokenIndex,
value_symbol: *Node,
@@ -1147,7 +1150,7 @@ pub const Node = struct {
};
pub const Else = struct {
- base: Node = Node {.id = .Else},
+ base: Node = Node{ .id = .Else },
else_token: TokenIndex,
payload: ?*Node,
body: *Node,
@@ -1176,7 +1179,7 @@ pub const Node = struct {
};
pub const Switch = struct {
- base: Node = Node {.id = .Switch},
+ base: Node = Node{ .id = .Switch },
switch_token: TokenIndex,
expr: *Node,
@@ -1208,7 +1211,7 @@ pub const Node = struct {
};
pub const SwitchCase = struct {
- base: Node = Node {.id = .SwitchCase},
+ base: Node = Node{ .id = .SwitchCase },
items: ItemList,
arrow_token: TokenIndex,
payload: ?*Node,
@@ -1243,7 +1246,7 @@ pub const Node = struct {
};
pub const SwitchElse = struct {
- base: Node = Node {.id = .SwitchElse},
+ base: Node = Node{ .id = .SwitchElse },
token: TokenIndex,
pub fn iterate(self: *SwitchElse, index: usize) ?*Node {
@@ -1260,7 +1263,7 @@ pub const Node = struct {
};
pub const While = struct {
- base: Node = Node {.id = .While},
+ base: Node = Node{ .id = .While },
label: ?TokenIndex,
inline_token: ?TokenIndex,
while_token: TokenIndex,
@@ -1319,7 +1322,7 @@ pub const Node = struct {
};
pub const For = struct {
- base: Node = Node {.id = .For},
+ base: Node = Node{ .id = .For },
label: ?TokenIndex,
inline_token: ?TokenIndex,
for_token: TokenIndex,
@@ -1370,7 +1373,7 @@ pub const Node = struct {
};
pub const If = struct {
- base: Node = Node {.id = .If},
+ base: Node = Node{ .id = .If },
if_token: TokenIndex,
condition: *Node,
payload: ?*Node,
@@ -1413,7 +1416,7 @@ pub const Node = struct {
};
pub const InfixOp = struct {
- base: Node = Node {.id = .InfixOp},
+ base: Node = Node{ .id = .InfixOp },
op_token: TokenIndex,
lhs: *Node,
op: Op,
@@ -1646,7 +1649,7 @@ pub const Node = struct {
};
pub const FieldInitializer = struct {
- base: Node = Node {.id = .FieldInitializer},
+ base: Node = Node{ .id = .FieldInitializer },
period_token: TokenIndex,
name_token: TokenIndex,
expr: *Node,
@@ -1670,7 +1673,7 @@ pub const Node = struct {
};
pub const SuffixOp = struct {
- base: Node = Node {.id = .SuffixOp},
+ base: Node = Node{ .id = .SuffixOp },
lhs: Lhs,
op: Op,
rtoken: TokenIndex,
@@ -1771,7 +1774,7 @@ pub const Node = struct {
};
pub const GroupedExpression = struct {
- base: Node = Node {.id = .GroupedExpression},
+ base: Node = Node{ .id = .GroupedExpression },
lparen: TokenIndex,
expr: *Node,
rparen: TokenIndex,
@@ -1795,7 +1798,7 @@ pub const Node = struct {
};
pub const ControlFlowExpression = struct {
- base: Node = Node {.id = .ControlFlowExpression},
+ base: Node = Node{ .id = .ControlFlowExpression },
ltoken: TokenIndex,
kind: Kind,
rhs: ?*Node,
@@ -1861,7 +1864,7 @@ pub const Node = struct {
};
pub const Suspend = struct {
- base: Node = Node {.id = .Suspend},
+ base: Node = Node{ .id = .Suspend },
suspend_token: TokenIndex,
body: ?*Node,
@@ -1890,7 +1893,7 @@ pub const Node = struct {
};
pub const IntegerLiteral = struct {
- base: Node = Node {.id = .IntegerLiteral},
+ base: Node = Node{ .id = .IntegerLiteral },
token: TokenIndex,
pub fn iterate(self: *IntegerLiteral, index: usize) ?*Node {
@@ -1907,7 +1910,7 @@ pub const Node = struct {
};
pub const EnumLiteral = struct {
- base: Node = Node {.id = .EnumLiteral},
+ base: Node = Node{ .id = .EnumLiteral },
dot: TokenIndex,
name: TokenIndex,
@@ -1925,7 +1928,7 @@ pub const Node = struct {
};
pub const FloatLiteral = struct {
- base: Node = Node {.id = .FloatLiteral},
+ base: Node = Node{ .id = .FloatLiteral },
token: TokenIndex,
pub fn iterate(self: *FloatLiteral, index: usize) ?*Node {
@@ -1942,7 +1945,7 @@ pub const Node = struct {
};
pub const BuiltinCall = struct {
- base: Node = Node {.id = .BuiltinCall},
+ base: Node = Node{ .id = .BuiltinCall },
builtin_token: TokenIndex,
params: ParamList,
rparen_token: TokenIndex,
@@ -1968,7 +1971,7 @@ pub const Node = struct {
};
pub const StringLiteral = struct {
- base: Node = Node {.id = .StringLiteral},
+ base: Node = Node{ .id = .StringLiteral },
token: TokenIndex,
pub fn iterate(self: *StringLiteral, index: usize) ?*Node {
@@ -1985,7 +1988,7 @@ pub const Node = struct {
};
pub const MultilineStringLiteral = struct {
- base: Node = Node {.id = .MultilineStringLiteral},
+ base: Node = Node{ .id = .MultilineStringLiteral },
lines: LineList,
pub const LineList = SegmentedList(TokenIndex, 4);
@@ -2004,7 +2007,7 @@ pub const Node = struct {
};
pub const CharLiteral = struct {
- base: Node = Node {.id = .CharLiteral},
+ base: Node = Node{ .id = .CharLiteral },
token: TokenIndex,
pub fn iterate(self: *CharLiteral, index: usize) ?*Node {
@@ -2021,7 +2024,7 @@ pub const Node = struct {
};
pub const BoolLiteral = struct {
- base: Node = Node {.id = .BoolLiteral},
+ base: Node = Node{ .id = .BoolLiteral },
token: TokenIndex,
pub fn iterate(self: *BoolLiteral, index: usize) ?*Node {
@@ -2038,7 +2041,7 @@ pub const Node = struct {
};
pub const NullLiteral = struct {
- base: Node = Node {.id = .NullLiteral},
+ base: Node = Node{ .id = .NullLiteral },
token: TokenIndex,
pub fn iterate(self: *NullLiteral, index: usize) ?*Node {
@@ -2055,7 +2058,7 @@ pub const Node = struct {
};
pub const UndefinedLiteral = struct {
- base: Node = Node {.id = .UndefinedLiteral},
+ base: Node = Node{ .id = .UndefinedLiteral },
token: TokenIndex,
pub fn iterate(self: *UndefinedLiteral, index: usize) ?*Node {
@@ -2072,7 +2075,7 @@ pub const Node = struct {
};
pub const AsmOutput = struct {
- base: Node = Node {.id = .AsmOutput},
+ base: Node = Node{ .id = .AsmOutput },
lbracket: TokenIndex,
symbolic_name: *Node,
constraint: *Node,
@@ -2117,7 +2120,7 @@ pub const Node = struct {
};
pub const AsmInput = struct {
- base: Node = Node {.id = .AsmInput},
+ base: Node = Node{ .id = .AsmInput },
lbracket: TokenIndex,
symbolic_name: *Node,
constraint: *Node,
@@ -2149,7 +2152,7 @@ pub const Node = struct {
};
pub const Asm = struct {
- base: Node = Node {.id = .Asm},
+ base: Node = Node{ .id = .Asm },
asm_token: TokenIndex,
volatile_token: ?TokenIndex,
template: *Node,
@@ -2184,7 +2187,7 @@ pub const Node = struct {
};
pub const Unreachable = struct {
- base: Node = Node {.id = .Unreachable},
+ base: Node = Node{ .id = .Unreachable },
token: TokenIndex,
pub fn iterate(self: *Unreachable, index: usize) ?*Node {
@@ -2201,7 +2204,7 @@ pub const Node = struct {
};
pub const ErrorType = struct {
- base: Node = Node {.id = .ErrorType},
+ base: Node = Node{ .id = .ErrorType },
token: TokenIndex,
pub fn iterate(self: *ErrorType, index: usize) ?*Node {
@@ -2235,7 +2238,7 @@ pub const Node = struct {
};
pub const DocComment = struct {
- base: Node = Node {.id = .DocComment},
+ base: Node = Node{ .id = .DocComment },
lines: LineList,
pub const LineList = SegmentedList(TokenIndex, 4);
@@ -2254,7 +2257,7 @@ pub const Node = struct {
};
pub const TestDecl = struct {
- base: Node = Node {.id = .TestDecl},
+ base: Node = Node{ .id = .TestDecl },
doc_comments: ?*DocComment,
test_token: TokenIndex,
name: *Node,
diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig
index d65d9bfc57..6e1ee4a601 100644
--- a/lib/std/zig/render.zig
+++ b/lib/std/zig/render.zig
@@ -643,7 +643,7 @@ fn renderExpression(
},
.ArrayAccess => |index_expr| {
- const lbracket = tree.prevToken(index_expr.firstToken());
+ const lbracket = tree.nextToken(suffix_op.lhs.node.lastToken());
const rbracket = tree.nextToken(index_expr.lastToken());
try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs.node, Space.None);