diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2023-11-29 16:01:41 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-02-19 11:54:01 +0000 |
| commit | e59ec59b027f921a6bfbe5014b15c2a802445ada (patch) | |
| tree | 1c69d1db1b34e0b53d620f9fe272cf9f374b1400 /pkg/ast/ast.go | |
| parent | 164800ebad7f26d05eefb0095d190462ed97bee0 (diff) | |
pkg/ast: support expressions with ast.Type
So far they have the following grammar:
OP = "==", "!=", "&"
value-expr = value-expr OP value-expr
| factor
factor = "(" and-expr ")"
| integer
| identifier
| string
Operators are left associative, e.g. A & B & C is the same as
(A & B) & C.
Further restrictions will be imposed in pkg/compiler.
This will help implement conditionally included fields.
Diffstat (limited to 'pkg/ast/ast.go')
| -rw-r--r-- | pkg/ast/ast.go | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/pkg/ast/ast.go b/pkg/ast/ast.go index 2458c1245..2726af602 100644 --- a/pkg/ast/ast.go +++ b/pkg/ast/ast.go @@ -252,15 +252,35 @@ func (n *Int) GetName() string { return n.Ident } +type Operator int + +const ( + OperatorCompareEq = iota + 1 + OperatorCompareNeq + OperatorBinaryAnd +) + +type BinaryExpression struct { + Pos Pos + Operator Operator + Left *Type + Right *Type +} + +func (n *BinaryExpression) Info() (Pos, string, string) { + return n.Pos, "binary-expression", "" +} + type Type struct { Pos Pos - // Only one of Value, Ident, String is filled. - Value uint64 - ValueFmt IntFmt - Ident string - String string - StringFmt StrFmt - HasString bool + // Only one of Value, Ident, String, Expression is filled. + Value uint64 + ValueFmt IntFmt + Ident string + String string + StringFmt StrFmt + HasString bool + Expression *BinaryExpression // Parts after COLON (for ranges and bitfields). Colon []*Type // Sub-types in []. |
