Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New preprocessor, work in progress #719

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions build/GenerateDef.zig
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ pub fn create(owner: *std.Build, options: Options) std.Build.Module.Import {
};
}

fn make(step: *Step, prog_node: std.Progress.Node) !void {
_ = prog_node;
fn make(step: *Step, options: std.Build.Step.MakeOptions) !void {
_ = options;
const b = step.owner;
const self: *GenerateDef = @fieldParentPtr("step", step);
const arena = b.allocator;
Expand Down
1 change: 1 addition & 0 deletions src/aro.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ test {
_ = @import("aro/target.zig");
_ = @import("aro/Tokenizer.zig");
_ = @import("aro/toolchains/Linux.zig");
_ = @import("aro/Treap.zig");
_ = @import("aro/Value.zig");
}
10 changes: 10 additions & 0 deletions src/aro/Diagnostics/messages.def
Original file line number Diff line number Diff line change
Expand Up @@ -2509,3 +2509,13 @@ auto_type_self_initialized
.msg = "variable '{s}' declared with deduced type '__auto_type' cannot appear in its own initializer"
.extra = .str
.kind = .@"error"

expected_left_angle_bracket
.msg = "expected '<' but got '{s}'"
.extra = .str
.kind = .@"error"

closing_paren_after
.msg = "expected '(' after '{s}'"
.extra = .str
.kind = .@"error"
33 changes: 33 additions & 0 deletions src/aro/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7097,6 +7097,10 @@ fn unExpr(p: *Parser) Error!Result {
return operand;
},
.plus_plus => {
if (p.in_macro) {
try p.err(.invalid_preproc_operator);
return error.ParsingFailed;
}
p.tok_i += 1;

var operand = try p.castExpr();
Expand All @@ -7123,6 +7127,10 @@ fn unExpr(p: *Parser) Error!Result {
return operand;
},
.minus_minus => {
if (p.in_macro) {
try p.err(.invalid_preproc_operator);
return error.ParsingFailed;
}
p.tok_i += 1;

var operand = try p.castExpr();
Expand Down Expand Up @@ -7423,6 +7431,10 @@ fn suffixExpr(p: *Parser, lhs: Result) Error!Result {
switch (p.tok_ids[p.tok_i]) {
.l_paren => return p.callExpr(lhs),
.plus_plus => {
if (p.in_macro) {
try p.err(.invalid_preproc_operator);
return error.ParsingFailed;
}
defer p.tok_i += 1;

var operand = lhs;
Expand All @@ -7441,6 +7453,10 @@ fn suffixExpr(p: *Parser, lhs: Result) Error!Result {
return operand;
},
.minus_minus => {
if (p.in_macro) {
try p.err(.invalid_preproc_operator);
return error.ParsingFailed;
}
defer p.tok_i += 1;

var operand = lhs;
Expand All @@ -7459,6 +7475,10 @@ fn suffixExpr(p: *Parser, lhs: Result) Error!Result {
return operand;
},
.l_bracket => {
if (p.in_macro) {
try p.err(.invalid_preproc_operator);
return error.ParsingFailed;
}
const l_bracket = p.tok_i;
p.tok_i += 1;
var index = try p.expr();
Expand Down Expand Up @@ -7495,11 +7515,19 @@ fn suffixExpr(p: *Parser, lhs: Result) Error!Result {
return ptr;
},
.period => {
if (p.in_macro) {
try p.err(.invalid_preproc_operator);
return error.ParsingFailed;
}
p.tok_i += 1;
const name = try p.expectIdentifier();
return p.fieldAccess(lhs, name, false);
},
.arrow => {
if (p.in_macro) {
try p.err(.invalid_preproc_operator);
return error.ParsingFailed;
}
p.tok_i += 1;
const name = try p.expectIdentifier();
if (lhs.ty.isArray()) {
Expand Down Expand Up @@ -8039,6 +8067,11 @@ fn makePredefinedIdentifier(p: *Parser, strings_top: usize) !Result {
}

fn stringLiteral(p: *Parser) Error!Result {
if (p.in_macro) {
try p.err(.invalid_preproc_expr_start);
return error.ParsingFailed;
}

var string_end = p.tok_i;
var string_kind: text_literal.Kind = .char;
while (text_literal.Kind.classify(p.tok_ids[string_end], .string_literal)) |next| : (string_end += 1) {
Expand Down
4 changes: 2 additions & 2 deletions src/aro/Pragma.zig
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ pub fn pasteTokens(pp: *Preprocessor, start_idx: TokenIndex) ![]const u8 {
.r_paren => rparen_count += 1,
.string_literal => {
if (rparen_count != 0) return error.ExpectedStringLiteral;
const str = pp.expandedSlice(tok);
try pp.char_buf.appendSlice(str[1 .. str.len - 1]);
const str = pp.tokSlice(tok);
try pp.char_buf.appendSlice(pp.gpa, str[1 .. str.len - 1]);
},
else => return error.ExpectedStringLiteral,
}
Expand Down
Loading
Loading