diff --git a/compiler/cl-ast/src/ast.rs b/compiler/cl-ast/src/ast.rs index 92ee1e4..08eaa0c 100644 --- a/compiler/cl-ast/src/ast.rs +++ b/compiler/cl-ast/src/ast.rs @@ -285,7 +285,6 @@ pub struct Path { #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub enum PathPart { SuperKw, - SelfKw, SelfTy, Ident(Sym), } diff --git a/compiler/cl-ast/src/ast_impl/convert.rs b/compiler/cl-ast/src/ast_impl/convert.rs index 3db3110..8f98da2 100644 --- a/compiler/cl-ast/src/ast_impl/convert.rs +++ b/compiler/cl-ast/src/ast_impl/convert.rs @@ -4,7 +4,6 @@ use super::*; impl> From for PathPart { fn from(value: T) -> Self { match value.as_ref() { - "self" => PathPart::SelfKw, "super" => PathPart::SuperKw, ident => PathPart::Ident(ident.into()), } diff --git a/compiler/cl-ast/src/ast_impl/display.rs b/compiler/cl-ast/src/ast_impl/display.rs index ef12529..c2f3d93 100644 --- a/compiler/cl-ast/src/ast_impl/display.rs +++ b/compiler/cl-ast/src/ast_impl/display.rs @@ -370,7 +370,6 @@ impl Display for PathPart { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { PathPart::SuperKw => "super".fmt(f), - PathPart::SelfKw => "self".fmt(f), PathPart::SelfTy => "Self".fmt(f), PathPart::Ident(id) => id.fmt(f), } diff --git a/compiler/cl-ast/src/ast_impl/weight_of.rs b/compiler/cl-ast/src/ast_impl/weight_of.rs index 1621308..1ebc1dd 100644 --- a/compiler/cl-ast/src/ast_impl/weight_of.rs +++ b/compiler/cl-ast/src/ast_impl/weight_of.rs @@ -264,7 +264,6 @@ impl WeightOf for PathPart { fn weight_of(&self) -> usize { match self { PathPart::SuperKw => size_of_val(self), - PathPart::SelfKw => size_of_val(self), PathPart::SelfTy => size_of_val(self), PathPart::Ident(interned) => interned.weight_of(), } diff --git a/compiler/cl-ast/src/ast_visitor/fold.rs b/compiler/cl-ast/src/ast_visitor/fold.rs index c1783b2..08fa247 100644 --- a/compiler/cl-ast/src/ast_visitor/fold.rs +++ b/compiler/cl-ast/src/ast_visitor/fold.rs @@ -210,7 +210,6 @@ pub trait Fold { fn fold_path_part(&mut self, p: PathPart) -> PathPart { match p { PathPart::SuperKw => PathPart::SuperKw, - PathPart::SelfKw => PathPart::SelfKw, PathPart::SelfTy => PathPart::SelfTy, PathPart::Ident(i) => PathPart::Ident(self.fold_sym(i)), } diff --git a/compiler/cl-ast/src/ast_visitor/walk.rs b/compiler/cl-ast/src/ast_visitor/walk.rs index 0ba3419..683d9af 100644 --- a/compiler/cl-ast/src/ast_visitor/walk.rs +++ b/compiler/cl-ast/src/ast_visitor/walk.rs @@ -464,7 +464,6 @@ impl Walk for PathPart { fn children<'a, V: Visit<'a>>(&'a self, v: &mut V) { match self { PathPart::SuperKw => {} - PathPart::SelfKw => {} PathPart::SelfTy => {} PathPart::Ident(sym) => sym.visit_in(v), } diff --git a/compiler/cl-interpret/src/interpret.rs b/compiler/cl-interpret/src/interpret.rs index bced2d4..fdb0795 100644 --- a/compiler/cl-interpret/src/interpret.rs +++ b/compiler/cl-interpret/src/interpret.rs @@ -512,7 +512,6 @@ mod assignment { _ => Err(Error::NotIndexable()), } } - [PathPart::SelfKw, rest @ ..] => project_path_in_namespace(env, rest), [PathPart::SelfTy, ..] => todo!("calc_address for `Self`"), [PathPart::SuperKw, ..] => todo!("calc_address for `super`"), } @@ -764,7 +763,6 @@ impl Interpret for Structor { let name = match parts.last() { Some(PathPart::Ident(name)) => *name, - Some(PathPart::SelfKw) => "self".into(), Some(PathPart::SelfTy) => "Self".into(), Some(PathPart::SuperKw) => "super".into(), None => "".into(), diff --git a/compiler/cl-parser/src/parser.rs b/compiler/cl-parser/src/parser.rs index dd6dd33..58d6dc6 100644 --- a/compiler/cl-parser/src/parser.rs +++ b/compiler/cl-parser/src/parser.rs @@ -188,11 +188,7 @@ macro literal_like() { /// Expands to a pattern which matches path-like [TokenKinds](TokenKind) macro path_like() { - TokenKind::Super - | TokenKind::SelfKw - | TokenKind::SelfTy - | TokenKind::Identifier - | TokenKind::ColonColon + TokenKind::Super | TokenKind::SelfTy | TokenKind::Identifier | TokenKind::ColonColon } pub trait Parse<'t>: Sized { @@ -689,7 +685,7 @@ impl Parse<'_> for UseTree { CURLIES, P, )(p)?), - TokenKind::SelfKw | TokenKind::Super | TokenKind::Identifier => { + TokenKind::Super | TokenKind::Identifier => { let name = PathPart::parse(p)?; if p.match_type(TokenKind::ColonColon, P).is_ok() { UseTree::Path(name, Box::new(UseTree::parse(p)?)) @@ -864,7 +860,6 @@ impl Parse<'_> for PathPart { const P: Parsing = Parsing::PathPart; let out = match p.peek_kind(P)? { TokenKind::Super => PathPart::SuperKw, - TokenKind::SelfKw => PathPart::SelfKw, TokenKind::SelfTy => PathPart::SelfTy, TokenKind::Identifier => PathPart::Ident(Sym::parse(p)?), t => return Err(p.error(Unexpected(t), P)), diff --git a/compiler/cl-repl/examples/yaml.rs b/compiler/cl-repl/examples/yaml.rs index 13b1136..2a65a8d 100644 --- a/compiler/cl-repl/examples/yaml.rs +++ b/compiler/cl-repl/examples/yaml.rs @@ -664,7 +664,6 @@ pub mod yamlify { fn yaml(&self, y: &mut Yamler) { match self { PathPart::SuperKw => y.value("super"), - PathPart::SelfKw => y.value("self"), PathPart::SelfTy => y.value("Self"), PathPart::Ident(i) => y.yaml(i), }; diff --git a/compiler/cl-token/src/token_type.rs b/compiler/cl-token/src/token_type.rs index c874e86..dc72fa3 100644 --- a/compiler/cl-token/src/token_type.rs +++ b/compiler/cl-token/src/token_type.rs @@ -33,7 +33,6 @@ pub enum TokenKind { Mut, // "mut" Pub, // "pub" Return, // "return" - SelfKw, // "self" SelfTy, // "Self" Static, // "static" Struct, // "struct" @@ -127,7 +126,6 @@ impl Display for TokenKind { TokenKind::Mut => "mut".fmt(f), TokenKind::Pub => "pub".fmt(f), TokenKind::Return => "return".fmt(f), - TokenKind::SelfKw => "self".fmt(f), TokenKind::SelfTy => "Self".fmt(f), TokenKind::Static => "static".fmt(f), TokenKind::Struct => "struct".fmt(f), @@ -220,7 +218,6 @@ impl FromStr for TokenKind { "mut" => Self::Mut, "pub" => Self::Pub, "return" => Self::Return, - "self" => Self::SelfKw, "Self" => Self::SelfTy, "static" => Self::Static, "struct" => Self::Struct, diff --git a/compiler/cl-typeck/src/table.rs b/compiler/cl-typeck/src/table.rs index 91ae3e5..3239cff 100644 --- a/compiler/cl-typeck/src/table.rs +++ b/compiler/cl-typeck/src/table.rs @@ -245,6 +245,14 @@ impl<'a> Table<'a> { } } + pub fn super_of(&self, node: Handle) -> Option { + match self.kinds.get(node)? { + NodeKind::Root => None, + NodeKind::Module => self.parent(node).copied(), + _ => self.super_of(*self.parent(node)?), + } + } + pub fn name(&self, node: Handle) -> Option { self.source(node).and_then(|s| s.name()) } @@ -280,8 +288,7 @@ impl<'a> Table<'a> { /// Does path traversal relative to the provided `node`. pub fn nav(&self, node: Handle, path: &[PathPart]) -> Option { match path { - [PathPart::SuperKw, rest @ ..] => self.nav(*self.parent(node)?, rest), - [PathPart::SelfKw, rest @ ..] => self.nav(node, rest), + [PathPart::SuperKw, rest @ ..] => self.nav(self.super_of(node)?, rest), [PathPart::SelfTy, rest @ ..] => self.nav(self.selfty(node)?, rest), [PathPart::Ident(name), rest @ ..] => self.nav(self.get_by_sym(node, name)?, rest), [] => Some(node), diff --git a/stdlib/std/test.cl b/stdlib/std/test.cl index 7bebee8..59a55b8 100644 --- a/stdlib/std/test.cl +++ b/stdlib/std/test.cl @@ -4,7 +4,7 @@ use super::preamble::*; struct UnitLike; -struct TupleLike(super::num::i32, super::self::test::char) +struct TupleLike(super::num::i32, super::test::char) struct StructLike { pub member1: UnitLike,