Skip to content

Commit

Permalink
add some comments of scope kind
Browse files Browse the repository at this point in the history
Signed-off-by: he1pa <18012015693@163.com>
  • Loading branch information
He1pa committed Jan 4, 2024
1 parent 9204199 commit 566cd3c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions kclvm/sema/src/advanced_resolver/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ impl<'ctx> AdvancedResolver<'ctx> {
let schema_symbol = self.ctx.current_schema_symbol.take();
let kind = match &schema_symbol {
Some(_) => LocalSymbolScopeKind::SchemaConfig,
None => LocalSymbolScopeKind::Common,
None => LocalSymbolScopeKind::Value,
};

self.enter_local_scope(
Expand Down Expand Up @@ -1042,7 +1042,7 @@ impl<'ctx> AdvancedResolver<'ctx> {
&self.ctx.current_filename.as_ref().unwrap().clone(),
start,
end,
LocalSymbolScopeKind::Common,
LocalSymbolScopeKind::Value,
);

self.expr(&entry.node.value);
Expand Down
22 changes: 20 additions & 2 deletions kclvm/sema/src/core/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ pub enum LocalSymbolScopeKind {
Lambda,
SchemaDef,
SchemaConfig,
Common,
Value,
}

impl Scope for LocalSymbolScope {
Expand Down Expand Up @@ -384,7 +384,25 @@ impl Scope for LocalSymbolScope {
}
}
}

// In SchemaConfig, available definitions only contain keys of schema attr,i.e., `left` values in schema expr.
// but in child scope, i.e., right value in schema expr, available definitions contain all parent definitions.
// ```
// b = "bar"
// foo = Foo{
// bar: b
// }
// ````
// and scope range is(use `#kind[]` to represent the range of the scope`)
// ```
// #Root[
// b = "bar"
// foo = Foo #SchemaConfig[{
// bar: #Value[b]
// }]
// ]
// ````
// At position of `bar`, the scope kind is SchemaConfig, only get the definition of bar.
// At position of seconde `b`, the scope is the child scope of SchemaConfig, need to recursively find the definition of `b`` at a higher level
if self.kind == LocalSymbolScopeKind::SchemaConfig && !recursive {
return all_defs_map;
} else {
Expand Down

0 comments on commit 566cd3c

Please sign in to comment.