Skip to content

Commit

Permalink
Added annotated symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
SpontanCombust committed Jun 12, 2024
1 parent b4502ac commit a825e9d
Show file tree
Hide file tree
Showing 10 changed files with 450 additions and 99 deletions.
177 changes: 177 additions & 0 deletions crates/analysis/src/symbol_analysis/symbols/annotated_symbols.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
use shrinkwraprs::Shrinkwrap;
use crate::symbol_analysis::symbol_path::SymbolPath;
use super::*;


/// Corresponding to @addMethod(Class) functions
#[derive(Debug, Clone, Shrinkwrap)]
#[shrinkwrap(mutable)]
pub struct AddedMemberFunctionSymbol {
pub inner: MemberFunctionSymbol
}

impl Symbol for AddedMemberFunctionSymbol {
fn typ(&self) -> SymbolType {
SymbolType::AddedMemberFunction
}

fn path(&self) -> &SymbolPath {
&self.inner.path()
}
}

impl LocatableSymbol for AddedMemberFunctionSymbol {
fn location(&self) -> &SymbolLocation {
&self.inner.location()
}
}

impl PrimarySymbol for AddedMemberFunctionSymbol { }

impl AddedMemberFunctionSymbol {
pub fn new(path: MemberCallableSymbolPath, location: SymbolLocation) -> Self {
Self {
inner: MemberFunctionSymbol::new(path, location)
}
}
}



/// Corresponding to @replaceMethod(Class) functions
#[derive(Debug, Clone, Shrinkwrap)]
#[shrinkwrap(mutable)]
pub struct ReplacedMemberFunctionSymbol {
pub inner: MemberFunctionSymbol
}

impl Symbol for ReplacedMemberFunctionSymbol {
fn typ(&self) -> SymbolType {
SymbolType::ReplacedMemberFunction
}

fn path(&self) -> &SymbolPath {
&self.inner.path()
}
}

impl LocatableSymbol for ReplacedMemberFunctionSymbol {
fn location(&self) -> &SymbolLocation {
&self.inner.location()
}
}

impl PrimarySymbol for ReplacedMemberFunctionSymbol { }

impl ReplacedMemberFunctionSymbol {
pub fn new(path: MemberCallableSymbolPath, location: SymbolLocation) -> Self {
Self {
inner: MemberFunctionSymbol::new(path, location)
}
}
}



/// Corresponding to @replaceMethod functions
#[derive(Debug, Clone, Shrinkwrap)]
#[shrinkwrap(mutable)]
pub struct ReplacedGlobalFunctionSymbol {
pub inner: GlobalFunctionSymbol
}

impl Symbol for ReplacedGlobalFunctionSymbol {
fn typ(&self) -> SymbolType {
SymbolType::ReplacedGlobalFunction
}

fn path(&self) -> &SymbolPath {
&self.inner.path()
}
}

impl LocatableSymbol for ReplacedGlobalFunctionSymbol {
fn location(&self) -> &SymbolLocation {
&self.inner.location()
}
}

impl PrimarySymbol for ReplacedGlobalFunctionSymbol { }

impl ReplacedGlobalFunctionSymbol {
pub fn new(path: GlobalCallableSymbolPath, location: SymbolLocation) -> Self {
Self {
inner: GlobalFunctionSymbol::new(path, location)
}
}
}



/// Corresponding to @wrapMethod(Class) functions
#[derive(Debug, Clone, Shrinkwrap)]
#[shrinkwrap(mutable)]
pub struct WrappedMemberFunctionSymbol {
pub inner: MemberFunctionSymbol
}

impl Symbol for WrappedMemberFunctionSymbol {
fn typ(&self) -> SymbolType {
SymbolType::WrappedMemberFunction
}

fn path(&self) -> &SymbolPath {
&self.inner.path()
}
}

impl LocatableSymbol for WrappedMemberFunctionSymbol {
fn location(&self) -> &SymbolLocation {
&self.inner.location()
}
}

impl PrimarySymbol for WrappedMemberFunctionSymbol { }

impl WrappedMemberFunctionSymbol {
pub fn new(path: MemberCallableSymbolPath, location: SymbolLocation) -> Self {
Self {
inner: MemberFunctionSymbol::new(path, location)
}
}
}



/// Corresponding to @addField(Class) vars
#[derive(Debug, Clone, Shrinkwrap)]
#[shrinkwrap(mutable)]
pub struct AddedMemberVarSymbol {
pub inner: MemberVarSymbol
}

impl Symbol for AddedMemberVarSymbol {
fn typ(&self) -> SymbolType {
SymbolType::AddedMemberVar
}

fn path(&self) -> &SymbolPath {
&self.inner.path()
}
}

impl LocatableSymbol for AddedMemberVarSymbol {
fn location(&self) -> &SymbolLocation {
&self.inner.location()
}
}

impl PrimarySymbol for AddedMemberVarSymbol { }

impl AddedMemberVarSymbol {
pub fn new(path: MemberDataSymbolPath, location: SymbolLocation) -> Self {
Self {
inner: MemberVarSymbol::new(path, location)
}
}
}
2 changes: 2 additions & 0 deletions crates/analysis/src/symbol_analysis/symbols/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod class_symbol;
mod state_symbol;
mod array_type_symbol;
mod symbol_specifiers;
mod annotated_symbols;
mod symbol_variant;
mod location;

Expand All @@ -25,5 +26,6 @@ pub use class_symbol::*;
pub use array_type_symbol::*;
pub use state_symbol::*;
pub use symbol_specifiers::*;
pub use annotated_symbols::*;
pub use symbol_variant::*;
pub use location::*;
34 changes: 30 additions & 4 deletions crates/analysis/src/symbol_analysis/symbols/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ pub enum SymbolType {
MemberFunction,
Event,
Constructor,
AddedMemberFunction,
ReplacedMemberFunction,
ReplacedGlobalFunction,
WrappedMemberFunction,

// data
EnumVariant,
Expand All @@ -53,6 +57,7 @@ pub enum SymbolType {
SuperVar,
ParentVar,
VirtualParentVar,
AddedMemberVar,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand All @@ -66,10 +71,31 @@ impl SymbolType {
pub fn category(&self) -> SymbolCategory {
use SymbolType::*;
match self {
Type | Enum | Struct | Class | State | Array => SymbolCategory::Type,
EnumVariant | Parameter | GlobalVar | MemberVar | Autobind | LocalVar |
ThisVar | SuperVar | ParentVar | VirtualParentVar => SymbolCategory::Data,
GlobalFunction | MemberFunction | Event | Constructor => SymbolCategory::Callable,
Type
| Enum
| Struct
| Class
| State
| Array => SymbolCategory::Type,
EnumVariant
| Parameter
| GlobalVar
| MemberVar
| Autobind
| LocalVar
| ThisVar
| SuperVar
| ParentVar
| VirtualParentVar
| AddedMemberVar => SymbolCategory::Data,
GlobalFunction
| MemberFunction
| Event
| Constructor
| AddedMemberFunction
| ReplacedMemberFunction
| ReplacedGlobalFunction
| WrappedMemberFunction => SymbolCategory::Callable,
}
}
}
Loading

0 comments on commit a825e9d

Please sign in to comment.