aboutsummaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2021-12-30 02:32:35 +0100
committerDaniel Gavin <danielgavin5@hotmail.com>2021-12-30 02:32:35 +0100
commita07efabcc54bea23707c4fa5e558f68f90ce42fa (patch)
tree29ab3107245bf1a43b3881887db070817db825aa /src/analysis
parent3ac23cfce721a19ad939750c2202685edc44d62c (diff)
refractor with bitsets, and fix inlined struct/union/enum
Diffstat (limited to 'src/analysis')
-rw-r--r--src/analysis/analysis.odin63
1 files changed, 52 insertions, 11 deletions
diff --git a/src/analysis/analysis.odin b/src/analysis/analysis.odin
index b6f4e70..09bfb3a 100644
--- a/src/analysis/analysis.odin
+++ b/src/analysis/analysis.odin
@@ -538,12 +538,12 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: index.Symbol, flags
return false;
}
- if a.is_distinct != b.is_distinct {
+ if .Distinct in a.flags != .Distinct in b.flags {
return false;
}
- if a.is_distinct == b.is_distinct &&
- a.is_distinct == true &&
+ if .Distinct in a.flags == .Distinct in b.flags &&
+ .Distinct in a.flags &&
a.name == b.name &&
a.pkg == b.pkg {
return true;
@@ -829,6 +829,14 @@ resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (i
using ast;
switch v in &node.derived {
+ case Union_Type:
+ return make_symbol_union_from_ast(ast_context, v, ast_context.field_name, true), true;
+ case Enum_Type:
+ return make_symbol_enum_from_ast(ast_context, v, ast_context.field_name, true), true;
+ case Struct_Type:
+ return make_symbol_struct_from_ast(ast_context, v, ast_context.field_name, true), true;
+ case Bit_Set_Type:
+ return make_symbol_bitset_from_ast(ast_context, v, ast_context.field_name, true), true;
case Array_Type:
return make_symbol_array_from_ast(ast_context, v), true;
case Dynamic_Array_Type:
@@ -1113,7 +1121,7 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i
if is_distinct {
return_symbol.name = node.name;
- return_symbol.is_distinct = is_distinct;
+ return_symbol.flags |= {.Distinct};
}
return return_symbol, ok;
@@ -1171,7 +1179,7 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i
if is_distinct {
return_symbol.name = node.name;
- return_symbol.is_distinct = is_distinct;
+ return_symbol.flags |= {.Distinct};
}
return_symbol.doc = common.get_doc(global.docs, context.temp_allocator);
@@ -1579,7 +1587,9 @@ make_symbol_procedure_from_ast :: proc(ast_context: ^AstContext, n: ^ast.Node, v
}
if expr, ok := ast_context.globals[name]; ok {
- symbol.is_deprecated = expr.deprecated;
+ if expr.deprecated {
+ symbol.flags |= {.Distinct};
+ }
}
symbol.value = index.SymbolProcedureValue {
@@ -1658,7 +1668,7 @@ make_symbol_basic_type_from_ast :: proc(ast_context: ^AstContext, n: ^ast.Node,
return symbol;
}
-make_symbol_union_from_ast :: proc(ast_context: ^AstContext, v: ast.Union_Type, ident: string) -> index.Symbol {
+make_symbol_union_from_ast :: proc(ast_context: ^AstContext, v: ast.Union_Type, ident: string, inlined := false) -> index.Symbol {
symbol := index.Symbol {
range = common.get_token_range(v, ast_context.file.src),
@@ -1666,6 +1676,11 @@ make_symbol_union_from_ast :: proc(ast_context: ^AstContext, v: ast.Union_Type,
pkg = get_package_from_node(v.node),
};
+ if inlined {
+ symbol.flags |= {.Anonymous};
+ symbol.name = "union";
+ }
+
names := make([dynamic]string, context.temp_allocator);
for variant in v.variants {
@@ -1689,14 +1704,19 @@ make_symbol_union_from_ast :: proc(ast_context: ^AstContext, v: ast.Union_Type,
return symbol;
}
-make_symbol_enum_from_ast :: proc(ast_context: ^AstContext, v: ast.Enum_Type, ident: string) -> index.Symbol {
-
+make_symbol_enum_from_ast :: proc(ast_context: ^AstContext, v: ast.Enum_Type, ident: string, inlined := false) -> index.Symbol {
symbol := index.Symbol {
range = common.get_token_range(v, ast_context.file.src),
type = .Enum,
pkg = get_package_from_node(v.node),
};
+ if inlined {
+ symbol.flags |= {.Anonymous};
+ symbol.name = "enum";
+ }
+
+
names := make([dynamic]string, context.temp_allocator);
for n in v.fields {
@@ -1719,7 +1739,7 @@ make_symbol_enum_from_ast :: proc(ast_context: ^AstContext, v: ast.Enum_Type, id
return symbol;
}
-make_symbol_bitset_from_ast :: proc(ast_context: ^AstContext, v: ast.Bit_Set_Type, ident: string) -> index.Symbol {
+make_symbol_bitset_from_ast :: proc(ast_context: ^AstContext, v: ast.Bit_Set_Type, ident: string, inlined := false) -> index.Symbol {
symbol := index.Symbol {
range = common.get_token_range(v, ast_context.file.src),
@@ -1727,6 +1747,11 @@ make_symbol_bitset_from_ast :: proc(ast_context: ^AstContext, v: ast.Bit_Set_Typ
pkg = get_package_from_node(v.node),
};
+ if inlined {
+ symbol.flags |= {.Anonymous};
+ symbol.name = "bitset";
+ }
+
symbol.value = index.SymbolBitSetValue {
expr = v.elem,
bitset_name = ident,
@@ -1735,7 +1760,7 @@ make_symbol_bitset_from_ast :: proc(ast_context: ^AstContext, v: ast.Bit_Set_Typ
return symbol;
}
-make_symbol_struct_from_ast :: proc(ast_context: ^AstContext, v: ast.Struct_Type, ident: string) -> index.Symbol {
+make_symbol_struct_from_ast :: proc(ast_context: ^AstContext, v: ast.Struct_Type, ident: string, inlined := false) -> index.Symbol {
symbol := index.Symbol {
range = common.get_token_range(v, ast_context.file.src),
@@ -1743,6 +1768,11 @@ make_symbol_struct_from_ast :: proc(ast_context: ^AstContext, v: ast.Struct_Type
pkg = get_package_from_node(v.node),
};
+ if inlined {
+ symbol.flags |= {.Anonymous};
+ symbol.name = "struct";
+ }
+
names := make([dynamic]string, context.temp_allocator);
types := make([dynamic]^ast.Expr, context.temp_allocator);
usings := make(map[string]bool, 0, context.temp_allocator);
@@ -2505,6 +2535,17 @@ get_call_commas :: proc(position_context: ^DocumentPositionContext, document: ^c
position_context.call_commas = commas[:];
}
+type_to_string :: proc(ast_context: ^AstContext, expr: ^ast.Expr) -> string {
+
+ if symbol, ok := resolve_type_expression(ast_context, expr); ok {
+ if .Anonymous in symbol.flags {
+ return symbol.name;
+ }
+ }
+
+ return common.node_to_string(expr);
+}
+
/*
Figure out what exactly is at the given position and whether it is in a function, struct, etc.
*/