aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/ast/ast.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-05-22 05:28:31 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-08-18 11:26:50 +0200
commit127a9c2b65ae07f309e839c3b8e5ab2ee7983e56 (patch)
tree3a4dd2af0a2fc09b2bba1dad738c7657d1b0de1d /pkg/ast/ast.go
parent5809a8e05714bda367f3fd57f9b983a3403f04b0 (diff)
pkg/ast: new parser for sys descriptions
The old parser in sys/sysparser is too hacky, difficult to extend and drops debug info too early, so that we can't produce proper error messages. Add a new parser that is build like a proper language parser and preserves full debug info for every token.
Diffstat (limited to 'pkg/ast/ast.go')
-rw-r--r--pkg/ast/ast.go118
1 files changed, 118 insertions, 0 deletions
diff --git a/pkg/ast/ast.go b/pkg/ast/ast.go
new file mode 100644
index 000000000..27497b2a9
--- /dev/null
+++ b/pkg/ast/ast.go
@@ -0,0 +1,118 @@
+// Copyright 2017 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+// Package ast parses and formats sys files.
+package ast
+
+// Pos represents source info for AST nodes.
+type Pos struct {
+ File string
+ Off int // byte offset, starting at 0
+ Line int // line number, starting at 1
+ Col int // column number, starting at 1 (byte count)
+}
+
+// Top-level AST nodes:
+
+type NewLine struct {
+ Pos Pos
+}
+
+type Comment struct {
+ Pos Pos
+ Text string
+}
+
+type Include struct {
+ Pos Pos
+ File *String
+}
+
+type Incdir struct {
+ Pos Pos
+ Dir *String
+}
+
+type Define struct {
+ Pos Pos
+ Name *Ident
+ Value *Int
+}
+
+type Resource struct {
+ Pos Pos
+ Name *Ident
+ Base *Ident
+ Values []*Int
+}
+
+type Call struct {
+ Pos Pos
+ Name *Ident
+ Args []*Field
+ Ret *Type
+}
+
+type Struct struct {
+ Pos Pos
+ Name *Ident
+ Fields []*Field
+ Attrs []*Ident
+ Comments []*Comment
+ IsUnion bool
+}
+
+type IntFlags struct {
+ Pos Pos
+ Name *Ident
+ Values []*Int
+}
+
+type StrFlags struct {
+ Pos Pos
+ Name *Ident
+ Values []*String
+}
+
+// Not top-level AST nodes:
+
+type Ident struct {
+ Pos Pos
+ Name string
+}
+
+type String struct {
+ Pos Pos
+ Value string
+}
+
+type Int struct {
+ Pos Pos
+ // Only one of Value, Ident, CExpr is filled.
+ Value uint64
+ ValueHex bool // says if value was in hex (for formatting)
+ Ident string
+ CExpr string
+}
+
+type Type struct {
+ Pos Pos
+ // Only one of Value, Ident, String is filled.
+ Value uint64
+ ValueHex bool
+ Ident string
+ String string
+ // Part after COLON (for ranges and bitfields).
+ Value2 uint64
+ Value2Hex bool
+ Ident2 string
+ Args []*Type
+}
+
+type Field struct {
+ Pos Pos
+ Name *Ident
+ Type *Type
+ NewBlock bool // separated from previous fields by a new line
+ Comments []*Comment
+}