Move compile result stuff out of specific stages.
This commit is contained in:
@@ -140,7 +140,7 @@ Semantic_Checker :: struct {
|
||||
|
||||
current_scope : Scope_Handle;
|
||||
|
||||
result_file : *Compiled_File;
|
||||
result : *Compile_Result;
|
||||
|
||||
current_buffer_index : u32 = 0;
|
||||
current_sampler_index : u32 = 0;
|
||||
@@ -451,7 +451,7 @@ Attempting to access a field on a primitive type '%'.
|
||||
init_string_builder(*builder,, temp);
|
||||
|
||||
variable := from_handle(checker, handle);
|
||||
print_to_builder(*builder, "Attempting to access a field on a primitive type '%'.\n", proper_type_to_string(checker.result_file.type_variables, variable));
|
||||
print_to_builder(*builder, "Attempting to access a field on a primitive type '%'.\n", proper_type_to_string(checker.result.type_variables, variable));
|
||||
|
||||
indent(*builder, 1);
|
||||
cyan(*builder);
|
||||
@@ -512,7 +512,7 @@ if_condition_has_to_be_boolean_type :: (checker : *Semantic_Checker, usage_site
|
||||
usage_child := usage_site.children[0];
|
||||
usage_loc := usage_child.source_location;
|
||||
|
||||
print_to_builder(*builder, "% has type %\n", print_from_source_location(*usage_loc), proper_type_to_string(checker.result_file.type_variables, var));
|
||||
print_to_builder(*builder, "% has type %\n", print_from_source_location(*usage_loc), proper_type_to_string(checker.result.type_variables, var));
|
||||
|
||||
message := builder_to_string(*builder,, temp);
|
||||
record_error(checker, message, usage_site.source_location, false);
|
||||
@@ -554,7 +554,7 @@ type_mismatch :: (checker : *Semantic_Checker, usage_site : *AST_Node, expect_no
|
||||
indent(*builder, 1);
|
||||
print_to_builder(*builder, "expected:\n");
|
||||
indent(*builder, 2);
|
||||
proper_type_to_string(*builder, checker.result_file.type_variables, expect_var);
|
||||
proper_type_to_string(*builder, checker.result.type_variables, expect_var);
|
||||
append(*builder, "\n");
|
||||
|
||||
// indent(*builder, 2);
|
||||
@@ -617,10 +617,10 @@ use_scope :: (checker : *Semantic_Checker, handle : Scope_Handle) -> Scope_Handl
|
||||
|
||||
push_scope :: (checker : *Semantic_Checker, name := "", kind : Scope_Kind = .Global) -> *Scope, Scope_Handle {
|
||||
new_scope : Scope;
|
||||
array_add(*checker.result_file.scope_stack.stack, new_scope);
|
||||
array_add(*checker.result.scope_stack.stack, new_scope);
|
||||
|
||||
count := checker.result_file.scope_stack.stack.count;
|
||||
scope := *checker.result_file.scope_stack.stack[count - 1];
|
||||
count := checker.result.scope_stack.stack.count;
|
||||
scope := *checker.result.scope_stack.stack[count - 1];
|
||||
scope.parent = checker.current_scope;
|
||||
scope.name = name;
|
||||
scope.kind = kind;
|
||||
@@ -628,7 +628,7 @@ push_scope :: (checker : *Semantic_Checker, name := "", kind : Scope_Kind = .Glo
|
||||
scope.builtin = true;
|
||||
}
|
||||
|
||||
scope.children.allocator = checker.result_file.scope_stack.allocator;
|
||||
scope.children.allocator = checker.result.scope_stack.allocator;
|
||||
|
||||
if checker.current_scope {
|
||||
scope := get_current_scope(checker);
|
||||
@@ -651,12 +651,12 @@ pop_scope :: (checker : *Semantic_Checker) -> Scope_Handle {
|
||||
}
|
||||
|
||||
peek_scope :: (checker : *Semantic_Checker) -> *Scope, Scope_Handle {
|
||||
if checker.result_file.scope_stack.stack.count == 0 {
|
||||
if checker.result.scope_stack.stack.count == 0 {
|
||||
return null, 0;
|
||||
}
|
||||
|
||||
count := checker.result_file.scope_stack.stack.count;
|
||||
scope := *checker.result_file.scope_stack.stack[count - 1];
|
||||
count := checker.result.scope_stack.stack.count;
|
||||
scope := *checker.result.scope_stack.stack[count - 1];
|
||||
return scope, xx count;
|
||||
}
|
||||
|
||||
@@ -673,7 +673,7 @@ get_scope :: (scope_stack : Scope_Stack, handle : Scope_Handle) -> *Scope {
|
||||
}
|
||||
|
||||
get_scope :: (checker : *Semantic_Checker, handle : Scope_Handle) -> *Scope {
|
||||
return get_scope(*checker.result_file.scope_stack, handle);
|
||||
return get_scope(*checker.result.scope_stack, handle);
|
||||
}
|
||||
|
||||
add_symbol_to_scope :: (state : Checker_State, scope_stack : *Scope_Stack, scope_handle : Scope_Handle, name : string, symbol : Defined_Symbol) -> *Defined_Symbol {
|
||||
@@ -695,8 +695,8 @@ add_symbol_to_scope :: (state : Checker_State, scope_stack : *Scope_Stack, scope
|
||||
|
||||
new_type_variable :: (checker : *Semantic_Checker) -> *Type_Variable, Type_Variable_Handle {
|
||||
variable : Type_Variable;
|
||||
handle := cast(Type_Variable_Handle)checker.result_file.type_variables.count + 1;
|
||||
array_add(*checker.result_file.type_variables, variable);
|
||||
handle := cast(Type_Variable_Handle)checker.result.type_variables.count + 1;
|
||||
array_add(*checker.result.type_variables, variable);
|
||||
|
||||
return from_handle(checker, handle), handle;
|
||||
}
|
||||
@@ -725,10 +725,10 @@ init_semantic_checker :: (checker : *Semantic_Checker, root : *AST_Node, path :
|
||||
checker.path = path;
|
||||
|
||||
// @Incomplete(niels): Use other allocator and/or add static array with convenience functions
|
||||
array_reserve(*checker.result_file.type_variables, 2048);
|
||||
array_reserve(*checker.result.type_variables, 2048);
|
||||
|
||||
checker.result_file.scope_stack.allocator = make_arena(*checker.result_file.scope_stack.arena);
|
||||
array_reserve(*checker.result_file.scope_stack.stack, 256);
|
||||
checker.result.scope_stack.allocator = make_arena(*checker.result.scope_stack.arena);
|
||||
array_reserve(*checker.result.scope_stack.stack, 256);
|
||||
|
||||
global_scope, global_handle := push_scope(checker, kind = .Global);
|
||||
array_reserve(*global_scope.children, 2048);
|
||||
@@ -754,7 +754,7 @@ find_symbol :: (scope_stack : Scope_Stack, name : string, current_scope : Scope_
|
||||
}
|
||||
|
||||
find_symbol :: (checker : *Semantic_Checker, name : string, current_scope : Scope_Handle, containing_scope : *Scope_Handle = null) -> *Defined_Symbol {
|
||||
return find_symbol(checker.result_file.scope_stack, name, current_scope, containing_scope);
|
||||
return find_symbol(checker.result.scope_stack, name, current_scope, containing_scope);
|
||||
}
|
||||
|
||||
find_symbol :: (name : string, checker : *Semantic_Checker, containing_scope : *Scope_Handle = null) -> *Defined_Symbol {
|
||||
@@ -767,7 +767,7 @@ from_handle :: (variables : []Type_Variable, handle : Type_Variable_Handle) -> *
|
||||
}
|
||||
|
||||
from_handle :: (checker : *Semantic_Checker, handle : Type_Variable_Handle) -> *Type_Variable {
|
||||
return from_handle(checker.result_file.type_variables, handle);
|
||||
return from_handle(checker.result.type_variables, handle);
|
||||
}
|
||||
|
||||
proper_type_to_string :: (builder : *String_Builder, variables : []Type_Variable, var : Type_Variable) {
|
||||
@@ -842,7 +842,6 @@ proper_type_to_string :: (variables : []Type_Variable, var : Type_Variable, allo
|
||||
|
||||
return "______not proper type______";
|
||||
}
|
||||
|
||||
|
||||
get_type_from_identifier :: (checker : *Semantic_Checker, scope : Scope_Handle, node : *AST_Node, typename : *string = null) -> Type_Kind {
|
||||
type_string := node.token.ident_value;
|
||||
@@ -872,10 +871,6 @@ get_type_from_identifier :: (checker : *Semantic_Checker, scope : Scope_Handle,
|
||||
return .Invalid;
|
||||
}
|
||||
|
||||
check_expression :: (node : *AST_Node, checker : *Semantic_Checker) -> Type_Variable_Handle {
|
||||
return 0;
|
||||
}
|
||||
|
||||
check_block :: (checker : *Semantic_Checker, node : *AST_Node) {
|
||||
for child : node.children {
|
||||
check_node(checker, child);
|
||||
@@ -898,7 +893,7 @@ declare_struct :: (checker : *Semantic_Checker, node : *AST_Node, name : string)
|
||||
symbol.name = name;
|
||||
symbol.source_node = node;
|
||||
symbol.type_variable = handle;
|
||||
add_symbol_to_scope(checker.state, *checker.result_file.scope_stack, checker.current_scope, name, symbol);
|
||||
add_symbol_to_scope(checker.state, *checker.result.scope_stack, checker.current_scope, name, symbol);
|
||||
} else {
|
||||
symbol_redeclaration(checker, node, find_result);
|
||||
return 0;
|
||||
@@ -933,7 +928,7 @@ declare_properties :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Va
|
||||
name := ifx node.name.count == 0 then "properties" else node.name;
|
||||
|
||||
if node.name.count > 0 {
|
||||
checker.result_file.property_name = name;
|
||||
checker.result.property_name = name;
|
||||
}
|
||||
type_var := declare_struct(checker, node, name);
|
||||
var := from_handle(checker, type_var);
|
||||
@@ -950,7 +945,7 @@ declare_cbuffer :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Varia
|
||||
var.type = .CBuffer;
|
||||
var.resource_index = checker.current_buffer_index;
|
||||
checker.current_buffer_index += 1;
|
||||
array_add(*checker.result_file.constant_buffers, type_var);
|
||||
array_add(*checker.result.constant_buffers, type_var);
|
||||
return type_var;
|
||||
}
|
||||
|
||||
@@ -986,11 +981,11 @@ declare_function :: (checker : *Semantic_Checker, node : *AST_Node, builtin : bo
|
||||
name_to_check := get_actual_function_name(node);
|
||||
|
||||
if node.vertex_entry_point {
|
||||
checker.result_file.vertex_entry_point.node = node;
|
||||
checker.result.vertex_entry_point.node = node;
|
||||
}
|
||||
|
||||
if node.pixel_entry_point {
|
||||
checker.result_file.pixel_entry_point.node = node;
|
||||
checker.result.pixel_entry_point.node = node;
|
||||
}
|
||||
find_result := find_symbol(checker, name_to_check, checker.current_scope);
|
||||
|
||||
@@ -1007,7 +1002,7 @@ declare_function :: (checker : *Semantic_Checker, node : *AST_Node, builtin : bo
|
||||
array_reserve(*symbol.functions, 32);
|
||||
array_add(*symbol.functions, function);
|
||||
|
||||
add_symbol_to_scope(checker.state, *checker.result_file.scope_stack, checker.current_scope, name_to_check, symbol);
|
||||
add_symbol_to_scope(checker.state, *checker.result.scope_stack, checker.current_scope, name_to_check, symbol);
|
||||
} else {
|
||||
//@Note(niels): This is some ugly code, but it's probably fine for now.
|
||||
field_list := node.children[0];
|
||||
@@ -1244,7 +1239,7 @@ check_field :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_
|
||||
symbol.name = node.name;
|
||||
symbol.source_node = node;
|
||||
symbol.type_variable = handle;
|
||||
add_symbol_to_scope(checker.state, *checker.result_file.scope_stack, checker.current_scope, node.name, symbol);
|
||||
add_symbol_to_scope(checker.state, *checker.result.scope_stack, checker.current_scope, node.name, symbol);
|
||||
} else {
|
||||
symbol_redeclaration(checker, node, find_result);
|
||||
return 0;
|
||||
@@ -1672,7 +1667,7 @@ types_compatible :: (checker : *Semantic_Checker, lhs : Type_Variable_Handle, rh
|
||||
// //~ Functions
|
||||
// }
|
||||
|
||||
add_hlsl_builtins :: (checker : *Semantic_Checker) {
|
||||
add_builtins :: (checker : *Semantic_Checker) {
|
||||
source_location := #location().fully_pathed_filename;
|
||||
path_array := split(source_location, "/");
|
||||
|
||||
@@ -1682,11 +1677,11 @@ add_hlsl_builtins :: (checker : *Semantic_Checker) {
|
||||
append(*sb, "/");
|
||||
}
|
||||
|
||||
append(*sb, "hlsl_builtin.ink");
|
||||
append(*sb, "builtins.ink");
|
||||
|
||||
path := builder_to_string(*sb);
|
||||
|
||||
HLSL_BUILTIN, ok := read_entire_file(path);
|
||||
BUILTIN, ok := read_entire_file(path);
|
||||
|
||||
if !ok {
|
||||
messages : [..]Compiler_Message;
|
||||
@@ -1698,36 +1693,36 @@ add_hlsl_builtins :: (checker : *Semantic_Checker) {
|
||||
|
||||
checker.state = .Adding_Builtins;
|
||||
|
||||
add_file_from_string(checker.result, BUILTIN);
|
||||
|
||||
lexer : Lexer;
|
||||
|
||||
lex(checker.result);
|
||||
parse(checker.result);
|
||||
type_check(checker, checker.result.root);
|
||||
|
||||
init_lexer_from_string(*lexer, HLSL_BUILTIN);
|
||||
if lexer.result.had_error {
|
||||
print("%\n", report_messages(lexer.result.messages));
|
||||
return;
|
||||
}
|
||||
|
||||
lex_result := lex(*lexer,, *temp);
|
||||
if lex_result.had_error {
|
||||
print("%\n", report_messages(lex_result.messages));
|
||||
return;
|
||||
}
|
||||
// lex_result := lex(*lexer,, *temp);
|
||||
// if lex_result.had_error {
|
||||
// print("%\n", report_messages(lex_result.messages));
|
||||
// return;
|
||||
// }
|
||||
|
||||
parse_state : Parse_State;
|
||||
init_parse_state(*parse_state, lex_result.tokens, lexer.path);
|
||||
// parse_state : Parse_State;
|
||||
// init_parse_state(*parse_state, lex_result.tokens, lexer.path);
|
||||
|
||||
parse_result := parse(*parse_state);
|
||||
if parse_result.had_error {
|
||||
print("%\n", report_messages(parse_result.messages));
|
||||
return;
|
||||
}
|
||||
// parse_result := parse(*parse_state);
|
||||
// if parse_result.had_error {
|
||||
// print("%\n", report_messages(parse_result.messages));
|
||||
// return;
|
||||
// }
|
||||
|
||||
type_check(checker, parse_result.root);
|
||||
if checker.had_error {
|
||||
print("%\n", report_messages(checker.messages));
|
||||
return;
|
||||
}
|
||||
// type_check(checker, parse_result.root);
|
||||
// if checker.had_error {
|
||||
// print("%\n", report_messages(checker.messages));
|
||||
// return;
|
||||
// }
|
||||
|
||||
for *type_var : checker.result_file.type_variables {
|
||||
for *type_var : checker.result.type_variables {
|
||||
type_var.builtin = true;
|
||||
}
|
||||
|
||||
@@ -1743,25 +1738,28 @@ check :: (result : *Compile_Result) {
|
||||
return;
|
||||
}
|
||||
|
||||
for *file : result.files {
|
||||
checker : Semantic_Checker;
|
||||
checker : Semantic_Checker;
|
||||
|
||||
checker.current_buffer_index = 0;
|
||||
checker.current_sampler_index = 0;
|
||||
checker.current_texture_index = 0;
|
||||
checker.result_file = file;
|
||||
array_reserve(*checker.messages, 32);
|
||||
checker.current_buffer_index = 0;
|
||||
checker.current_sampler_index = 0;
|
||||
checker.current_texture_index = 0;
|
||||
checker.result = result;
|
||||
file := result.file;
|
||||
root := result.root;
|
||||
array_reserve(*checker.messages, 32);
|
||||
|
||||
init_semantic_checker(*checker, file.ast_root, file.file.path);
|
||||
init_semantic_checker(*checker, result.root, result.file.path);
|
||||
|
||||
// @Performance: Should have this built in stuff done earlier and only once
|
||||
add_hlsl_builtins(*checker);
|
||||
// @Performance: Should have this built in stuff done earlier and only once
|
||||
add_builtins(*checker);
|
||||
checker.result.file = file;
|
||||
|
||||
type_check(*checker, file.ast_root);
|
||||
|
||||
result.had_error |= checker.had_error;
|
||||
copy_messages(checker.messages, *result.messages);
|
||||
}
|
||||
result.root = root;
|
||||
|
||||
type_check(*checker, result.root);
|
||||
|
||||
result.had_error |= checker.had_error;
|
||||
copy_messages(checker.messages, *result.messages);
|
||||
}
|
||||
|
||||
// ===========================================================
|
||||
@@ -2040,7 +2038,7 @@ pretty_print_symbol_table :: (checker : *Semantic_Checker, allocator : Allocator
|
||||
builder : String_Builder;
|
||||
init_string_builder(*builder,, allocator);
|
||||
|
||||
pretty_print_scope(xx checker.current_scope, checker.result_file.scope_stack, checker.result_file.type_variables, *checker.result_file.scope_stack.stack[0], *builder);
|
||||
pretty_print_scope(xx checker.current_scope, checker.result.scope_stack, checker.result.type_variables, *checker.result.scope_stack.stack[0], *builder);
|
||||
|
||||
return builder_to_string(*builder,, allocator);
|
||||
}
|
||||
@@ -2049,11 +2047,8 @@ pretty_print_symbol_table :: (result : *Compile_Result, allocator : Allocator) -
|
||||
builder : String_Builder;
|
||||
init_string_builder(*builder,, allocator);
|
||||
|
||||
for *file : result.files {
|
||||
current_scope := cast(Scope_Handle)1;
|
||||
pretty_print_scope(current_scope, file.scope_stack, file.type_variables, *file.scope_stack.stack[0], *builder);
|
||||
|
||||
}
|
||||
current_scope := cast(Scope_Handle)1;
|
||||
pretty_print_scope(current_scope, result.scope_stack, result.type_variables, *result.scope_stack.stack[0], *builder);
|
||||
|
||||
|
||||
return builder_to_string(*builder,, allocator);
|
||||
|
||||
Reference in New Issue
Block a user