aboutsummaryrefslogtreecommitdiff
path: root/src/parser.js
diff options
context:
space:
mode:
authoralon@honor <none@none>2010-09-14 20:10:32 -0700
committeralon@honor <none@none>2010-09-14 20:10:32 -0700
commit0dd0f40a7a2c2fdf5e8344d492b3575fab8268a6 (patch)
treed44f340caa56c9533483dacc72daf66b338c5f5b /src/parser.js
parenta8d7622f69054a6970906b2512f3107ea1e29c58 (diff)
proper flattening of nested structures +test
Diffstat (limited to 'src/parser.js')
-rw-r--r--src/parser.js26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/parser.js b/src/parser.js
index e4beee08..6f737c43 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -1107,6 +1107,7 @@ function analyzer(data) {
while (more) {
more = false;
values(item.types).forEach(function(type) {
+ if (type.flatIndexes) return;
var ready = true;
type.fields.forEach(function(field) {
//print('// zz getT: ' + type.name_ + ' : ' + field);
@@ -1126,31 +1127,26 @@ function analyzer(data) {
return;
}
type.flatSize = 0;
- type.needsFlattening = false;
var sizes = [];
type.flatIndexes = type.fields.map(function(field) {
- var curr = type.flatSize;
+ var soFar = type.flatSize;
+ var size = 1;
if (isStructType(field)) {
- dprint('types', 'type: ' + type.name_ + ' is so far of size ' + curr + ' and has ' + field + ' which is sized ' + item.types[field].flatSize);
- var size = item.types[field].flatSize;
- type.flatSize += size;
- sizes.push(size);
- type.needsFlattening = true;
- } else {
- type.flatSize ++;
+ size = item.types[field].flatSize;
}
- return curr;
+ type.flatSize += size;
+ sizes.push(size);
+ return soFar;
});
- dprint('types', 'type: ' + type.name_ + ' has FINAL size of ' + type.flatSize);
- if (type.needsFlattening && dedup(sizes).length == 1) {
+ if (dedup(sizes).length == 1) {
type.flatFactor = sizes[0];
}
+ type.needsFlattening = (this.flatFactor != 1);
+ dprint('types', 'type: ' + type.name_ + ' : ' + JSON.stringify(type.fields));
+ dprint('types', ' has final size of ' + type.flatSize + ', flatting: ' + type.needsFlattening + ' ? ' + (type.flatFactor ? type.flatFactor : JSON.stringify(type.flatIndexes)));
});
}
- values(item.types).forEach(function(type) {
- dprint('types', 'type: ' + type.name_);// + ' : ' + JSON.stringify(type.fields));
- });
item.typed = true;
return [item];
},