aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-04-28 16:04:44 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-04-28 16:04:44 -0700
commit46b0b84b90119a1eb70a30f78baa8239cafb2524 (patch)
tree8dc295fa3eb52dc966444b381724206eb4e445ff /src/parser.cpp
parenta299de2265ae1fc2da31214725ea5bf399848319 (diff)
downloadzig-46b0b84b90119a1eb70a30f78baa8239cafb2524.tar.gz
zig-46b0b84b90119a1eb70a30f78baa8239cafb2524.zip
ability to specify body of an extern function
closes #101
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 311bbe093a..603bb990b9 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -2414,27 +2414,46 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mand
}
/*
-FnDef = option("inline") FnProto Block
+FnDef = option("inline" | "extern") FnProto Block
*/
static AstNode *ast_parse_fn_def(ParseContext *pc, int *token_index, bool mandatory,
ZigList<AstNode*> *directives, VisibMod visib_mod)
{
Token *first_token = &pc->tokens->at(*token_index);
bool is_inline;
+ bool is_extern;
if (first_token->id == TokenIdKeywordInline) {
*token_index += 1;
is_inline = true;
+ is_extern = false;
+ } else if (first_token->id == TokenIdKeywordExtern) {
+ *token_index += 1;
+ is_extern = true;
+ is_inline = false;
} else {
is_inline = false;
+ is_extern = false;
}
AstNode *fn_proto = ast_parse_fn_proto(pc, token_index, mandatory, directives, visib_mod);
- if (!fn_proto)
+ if (!fn_proto) {
+ if (is_inline || is_extern) {
+ *token_index -= 1;
+ }
return nullptr;
- AstNode *node = ast_create_node(pc, NodeTypeFnDef, first_token);
+ }
fn_proto->data.fn_proto.is_inline = is_inline;
+ fn_proto->data.fn_proto.is_extern = is_extern;
+ Token *semi_token = &pc->tokens->at(*token_index);
+ if (semi_token->id == TokenIdSemicolon) {
+ *token_index += 1;
+ normalize_parent_ptrs(fn_proto);
+ return fn_proto;
+ }
+
+ AstNode *node = ast_create_node(pc, NodeTypeFnDef, first_token);
node->data.fn_def.fn_proto = fn_proto;
node->data.fn_def.body = ast_parse_block(pc, token_index, true);
normalize_parent_ptrs(node);