-
Notifications
You must be signed in to change notification settings - Fork 126
Conversation
8023b53
to
3e40b99
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff, thank you very much for tackling this! I have a bunch of fairly minor comments, but on the whole this looks great.
+---------------------------+--------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------+ | ||
| ``^x`` | `ComplementExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$ComplementExpr.html>`__ | `BitwiseUnaryExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$BitwiseUnaryExpr.html>`__ | | ||
+---------------------------+--------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------+ | ||
| ``*x`` | `DerefExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$DerefExpr.html>`__ | | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually a StarExpr
. Class DerefExpr
exists and corresponds to something the Go compiler frontend claims to emit, but it actually never does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be worth adding a cautionary note to that effect to the qldoc of DerefExpr
. Could you do that in this PR?
| .. _VariableName: https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$VariableName.html | .. _DefineStmt: https://help.semmle.com/qldoc/go/semmle/go/Stmt.qll/type.Stmt$DefineStmt.html | .. _SimpleAssignStmt: https://help.semmle.com/qldoc/go/semmle/go/Stmt.qll/type.Stmt$SimpleAssignStmt.html | | | ||
| .. _Expr: https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$Expr.html | | .. _Assignment: https://help.semmle.com/qldoc/go/semmle/go/Stmt.qll/type.Stmt$Assignment.html | | | ||
+---------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------+ | ||
| Expr_ ``...`` ``+=`` Expr_ ``...`` | AddAssignStmt_ | CompoundAssignStmt_, Assignment_ | | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe lhs and rhs for compound assignments must always be singletons (cf https://golang.org/ref/spec#Assignments).
================================== | ||
AST class reference — Learn CodeQL | ||
================================== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
================================== | |
AST class reference — Learn CodeQL | |
================================== | |
Abstract syntax tree classes for Go | |
=================================== | |
CodeQL has a large selection of classes for working with the abstract syntax tree representation of Go programs. | |
The abstract syntax tree (AST) represents the syntactic structure of a program. Nodes in the AST represent elements such as statements and expressions. |
+-------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+ | ||
| ``struct {x, y int; z float32}`` | `StructTypeExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$StructTypeExpr.html>`__ | | | ||
+-------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+ | ||
| ``fun c(a, b int, c float32) (float32, bool)`` | `FuncTypeExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$FuncTypeExpr.html>`__ | | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ``fun c(a, b int, c float32) (float32, bool)`` | `FuncTypeExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$FuncTypeExpr.html>`__ | | | |
| ``func c(a, b int, c float32) (float32, bool)`` | `FuncTypeExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$FuncTypeExpr.html>`__ | | |
| ``chan float64`` | `SendRecvChanTypeExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$SendRecvChanTypeExpr.html>`__ | `ChanTypeExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$ChanTypeExpr.html>`__ | | ||
+-------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+ | ||
|
||
Expressions representing syntactic context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not very clear what this means. Could you try to rephrase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't think of a good way of expressing it. "Expression classes which require syntactic context"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe remove this section and instead add remarks for Ident
and SelectorExpr
pointing people at these more specialised classes. I think those are the most important ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be a shame to lose all that info because it seems useful. I've reworked it as a "Name expressions" section and another table in the Miscellaneous section. Let me know what you think.
- `ValueExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$ValueExpr.html>`__: | ||
an expression that can be evaluated to a value (as opposed to | ||
expressions that refer to a package, a type, or a statement | ||
label). This generalises |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
label). This generalises | |
label). This generalizes |
(Our public-facing documentation generally uses US spelling.)
+------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+ | ||
| ``x.( `TypeExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$TypeExpr.html>`__ )`` | `TypeAssertExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$TypeAssertExpr.html>`__ | | | ||
+------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+ | ||
| ``*x`` | `StarExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$StarExpr.html>`__ | | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps worth remarking here that a StarExpr
can either be a TypeExpr
or a ValueExpr
, depending on context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost good to go, just a few minor comments left.
ql/src/semmle/go/Expr.qll
Outdated
* ```go | ||
* *p | ||
* ``` | ||
* A unary pointer-dereference expression. Never actually emitted by the go compiler - StarExpr is used instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* A unary pointer-dereference expression. Never actually emitted by the go compiler - StarExpr is used instead. | |
* A unary pointer-dereference expression. | |
* | |
* This class exists for compatibility reasons only and should not normally be used directly. Use `StarExpr` instead. |
or a | ||
`FunctionName <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$FunctionName.html>`__, | ||
depending on what sort of entity the name refers to. | ||
The following classes relate to what sort of entity the name refers to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would prefer organizing this as a nested list rather than a table.
| ``f(x)`` | `CallExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$CallExpr.html>`__ | `CallOrConversionExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$CallOrConversionExpr.html>`__ | | | ||
+----------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ||
|
||
The following classes do not have a standard syntax. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes it sound like something is wrong or broken. Perhaps rephrase as "The following classes organize expressions by the kind of entity they refer to" or something like that, and use a list instead of a table.
+------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ||
| `ValueExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$BadExpr.html>`__ | an expression that can be evaluated to a value (as opposed to expressions that refer to a package, a type, or a statement label). This generalizes `ReferenceExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$ReferenceExpr.html>`__ | | ||
+------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ||
| `BadExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$BadExpr.html>`__ | an expression that cannot be parsed | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps put into one of the other tables, similar to BadStmt
?
Looking good; thanks for bearing with me! I just noticed one thing that may be worth addressing: for statements, you provide schematic syntax (as in " Now I can see that it is not helpful to give schematic syntax for literals, but perhaps we could do it for the other expressions? So instead of "x |
No problem @max-schaefer , I'm very happy to improve it as much as possible now so I don't need to come back to it later. I learned how to avoid unwanted spaces in RST, so I've done that as well as carrying out your suggestion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff, thanks!
One last organisational thing: could you rebase this onto the rc/1.24
branch and change the PR to target that branch? As discussed with @felicitymay, we'll want to put a copy of this reference onto the rc/1.24
branch of https://github.com/github/codeql to expedite publication, and it would probably make sense to do the same in this repo for consistency.
20844db
to
7fc4d1d
Compare
7fc4d1d
to
ec53bd9
Compare
I didn't know how to do that in rst before
ec53bd9
to
69eb043
Compare
🎉 Next, could you make a PR against the |
I have now done that: github/codeql#3675 |
Here is a draft AST class reference for codeql-go. The ordering is probably a bit weird, because I based it on the java one and added go-specific classes at the end of each table.