aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2021-02-10 02:27:04 +0100
committerDanielGavin <danielgavin5@hotmail.com>2021-02-10 02:27:04 +0100
commit51595ac19fe8f7c13788199c8af8033eddbf2448 (patch)
treeed7b123dc2806a4c9713487f64ccc4a6b5c8f4b3 /src
parent53997441185f241c9c63b9b1c186a2fd7daf0c63 (diff)
add hard coded support for where ODIN_OS = "windows"
Diffstat (limited to 'src')
-rw-r--r--src/common/ast.odin73
-rw-r--r--src/index/collector.odin33
-rw-r--r--src/server/analysis.odin2
3 files changed, 103 insertions, 5 deletions
diff --git a/src/common/ast.odin b/src/common/ast.odin
index 3826bf4..cd44cdf 100644
--- a/src/common/ast.odin
+++ b/src/common/ast.odin
@@ -33,6 +33,7 @@ GlobalExpr :: struct {
docs: ^ast.Comment_Group,
};
+//TODO(add a sub procedure to avoid repeating the value decl work)
collect_globals :: proc(file: ast.File) -> [] GlobalExpr {
exprs := make([dynamic] GlobalExpr, context.temp_allocator);
@@ -59,6 +60,78 @@ collect_globals :: proc(file: ast.File) -> [] GlobalExpr {
}
+ else if when_decl, ok := decl.derived.(ast.When_Stmt); ok {
+
+ if when_decl.cond == nil {
+ continue;
+ }
+
+ if when_decl.body == nil {
+ continue;
+ }
+
+ if binary, ok := when_decl.cond.derived.(ast.Binary_Expr); ok {
+
+ if binary.left == nil || binary.right == nil {
+ continue;
+ }
+
+ ident: ^ast.Ident;
+ basic_lit: ^ast.Basic_Lit;
+
+ if t, ok := binary.left.derived.(ast.Ident); ok {
+ ident = cast(^ast.Ident)binary.left;
+ }
+
+ else if t, ok := binary.left.derived.(ast.Basic_Lit); ok {
+ basic_lit = cast(^ast.Basic_Lit)binary.left;
+ }
+
+ if t, ok := binary.right.derived.(ast.Ident); ok {
+ ident = cast(^ast.Ident)binary.right;
+ }
+
+ else if t, ok := binary.right.derived.(ast.Basic_Lit); ok {
+ basic_lit = cast(^ast.Basic_Lit)binary.right;
+ }
+
+ if ident != nil && basic_lit != nil {
+
+ //hardcode for windows for now
+ if ident.name == "ODIN_OS" && basic_lit.tok.text == "\"windows\"" {
+
+ log.errorf("when %v %v", ident, basic_lit);
+
+ if block, ok := when_decl.body.derived.(ast.Block_Stmt); ok {
+
+ for stmt in block.stmts {
+
+ if value_decl, ok := stmt.derived.(ast.Value_Decl); ok {
+
+ for name, i in value_decl.names {
+
+ str := get_ast_node_string(name, file.src);
+
+ if value_decl.type != nil {
+ append(&exprs, GlobalExpr { name = str, expr = value_decl.type, mutable = value_decl.is_mutable, docs = value_decl.docs });
+ }
+
+ else {
+ if len(value_decl.values) > i {
+ append(&exprs, GlobalExpr { name = str, expr = value_decl.values[i], docs = value_decl.docs });
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ //YUPPI - what a fun slide
+
+ }
+
else if foreign_decl, ok := decl.derived.(ast.Foreign_Block_Decl); ok {
if foreign_decl.body == nil {
diff --git a/src/index/collector.odin b/src/index/collector.odin
index e3cfc59..0a765ad 100644
--- a/src/index/collector.odin
+++ b/src/index/collector.odin
@@ -204,7 +204,15 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri
name := expr.name;
- switch v in expr.expr.derived {
+ col_expr := expr.expr;
+
+ if helper, ok := col_expr.derived.(ast.Helper_Type); ok {
+ if helper.type != nil {
+ col_expr = helper.type;
+ }
+ }
+
+ switch v in col_expr.derived {
case ast.Proc_Lit:
token = v;
token_type = .Function;
@@ -222,11 +230,26 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri
if v.type != nil {
symbol.value = collect_procedure_fields(collection, v.type, v.type.params, v.type.results, package_map);
}
+ case ast.Proc_Type:
+ token = v;
+ token_type = .Function;
+
+ if v.params != nil {
+ symbol.signature = strings.concatenate( {"(", string(file.src[v.params.pos.offset:v.params.end.offset]), ")"},
+ collection.allocator);
+ }
+
+ if v.results != nil {
+ symbol.returns = strings.concatenate( {"(", string(file.src[v.results.pos.offset:v.results.end.offset]), ")"},
+ collection.allocator);
+ }
+
+ symbol.value = collect_procedure_fields(collection, cast(^ast.Proc_Type)col_expr, v.params, v.results, package_map);
case ast.Proc_Group:
token = v;
token_type = .Function;
symbol.value = SymbolProcedureGroupValue {
- group = clone_type(expr.expr, collection.allocator, &collection.unique_strings),
+ group = clone_type(col_expr, collection.allocator, &collection.unique_strings),
};
case ast.Struct_Type:
token = v;
@@ -245,13 +268,13 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri
symbol.signature = "union";
case ast.Basic_Lit:
token = v;
- symbol.value = collect_generic(collection, expr.expr, package_map);
+ symbol.value = collect_generic(collection, col_expr, package_map);
case ast.Ident:
token = v;
token_type = .Variable;
- symbol.value = collect_generic(collection, expr.expr, package_map);
+ symbol.value = collect_generic(collection, col_expr, package_map);
case: // default
- symbol.value = collect_generic(collection, expr.expr, package_map);
+ symbol.value = collect_generic(collection, col_expr, package_map);
token_type = .Variable;
token = expr.expr;
break;
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 766fa4f..6d791e9 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -582,6 +582,8 @@ resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (i
return resolve_type_expression(ast_context, v.expr);
case Tag_Expr:
return resolve_type_expression(ast_context, v.expr);
+ case Helper_Type:
+ return resolve_type_expression(ast_context, v.type);
case Ellipsis:
return resolve_type_expression(ast_context, v.expr);
case Implicit: