Skip to content

Commit

Permalink
Classes support (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmichaelk authored Sep 15, 2024
1 parent 60d62d3 commit 2ed94ee
Show file tree
Hide file tree
Showing 9 changed files with 413 additions and 3 deletions.
4 changes: 4 additions & 0 deletions internal/lsp/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func getSignature(def *ttcn3.Node) string {
sig.WriteString("\n ")
sig.Write(content[node.Return.Pos():node.Return.End()])
}
case *syntax.ClassTypeDecl:
if node.LBrace != nil {
sig.Write(content[node.Pos() : node.LBrace.Pos()-1])
}
case *syntax.ValueDecl, *syntax.TemplateDecl, *syntax.FormalPar, *syntax.StructTypeDecl, *syntax.MapTypeDecl, *syntax.ComponentTypeDecl, *syntax.EnumTypeDecl, *syntax.PortTypeDecl:
sig.Write(content[def.Node.Pos():def.Node.End()])
case *syntax.Field:
Expand Down
2 changes: 2 additions & 0 deletions internal/lsp/semantic_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ func DefinitionToken(tree *ttcn3.Tree, id syntax.Node) (SemanticTokenType, Seman
return Parameter, Declaration
case *syntax.StructTypeDecl:
return Struct, Definition
case *syntax.ClassTypeDecl:
return Class, Definition
case *syntax.MapTypeDecl:
return Map, Definition
case *syntax.EnumTypeDecl:
Expand Down
5 changes: 4 additions & 1 deletion ttcn3/scopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func NewScope(n syntax.Node, tree *Tree) *Scope {
case *syntax.BehaviourSpec:
scp.add(n.Params)

case *syntax.Module:
case *syntax.Module, *syntax.ClassTypeDecl:
n.Inspect(func(n syntax.Node) bool {
switch n := n.(type) {
// Groups are not visible in the global scope.
Expand Down Expand Up @@ -235,6 +235,9 @@ func (scp *Scope) add(n syntax.Node) error {
case *syntax.StructTypeDecl:
scp.Insert(n, n.Name)

case *syntax.ClassTypeDecl:
scp.Insert(n, n.Name)

case *syntax.MapTypeDecl:
scp.Insert(n, n.Name)

Expand Down
25 changes: 25 additions & 0 deletions ttcn3/syntax/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,13 @@ type (
With *WithSpec
}

// A ConstructorDecl represents a class constructor definition.
ConstructorDecl struct {
CreateTok Token // CREATE
Params *FormalPars // Formal parameter list
Body *BlockStmt // Body
}

// A SignatureDecl represents a signature type for procedure based communication.
SignatureDecl struct {
Tok Token // Position of "signature"
Expand Down Expand Up @@ -672,6 +679,23 @@ type (
With *WithSpec
}

// A StructTypeDecl represents a name struct type.
ClassTypeDecl struct {
TypeTok Token // Position of "type"
Kind Token // CLASS
Modif Token // "@abstract" or nil
Name *Ident // Name
ExtendsTok Token
Extends []Expr
RunsOn *RunsOnSpec // Optional runs-on-spec
Mtc *MtcSpec // Optional mtc-spec
System *SystemSpec // Optional system-spec
LBrace Token // Position of "{"
Defs []*ModuleDef
RBrace Token // Position of }"
With *WithSpec
}

MapTypeDecl struct {
TypeTok Token
Spec *MapSpec
Expand Down Expand Up @@ -757,6 +781,7 @@ func (x *FuncDecl) declNode() {}
func (x *SignatureDecl) declNode() {}
func (x *SubTypeDecl) declNode() {}
func (x *StructTypeDecl) declNode() {}
func (x *ClassTypeDecl) declNode() {}
func (x *MapTypeDecl) declNode() {}
func (x *EnumTypeDecl) declNode() {}
func (x *BehaviourTypeDecl) declNode() {}
Expand Down
Loading

0 comments on commit 2ed94ee

Please sign in to comment.