From 1e3d236aed29b8d5d2d2aadc516b6e5a0a9c7ddc Mon Sep 17 00:00:00 2001 From: Pavol Bielik Date: Sun, 25 Jan 2015 01:50:10 +0100 Subject: [PATCH] do not output constrains if there are no features --- lib/feature_extractor.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/feature_extractor.js b/lib/feature_extractor.js index 0145413b..4b36bcd9 100644 --- a/lib/feature_extractor.js +++ b/lib/feature_extractor.js @@ -49,9 +49,10 @@ function replaceMangled(code, file) { var feature_outputter = new FeatureJsonOutputter(); generateAstFeatures(toplevel, feature_outputter); generateFnamesFeatures(toplevel, feature_outputter); + generateFscopeConstraints(toplevel, feature_outputter); - //feature_outputter.string_map defines what id is assigment to each node in the final output - //therefore to assign same ids, we need to first populate by running feature extraction + //feature_outputter.string_map defines what id is assigned to each node in the final output + //therefore to assign same ids, we need to first populate string_map by running feature extraction var stream = OutputStream({beautify : true, replace_mangled_map : feature_outputter.string_map}); toplevel.print(stream); return stream.toString(); @@ -361,6 +362,7 @@ function FeatureJsonOutputter() { this.depth = 0; this.pairs = {}; this.cur_scope = {}; + this.has_features = false; } FeatureJsonOutputter.prototype.indent = function() { @@ -432,6 +434,8 @@ FeatureJsonOutputter.prototype.addFeature = function(a, b, name){ return; } + this.has_features = true; + this.openElem(); this.output += '"a": ' + a_id + ","; @@ -457,6 +461,12 @@ FeatureJsonOutputter.prototype.addSymbol = function(key){ }; FeatureJsonOutputter.prototype.dumpSymbols = function(){ + if (!this.has_features) { + this.openArray("assign"); + this.closeArray(); + return; + } + this.openArray("assign"); // var keys = Object.keys( this.string_map.map ); @@ -479,6 +489,10 @@ FeatureJsonOutputter.prototype.addToScope = function(a){ FeatureJsonOutputter.prototype.endScope = function(){ //{"cn":"!=","n":[14,366,370,372,108,40,356]} + if (!this.has_features) { + return; + } + var keys = Object.keys(this.cur_scope); if (keys.length <= 1) { return;