Skip to content

Commit 06038d5

Browse files
committed
Improve comments about Fields
1 parent e01e40c commit 06038d5

File tree

2 files changed

+94
-8
lines changed

2 files changed

+94
-8
lines changed

go/ql/lib/semmle/go/AST.qll

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,24 +194,27 @@ class DeclParent extends @declparent, AstNode {
194194
}
195195

196196
/**
197-
* An AST node whose children include fields.
197+
* An AST node whose children include field declarations.
198+
*
199+
* A field declaration can be in a struct, a function (for parameter or result
200+
* variables), or an interface (in which case it is a method or embedding spec).
198201
*/
199202
class FieldParent extends @fieldparent, AstNode {
200203
/**
201-
* Gets the `i`th field of this node.
204+
* Gets the `i`th field declaration of this node.
202205
*
203-
* Note that the precise indices of fields are considered an implementation detail
204-
* and are subject to change without notice.
206+
* Note that the precise indices of field declarations are considered an
207+
* implementation detail and are subject to change without notice.
205208
*/
206209
FieldBase getField(int i) { fields(result, this, i) }
207210

208211
/**
209-
* Gets a child field of this node in the AST.
212+
* Gets a child field declaration of this node in the AST.
210213
*/
211214
FieldBase getAField() { result = this.getField(_) }
212215

213216
/**
214-
* Gets the number of child fields of this node.
217+
* Gets the number of child field declarations of this node.
215218
*/
216219
int getNumFields() { result = count(this.getAField()) }
217220
}

go/ql/lib/semmle/go/Decls.qll

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,19 @@ class AliasSpec extends @aliasspec, TypeSpec { }
416416
class TypeDefSpec extends @typedefspec, TypeSpec { }
417417

418418
/**
419-
* A field declaration, of a struct, a function (in which case this is a parameter or result variable),
420-
* or an interface (in which case this is a method or embedding spec).
419+
* A field declaration, in a struct, a function (for parameter or result
420+
* variables), or an interface (in which case this is a method or embedding
421+
* spec).
422+
*
423+
* Examples:
424+
*
425+
* ```go
426+
* s string
427+
* x, y int
428+
* Close() error
429+
* io.Reader
430+
* ~int | float32
431+
* ```
421432
*/
422433
class FieldBase extends @field, ExprParent {
423434
/**
@@ -433,6 +444,13 @@ class FieldBase extends @field, ExprParent {
433444

434445
/**
435446
* A field declaration in a struct type.
447+
*
448+
* Examples:
449+
*
450+
* ```go
451+
* Name string `json:"name"`
452+
* x, y int
453+
* ```
436454
*/
437455
class FieldDecl extends FieldBase, Documentable, ExprParent {
438456
StructTypeExpr st;
@@ -464,6 +482,12 @@ class FieldDecl extends FieldBase, Documentable, ExprParent {
464482

465483
/**
466484
* An embedded field declaration in a struct.
485+
*
486+
* Examples:
487+
*
488+
* ```go
489+
* io.Reader
490+
* ```
467491
*/
468492
class EmbeddedFieldDecl extends FieldDecl {
469493
EmbeddedFieldDecl() { not exists(this.getNameExpr(_)) }
@@ -473,6 +497,13 @@ class EmbeddedFieldDecl extends FieldDecl {
473497

474498
/**
475499
* A function parameter or result variable declaration.
500+
*
501+
* Examples:
502+
*
503+
* ```go
504+
* name string
505+
* x, y int
506+
* ```
476507
*/
477508
class ParameterOrResultDecl extends FieldBase, Documentable, ExprParent {
478509
int rawIndex;
@@ -507,6 +538,13 @@ class ParameterOrResultDecl extends FieldBase, Documentable, ExprParent {
507538

508539
/**
509540
* A parameter declaration.
541+
*
542+
* Examples:
543+
*
544+
* ```go
545+
* name string
546+
* x, y int
547+
* ```
510548
*/
511549
class ParameterDecl extends ParameterOrResultDecl {
512550
ParameterDecl() { rawIndex >= 0 }
@@ -524,6 +562,13 @@ class ParameterDecl extends ParameterOrResultDecl {
524562

525563
/**
526564
* A receiver declaration in a function declaration.
565+
*
566+
* Examples:
567+
*
568+
* ```go
569+
* p *Point
570+
* r io.Reader
571+
* ```
527572
*/
528573
class ReceiverDecl extends FieldBase, Documentable, ExprParent {
529574
FuncDecl fd;
@@ -547,6 +592,14 @@ class ReceiverDecl extends FieldBase, Documentable, ExprParent {
547592

548593
/**
549594
* A result variable declaration.
595+
*
596+
* Examples:
597+
*
598+
* ```go
599+
* error
600+
* r io.Reader
601+
* x, y int
602+
* ```
550603
*/
551604
class ResultVariableDecl extends ParameterOrResultDecl {
552605
ResultVariableDecl() { rawIndex < 0 }
@@ -564,6 +617,15 @@ class ResultVariableDecl extends ParameterOrResultDecl {
564617

565618
/**
566619
* A type parameter declaration in a type specification.
620+
*
621+
* Examples:
622+
*
623+
* ```go
624+
* T any
625+
* S, T comparable
626+
* K ~int32 | float32
627+
* _ any
628+
* ```
567629
*/
568630
class TypeParamDecl extends @typeparamdecl, Documentable, ExprParent {
569631
TypeParamDecl() { typeparamdecls(this, _, _) }
@@ -615,6 +677,14 @@ class TypeParamDecl extends @typeparamdecl, Documentable, ExprParent {
615677

616678
/**
617679
* A method or embedding specification in an interface type expression.
680+
*
681+
* Examples:
682+
*
683+
* ```go
684+
* Read([]byte) (int, error)
685+
* io.Reader
686+
* ~int32 | float32
687+
* ```
618688
*/
619689
class InterfaceMemberSpec extends FieldBase, Documentable, ExprParent {
620690
InterfaceTypeExpr ite;
@@ -636,6 +706,12 @@ class InterfaceMemberSpec extends FieldBase, Documentable, ExprParent {
636706

637707
/**
638708
* A method specification in an interface.
709+
*
710+
* Examples:
711+
*
712+
* ```go
713+
* Read([]byte) (int, error)
714+
* ```
639715
*/
640716
class MethodSpec extends InterfaceMemberSpec {
641717
Expr name;
@@ -654,6 +730,13 @@ class MethodSpec extends InterfaceMemberSpec {
654730

655731
/**
656732
* An embedding specification in an interface.
733+
*
734+
* Examples:
735+
*
736+
* ```go
737+
* io.Reader
738+
* ~int32 | float32
739+
* ```
657740
*/
658741
class EmbeddingSpec extends InterfaceMemberSpec {
659742
EmbeddingSpec() { not exists(this.getChildExpr(1)) }

0 commit comments

Comments
 (0)