summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2018-09-26 17:52:01 +0300
committerJari Vetoniemi <mailroxas@gmail.com>2018-09-26 17:52:01 +0300
commit06c4761a3a2b129d221851391ced380e233c6ee1 (patch)
tree057beb15e444149db6f96721fe1bb38b19d1c352 /src
parente9e8d7bdac8ff71e8a9051264fabc13ce8964f61 (diff)
Indicate fields with slices in output
Diffstat (limited to 'src')
-rw-r--r--src/compiler/compiler.lm25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/compiler/compiler.lm b/src/compiler/compiler.lm
index 052d4f7..72e000f 100644
--- a/src/compiler/compiler.lm
+++ b/src/compiler/compiler.lm
@@ -105,15 +105,23 @@ context fspec
def filter
[`| function:reference::function::type]
- def length
+ def subscript
[`[ expr:expr::bracket::type `: slice:expr::bracket::type `]]
| [`[ expr:expr::bracket::type `]]
def extra
+ # if set, this field has trivial length, otherwise need to read subscripts
length:collapser::collapsed
- [length* filter:filter* visual:visual? endianess:endianess?] {
+ [subscript:subscript* filter:filter* visual:visual? endianess:endianess?] {
f:str = ''
- for l:length in repeat(r1) {
+ has_slice:bool
+ for l:subscript in repeat(r1) {
+ if (l.slice) {
+ f = ''
+ has_slice = true
+ break
+ }
+
if (f != '')
f = f + '*'
@@ -123,7 +131,12 @@ context fspec
f = f + '(' + $l.expr.collapsed + ')'
}
}
- lhs.length = collapser::collapsestr(f)
+
+ if (f == '' && !has_slice)
+ f = '1'
+
+ if (f != '')
+ lhs.length = collapser::collapsestr(f)
}
def type
@@ -260,11 +273,13 @@ print_declaration(d:fspec::declaration::type)
print(' it has a variable length that needs to be computed with formula `', $d.extra.length, '`\n')
} else {
if (d.extra.length.result.value.number) {
- print(' it has a constant length of `', $d.extra.length.result.value, '`\n')
+ print(' it has a constant length of ', $d.extra.length.result.value, '\n')
} else if (d.extra.length.result.value.string) {
print(' its length will increase until pattern `', $d.extra.length.result.value.string.raw, '` has been read from stream\n')
}
}
+ } else {
+ print(' the subscripts contain slices, and thus needs some runtime loops to be computed\n')
}
for f:fspec::declaration::filter in repeat(d.extra.filter)