StructDeclSyntax

io.joern.swiftsrc2cpg.parser.SwiftNodeSyntax.StructDeclSyntax

Documentation

A struct declaration

An example of a struct declaration is

struct SomeStruct {
 let someMember: String
 var anotherMember: Int

 func foo() {
   print(someMember)
 }

 mutating func bar() {
   anotherMember = 42
 }
}

A struct declaration may be declared without any members.

struct EmptyStruct {

}

A struct declaration may include a type inheritance clause listing one or more protocols the struct conforms to.

The example below uses Hashable and Equatable protocols whose members are automatically synthesized by the compiler if the struct contains stored members that are themselves Hashable and Equatable.

struct AdvancedStruct: Hashable, Equatable {
 let someMember: String
 var anotherMember: Int
}

A struct declaration may include a generic parameter clause as well as a generic where clause.

struct Stack<Element> {
 var items: [Element] = []

 mutating func push(_ item: Element) {
   items.append(item)
 }

 mutating func pop() -> Element {
   return items.removeLast()
 }
}

Children

  • attributes: AttributeListSyntax
  • modifiers: DeclModifierListSyntax
  • structKeyword: struct
  • name: <identifier>
  • genericParameterClause: GenericParameterClauseSyntax?
  • inheritanceClause: InheritanceClauseSyntax?
  • genericWhereClause: GenericWhereClauseSyntax?
  • memberBlock: MemberBlockSyntax

Nowhere contained in

Attributes

Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait NamedDecl
trait DeclGroup
trait DeclSyntax
trait SwiftNode
class Object
trait Matchable
class Any
Show all

Members list

Value members

Inherited methods

def endColumn: Option[Int]

Attributes

Inherited from:
SwiftNode
def endLine: Option[Int]

Attributes

Inherited from:
SwiftNode
def endOffset: Option[Int]

Attributes

Inherited from:
SwiftNode
def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product
def startColumn: Option[Int]

Attributes

Inherited from:
SwiftNode
def startLine: Option[Int]

Attributes

Inherited from:
SwiftNode
def startOffset: Option[Int]

Attributes

Inherited from:
SwiftNode
override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
SwiftNode -> Any
Inherited from:
SwiftNode