Started some fixes for array support. Not entirely there yet.
This commit is contained in:
69
Check.jai
69
Check.jai
@@ -35,14 +35,13 @@ Type_Kind :: enum {
|
||||
Unresolved_Expression;
|
||||
|
||||
Struct;
|
||||
Properties;
|
||||
CBuffer;
|
||||
Array;
|
||||
}
|
||||
|
||||
Source_Kind :: enum {
|
||||
Expression;
|
||||
Declaration; // struct, properties, function, etc.
|
||||
Declaration; // struct, cbuffers, function, etc.
|
||||
}
|
||||
|
||||
Typenames :: string.[
|
||||
@@ -75,7 +74,9 @@ Type_Variable :: struct {
|
||||
struct_field_parent : *AST_Node;
|
||||
|
||||
typename : string;
|
||||
is_array : bool;
|
||||
// is_array : bool;
|
||||
element_type : Type_Kind;
|
||||
element_typename : string;
|
||||
|
||||
MAX_TYPE_VARIABLE_CHILDREN :: 32;
|
||||
children : Static_Array(Type_Variable_Handle, MAX_TYPE_VARIABLE_CHILDREN);
|
||||
@@ -108,7 +109,6 @@ Scope_Kind :: enum {
|
||||
Global;
|
||||
Function;
|
||||
Struct;
|
||||
Properties;
|
||||
}
|
||||
|
||||
Scope :: struct {
|
||||
@@ -834,10 +834,6 @@ add_child :: (checker : *Checker, handle : Type_Variable_Handle, child : Type_Va
|
||||
}
|
||||
|
||||
init_semantic_checker :: (checker : *Checker, root : *AST_Node, path : string) {
|
||||
checker.current_buffer_index = 0;
|
||||
checker.current_sampler_index = 0;
|
||||
checker.current_texture_index = 0;
|
||||
|
||||
checker.program_root = root;
|
||||
checker.path = path;
|
||||
|
||||
@@ -1260,14 +1256,13 @@ check_variable :: (checker : *Checker, node : *AST_Node, struct_field_parent : *
|
||||
}
|
||||
|
||||
if node.children.count > 0 {
|
||||
if variable.type != .Struct && variable.type != .Properties && variable.type != .CBuffer {
|
||||
if variable.type != .Struct && variable.type != .CBuffer {
|
||||
field_access_on_primitive_type(checker, node, find_result.type_variable);
|
||||
return 0;
|
||||
} else if variable.type == .Array {
|
||||
|
||||
} else {
|
||||
lookup_name : string = variable.typename;
|
||||
if variable.typename == "properties" {
|
||||
lookup_name = variable.name;
|
||||
}
|
||||
struct_symbol := find_symbol(checker, lookup_name, checker.current_scope);
|
||||
type_variable := from_handle(checker, struct_symbol.type_variable);
|
||||
|
||||
@@ -1307,27 +1302,23 @@ check_field :: (checker : *Checker, node : *AST_Node) -> Type_Variable_Handle {
|
||||
variable, handle := new_type_variable(checker);
|
||||
variable.name = node.name;
|
||||
typename : string;
|
||||
variable.type = lookup_type(checker, checker.current_scope, node, *typename);
|
||||
|
||||
variable.is_array = node.array_field;
|
||||
|
||||
if variable.is_array {
|
||||
// variable.is_array = node.array_field;
|
||||
if node.array_field {
|
||||
variable.type = .Array;
|
||||
variable.element_type = lookup_type(checker, checker.current_scope, node, *variable.element_typename);
|
||||
} else {
|
||||
variable.type = lookup_type(checker, checker.current_scope, node, *typename);
|
||||
}
|
||||
|
||||
if variable.type == .Array {
|
||||
size_node := node.children[0];
|
||||
size_var := check_node(checker, size_node);
|
||||
if from_handle(checker, size_var).type != .Int {
|
||||
//@Incomplete(niels): Type mismatch here. With integral type required message.
|
||||
}
|
||||
}
|
||||
|
||||
if variable.source_kind == .Declaration && variable.type == .Sampler {
|
||||
variable.resource_index = checker.current_sampler_index;
|
||||
checker.current_sampler_index += 1;
|
||||
}
|
||||
|
||||
if variable.source_kind == .Declaration && variable.type == .Texture2D {
|
||||
variable.resource_index = checker.current_texture_index;
|
||||
checker.current_texture_index += 1;
|
||||
}
|
||||
|
||||
variable.typename = typename;
|
||||
variable.source_node = node;
|
||||
@@ -1348,20 +1339,33 @@ check_field :: (checker : *Checker, node : *AST_Node) -> Type_Variable_Handle {
|
||||
symbol.source_node = node;
|
||||
symbol.type_variable = handle;
|
||||
add_symbol_to_scope(checker.state, *checker.ctx.scope_stack, checker.current_scope, node.name, symbol);
|
||||
variable.source_kind = .Declaration;
|
||||
} else {
|
||||
symbol_redeclaration(checker, node, find_result);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if node.token.ident_value.count > 0 {
|
||||
variable.type = lookup_type(checker, checker.current_scope, node);
|
||||
if variable.source_kind == .Declaration && variable.type == .Sampler {
|
||||
variable.resource_index = checker.current_sampler_index;
|
||||
checker.current_sampler_index += 1;
|
||||
}
|
||||
|
||||
if node.children.count > 0 {
|
||||
if variable.source_kind == .Declaration && variable.type == .Texture2D {
|
||||
variable.resource_index = checker.current_texture_index;
|
||||
checker.current_texture_index += 1;
|
||||
}
|
||||
|
||||
if variable.type != .Array && node.children.count > 0 || variable.type == .Array && node.children.count > 1 {
|
||||
rhs : Type_Variable_Handle;
|
||||
assert(node.children.count == 1);
|
||||
for child : node.children {
|
||||
start_index := 0;
|
||||
if variable.type == .Array {
|
||||
start_index += 1;
|
||||
}
|
||||
|
||||
for i : start_index..node.children.count - 1 {
|
||||
child := node.children[i];
|
||||
rhs = check_node(checker, child);
|
||||
}
|
||||
|
||||
@@ -2219,9 +2223,6 @@ check :: (ctx : *Compiler_Context, allocator : Allocator = temp) {
|
||||
|
||||
checker : Checker;
|
||||
|
||||
checker.current_buffer_index = 0;
|
||||
checker.current_sampler_index = 0;
|
||||
checker.current_texture_index = 0;
|
||||
checker.ctx = ctx;
|
||||
|
||||
init_semantic_checker(*checker, ctx.root, ctx.file.path);
|
||||
@@ -2261,7 +2262,7 @@ type_to_string :: (type_variable : Type_Variable) -> string {
|
||||
return type_variable.typename;
|
||||
}
|
||||
case .Array;
|
||||
return "array";
|
||||
// return "array";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@@ -2365,7 +2366,6 @@ pretty_print_scope :: (ctx : *Compiler_Context, current_scope : Scope_Handle, sc
|
||||
pretty_print_function(*scope_stack, current_scope, variables, builder, key, type_variable, 1);
|
||||
}
|
||||
case .CBuffer; #through;
|
||||
case .Properties; #through;
|
||||
case .Struct; {
|
||||
if type_variable.typename.count > 0 && type_variable.source_kind != .Declaration {
|
||||
indent(builder, indentation + 1);
|
||||
@@ -2391,7 +2391,6 @@ pretty_print_scope :: (ctx : *Compiler_Context, current_scope : Scope_Handle, sc
|
||||
pretty_print_function(*scope_stack, current_scope, variables, builder, key, type_variable, 1);
|
||||
}
|
||||
case .CBuffer; #through;
|
||||
case .Properties; #through;
|
||||
case .Struct; {
|
||||
if type_variable.typename.count > 0 && type_variable.source_kind != .Declaration {
|
||||
indent(builder, indentation + 1);
|
||||
|
||||
Reference in New Issue
Block a user