mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
analyze looks for root export decl only in the root source file
This commit is contained in:
parent
cd68969115
commit
31cf43de54
3 changed files with 49 additions and 41 deletions
|
|
@ -175,6 +175,7 @@ static void preview_function_declarations(CodeGen *g, ImportTableEntry *import,
|
|||
}
|
||||
break;
|
||||
case NodeTypeRootExportDecl:
|
||||
if (import == g->root_import) {
|
||||
for (int i = 0; i < node->data.root_export_decl.directives->length; i += 1) {
|
||||
AstNode *directive_node = node->data.root_export_decl.directives->at(i);
|
||||
Buf *name = &directive_node->data.directive.name;
|
||||
|
|
@ -211,6 +212,10 @@ static void preview_function_declarations(CodeGen *g, ImportTableEntry *import,
|
|||
if (g->out_type == OutTypeUnknown)
|
||||
g->out_type = export_out_type;
|
||||
}
|
||||
} else {
|
||||
add_node_error(g, node,
|
||||
buf_sprintf("root export declaration only valid in root source file"));
|
||||
}
|
||||
break;
|
||||
case NodeTypeUse:
|
||||
// nothing to do here
|
||||
|
|
@ -428,13 +433,6 @@ static void analyze_root(CodeGen *g, ImportTableEntry *import, AstNode *node) {
|
|||
analyze_top_level_declaration(g, child);
|
||||
}
|
||||
|
||||
if (!g->root_out_name) {
|
||||
add_node_error(g, node,
|
||||
buf_sprintf("missing export declaration and output name not provided"));
|
||||
} else if (g->out_type == OutTypeUnknown) {
|
||||
add_node_error(g, node,
|
||||
buf_sprintf("missing export declaration and export type not provided"));
|
||||
}
|
||||
}
|
||||
|
||||
void semantic_analyze(CodeGen *g) {
|
||||
|
|
@ -447,4 +445,12 @@ void semantic_analyze(CodeGen *g) {
|
|||
ImportTableEntry *import = entry->value;
|
||||
analyze_root(g, import, import->root);
|
||||
}
|
||||
|
||||
if (!g->root_out_name) {
|
||||
add_node_error(g, g->root_import->root,
|
||||
buf_sprintf("missing export declaration and output name not provided"));
|
||||
} else if (g->out_type == OutTypeUnknown) {
|
||||
add_node_error(g, g->root_import->root,
|
||||
buf_sprintf("missing export declaration and export type not provided"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -661,7 +661,7 @@ static void init(CodeGen *g, Buf *source_path) {
|
|||
|
||||
}
|
||||
|
||||
static void codegen_add_code(CodeGen *g, Buf *source_path, Buf *source_code) {
|
||||
static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *source_code) {
|
||||
Buf full_path = BUF_INIT;
|
||||
os_path_join(g->root_source_dir, source_path, &full_path);
|
||||
|
||||
|
|
@ -715,13 +715,14 @@ static void codegen_add_code(CodeGen *g, Buf *source_path, Buf *source_code) {
|
|||
codegen_add_code(g, &top_level_decl->data.use.path, &import_code);
|
||||
}
|
||||
}
|
||||
|
||||
return import_entry;
|
||||
}
|
||||
|
||||
void codegen_add_root_code(CodeGen *g, Buf *source_path, Buf *source_code) {
|
||||
init(g, source_path);
|
||||
|
||||
codegen_add_code(g, source_path, source_code);
|
||||
|
||||
g->root_import = codegen_add_code(g, source_path, source_code);
|
||||
|
||||
if (g->verbose) {
|
||||
fprintf(stderr, "\nSemantic Analysis:\n");
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ struct CodeGen {
|
|||
int version_minor;
|
||||
int version_patch;
|
||||
bool verbose;
|
||||
ImportTableEntry *root_import;
|
||||
};
|
||||
|
||||
struct TypeNode {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue