diff --git a/AST.jai b/AST.jai index adbc878..918e98a 100644 --- a/AST.jai +++ b/AST.jai @@ -14,6 +14,8 @@ AST_Kind :: enum { Meta; Instance; //== + // Directives + If_Directive; // Hint; // Type; @@ -191,7 +193,13 @@ pretty_print_children :: (parent : *AST_Node, indentation : int, builder : *Stri ind = 0; } // skip := ifx it_index > 0 then false else true; - pretty_print_node(child, ind, builder); + + if child.kind == .Function { + pretty_print_declaration(child, ind, builder); + } else { + pretty_print_node(child, ind, builder); + } + if it_index != children.count - 1 { if flags & .Separator { @@ -434,6 +442,10 @@ pretty_print_declaration :: (declaration : *AST_Node, indentation : int, builder append(builder, "pixel "); } + if declaration.kind == .If_Directive { + append(builder, "#if "); + } + if declaration.kind == .Properties { append(builder, "properties"); if declaration.name.count > 0 { @@ -463,24 +475,15 @@ pretty_print_declaration :: (declaration : *AST_Node, indentation : int, builder } if declaration.children.count > 0 { - // print_to_builder(builder, "\n"); - // if declaration.kind == .Function { - // field_list := declaration.children[0]; - // pretty_print_fieldlist(field_list, indentation + 1, builder); - // append(builder, "\n"); + if declaration.kind == .If_Directive { + pretty_print_node(declaration.children[0], 0, builder); + append(builder, "\n"); + pretty_print_node(declaration.children[1], indentation + 5, builder); + } else { + print_to_builder(builder, "\n"); + pretty_print_children(declaration, indentation + 1, builder, flags = .NewLine); + } - // if declaration.children.count > 1 { - // body := declaration.children[1]; - // pretty_print_node(body, indentation + 1, builder, true); - // } - // } else if declaration.kind == .Struct { - // pretty_print_node(declaration.children[0], indentation + 1, builder); - // } else { - // pretty_print_node(declaration.children[0], indentation + 1, builder); - // } - - print_to_builder(builder, "\n"); - pretty_print_children(declaration, indentation + 1, builder, flags = .NewLine); } append(builder, ")"); diff --git a/Parsing.jai b/Parsing.jai index 54e6f0e..64805a1 100644 --- a/Parsing.jai +++ b/Parsing.jai @@ -19,15 +19,6 @@ Parse_State :: struct { //////////////////////////// //@nb - Result and error handling -// Parse_Result :: struct { -// root : *AST_Node; -// nodes : [..]AST_Node; - -// had_error : bool; - -// messages : [..]Compiler_Message; -// } - Parse_Error_Kind :: enum { Parse_Error_Type_Missing; Parse_Error_Expected_Expression; @@ -616,6 +607,23 @@ directive :: (state : *Parse_State) -> *AST_Node { func := function_declaration(state, identifier_token, .None, false, false); func.foreign_declaration = true; return func; + } else if state.current.ident_value == "if" { + if_directive := make_node(state, .If_Directive); + + source_location : Source_Range; + // source_location.begin = state.previous; + + advance(state); + + cond := expression(state); + add_child(if_directive, cond); + + if_body := block(state); + add_child(if_directive, if_body); + + if_directive.source_location = source_location; + + return if_directive; } return null; diff --git a/Semantic_Analysis.jai b/Semantic_Analysis.jai index 8c89191..00f0575 100644 --- a/Semantic_Analysis.jai +++ b/Semantic_Analysis.jai @@ -55,6 +55,9 @@ Typenames :: string.[ "bool" , ]; +//@Incomplete(niels): We can vastly simplify type handling +// There's really no reason to have these type variables anymore now that we don't do union find +// We can just have the built-in types and then we can declare structs, functions, buffers etc. as one time things. Type_Variable :: struct { type : Type_Kind; kind : Type_Variable_Kind; @@ -1432,8 +1435,6 @@ check_node :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_H lhs_type := from_handle(checker, lhs_var); rhs_type := from_handle(checker, rhs_var); - - variable.type = lhs_type.type; variable.typename = lhs_type.typename; variable.scope = lhs_type.scope; @@ -1532,6 +1533,10 @@ check_node :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_H } } } + case .If_Directive; { + cond_var := check_node(checker, node.children[0]); + assert(false, "Not implemented yet\n"); + } case .Variable; { return check_variable(checker, node); } diff --git a/test/ifdefs.ink b/test/ifdefs.ink new file mode 100644 index 0000000..04f1612 --- /dev/null +++ b/test/ifdefs.ink @@ -0,0 +1,5 @@ +#if Defines.Skinning { + vertex main :: () { + // Stub + } +}