Permalink
Browse files

visualization

  • Loading branch information...
1 parent 2695f91 commit 5815dd601a61642f901beeb399cd7006dc92b1f2 hochang committed Oct 24, 2012
@@ -75,12 +75,12 @@ function plan(compiled) {
creates[line.id.toString()] = line;
}
else if (line.type === 'if') {
- divescope(line.if);
- divescope(line.else);
+ divescope(line.if, line);
+ divescope(line.else, line);
}
else if (line.type === 'try') {
//dependsOn are the lines in try clause
- divescope(line.dependsOn);
+ divescope(line.dependsOn, line);
_.each(line.catchClause, function(k, mycatch){
divescope(mycatch, line);
});
@@ -194,7 +194,6 @@ function plan(compiled) {
}
if(node.scope) {
used.push(node.scope.id);
- //addListener(node, node.scope);
}
}
used.push(ret.rhs.id);
@@ -244,17 +243,9 @@ function walk(line, symbols) {
break;
case 'define':
introspectObject(line.object, symbols, line.dependsOn, line);
- if(line.fallback) {
- walk(line.fallback, symbols);
- }
break;
case 'return':
walk(line.rhs, symbols);
-
- if(line.fallback) {
- walk(line.fallback, symbols);
- }
-
// Route
if(line.route) {
introspectString(line.route.path, symbols, line.dependsOn);
@@ -269,9 +260,6 @@ function walk(line, symbols) {
case 'delete':
introspectFrom(line, [line.source], symbols);
line = introspectWhere(line, symbols);
- if(line.fallback) {
- walk(line.fallback, symbols);
- }
break;
case 'insert':
introspectFrom(line, [line.source], symbols);
@@ -284,9 +272,6 @@ function walk(line, symbols) {
if(line.jsonObj) {
introspectString(line.jsonObj.value, symbols, line.dependsOn, line);
}
- if(line.fallback) {
- walk(line.fallback, symbols);
- }
break;
case 'update':
introspectFrom(line, [line.source], symbols);
@@ -299,9 +284,6 @@ function walk(line, symbols) {
introspectFrom(line.joiner, line.joiner.fromClause, symbols, line);
introspectWhere(line.joiner, symbols, line);
}
- if(line.fallback) {
- walk(line.fallback, symbols);
- }
break;
case 'if':
addDep(line, line.dependsOn, line.condition, symbols);
@@ -321,10 +303,6 @@ function walk(line, symbols) {
addDep(line, line.dependsOn, dependency, symbols);
walk(dependency, symbols);
});
- if(line.fallback) {
- walk(line.fallback, symbols);
- }
-
break;
case 'try':
_.each(line.dependsOn, function(tryline){
@@ -344,6 +322,9 @@ function walk(line, symbols) {
}
break;
}
+ if(line.fallback) {
+ walk(line.fallback, symbols);
+ }
}
function addListener(node, listener) {
@@ -475,7 +475,6 @@ TryClause = 'try' insig '{' insig tryClause:TryCrlf+ insig '}' catchClause:Catch
type : 'try',
dependsOn : tryClause,
catchClause : catchClause,
- exceptions : [],
finallyClause : finallyClause || undefined
}
}
@@ -515,9 +514,7 @@ LogicParen = '(' insig p:LogicPhrase insig ')' insig {
LogicPhrase = OrPhrase / AndPhrase / NotPhrase / NormalPhrase;
OrPhrase = s1:(AndPhrase / NotPhrase / NormalPhrase) insig sn:OrTail{
- if(sn){
- s1.fallback = sn;
- }
+ s1.fallback = sn;
return s1;
}
OrTail = '||' insig s:LogicStatement insig{
@@ -17,7 +17,7 @@
"use strict";
var compiler = require('../lib/compiler');
-
+var _ = require('underscore')
module.exports = {
'try catch': function(test) {
var q = "try {select * from aaa;\n\
@@ -84,7 +84,6 @@ $(document).ready(function() {
$('#step').hide();
emitterID = 0;
runQuery(statement, escaped, compiled);
- pastePic();
});
$('#debug').unbind();
@@ -96,7 +95,6 @@ $(document).ready(function() {
step = 1;
runQuery(statement, escaped, compiled, true);
$('#step').show();
- pastePic(compiled);
});
$('#step').unbind();
@@ -319,7 +317,7 @@ $(document).ready(function() {
// Tell the server what notifications to receive
function subscribe(socket, uri) {
var events = ['ack', 'compile-error', 'statement-error', 'statement-in-flight',
- 'statement-success', 'statement-request', 'statement-response', 'script-done', 'ql.io-debug'];
+ 'statement-success', 'statement-request', 'statement-response', 'script-done', 'ql.io-debug', 'ql.io-visualization'];
var packet = {
type: 'events',
data: JSON.stringify(events)
@@ -421,6 +419,10 @@ $(document).ready(function() {
opacity: 1.0
});
});
+ emitter.on('ql.io-visualization', function(data){
+ $('#dependencyMap').attr('src', data);
+ $('#dependencyMap').show();
+ })
emitter.on('script-done', function (data) {
markers.push(editor.setMarker(data.line - 1, data.elapsed + ' ms', 'green'));
});
@@ -435,52 +437,14 @@ $(document).ready(function() {
id : emitterID
};
socket.send(JSON.stringify(packet));
+ delPic();
}
- function pastePic(forest) {
- function getDepHelper(tree) {
- sofar = "";
+ function delPic(){
+ $('#dependencyMap').hide()
+ }
+});
+
+
- if (tree.hasOwnProperty('rhs')) {
- sofar += getDepHelper(tree.rhs);
- }
- var line_num = tree.line ? tree.line : 'return';
- if (tree.hasOwnProperty('fallback') && tree.fallback.dependsOn.length > 0) {
- var fallback = tree.fallback;
- for (var j = 0; j < fallback.dependsOn.length; j++) {
- var addition = '%5B'+line_num+'%5D->%5Bnote:'+fallback.dependsOn[j].line+'%5D,';
- sofar += addition;
- sofar += getDepHelper(fallback.dependsOn[j]);
- }
- }
- if (tree.dependsOn && tree.dependsOn.length > 0) {
- for (var j = 0; j < tree.dependsOn.length; j++) {
- var dep = tree.dependsOn[j];
- var addition = '%5B'+line_num+'%5D-%3E%5B'+dep.line+'%5D,'
- sofar += addition;
- sofar += getDepHelper(dep);
- }
- }
- return sofar;
- }
- var deptxt = '';
- if (forest) {
- for (var k = 0; k < forest.length; k++) {
- deptxt += getDepHelper(forest[k]);
- }
- /*$.ajax({
- type: 'POST',
- url: 'http://yuml.me/diagram/plain/class/',
- body: {dsl_text: '[a]'},
- success: function(){
- alert('good')
- },
- error: function(data){console.log(data)}
- }) */
- //$.get('http://yuml.me/diagram/plain/class/[a]', function(){alert('nice')})
- deptxt = 'http://ql-2:3026/diagram/scruffy;/class/'+deptxt.substring(0, deptxt.length-1)+'.png';
- }
- $('#dependencyMap').attr('src', deptxt);
- }
-});
@@ -41,6 +41,7 @@ var configLoader = require('./engine/config.js'),
LogEmitter = require('./engine/log-emitter.js'),
winston = require('winston'),
compiler = require('ql.io-compiler'),
+ visualization = require('./engine/visualization'),
_ = require('underscore'),
EventEmitter = require('events').EventEmitter,
util = require('util'),
@@ -285,6 +286,9 @@ Engine.prototype.execute = function() {
timeoutID = setTimeout( function () {
emitter.emit(eventTypes.KILL);
}, 1800000);// clear unused session in 30 minutes.
+ //try get visualization picture.
+ visualization.getPic(plan, emitter);
+
}
// Initialize the exec state
@@ -306,6 +310,7 @@ Engine.prototype.execute = function() {
init(line);
});
_.each(statement.catchClause, function(currentcatch){
+ init(currentcatch.condition);
_.each(currentcatch.lines, function(line){
init(line);
});
@@ -342,14 +347,45 @@ Engine.prototype.execute = function() {
/* Skip assign statement. Make it undefined, and trigger listener
*/
function skipVar(statement){
- context[statement.assign] = undefined;
+ if (execState[statement.id].state == eventTypes.STATEMENT_SUCCESS){
+ return;
+ }
execState[statement.id].state = eventTypes.STATEMENT_SUCCESS;
- _.each(statement.listeners, function(listener) {
- execState[listener.id].count--;
- if (!(listener.fbhold)){
- sweep(listener);
- }
- });
+ switch(statement.type){
+ case 'try':
+ _.each(statement.dependsOn, function(tryline){//these are just lines within try{}
+ skipVar(tryline);
+ });
+ _.each(statement.catchClause, function(mycatch,k){
+ _.each(mycatch.lines, function(catchline){
+ skipVar(catchline);
+ });
+ });
+ _.each(statement.finallyClause, function(finallyline){
+ skipVar(finallyline);
+ });
+ break;
+ case 'if':
+ _.each(statement.if, function(st) {
+ skipVar(st);
+ });
+ _.each(statement.else, function(st) {
+ skipVar(st);
+ });
+ break;
+ default:
+ if(!statement.assign){
+ return;
+ }
+ context[statement.assign] = null;
+ _.each(statement.listeners, function(listener) {
+ execState[listener.id].count--;
+ if (!(listener.fbhold)){
+ sweep(listener);
+ }
+ });
+ }
+
}
// scope is complex to execute, handle separately
@@ -388,15 +424,16 @@ Engine.prototype.execute = function() {
if(skip) {
return;
}
+ if(statement.scope && execState[statement.scope.id].state === eventTypes.STATEMENT_WAITING) {
+ sweep(statement.scope);
+ return;
+ }
_.each(statement.dependsOn, function(dependency) {
if(execState[dependency.id].state === eventTypes.STATEMENT_WAITING) {
// Exec the dependency
sweep(dependency);
}
});
- if(statement.scope && execState[statement.scope.id].state === eventTypes.STATEMENT_WAITING) {
- sweep(statement.scope);
- }
if(statement.rhs) {
_.each(statement.rhs.dependsOn, function(dependency) {
if(execState[dependency.id].state === eventTypes.STATEMENT_WAITING) {
@@ -111,4 +111,6 @@ exports.DEBUG = 'ql.io-debug';
exports.DEBUG_STEP = 'ql.io-debug-step';
+exports.VISUALIZATION = 'ql.io-visualization'
+
exports.KILL = 'ql.io-kill';
@@ -48,14 +48,14 @@ exports.throw = function(opts, statement, parentEvent, cb) {
assert.ok(statement, 'Argument cb can not be undefined');
var tables = opts.tables,
- throwTx = opts.logEmitter.beginEvent({
- parent: parentEvent,
- type: 'throw',
- message: {
- line: statement.line
- },
- cb: cb})
- if(!opts.context[statement.err]){// this is simple field check, no logic.exec required
+ throwTx = opts.logEmitter.beginEvent({
+ parent: parentEvent,
+ type: 'throw',
+ message: {
+ line: statement.line
+ },
+ cb: cb})
+ if(!opts.context.hasOwnProperty(statement.err)){// this is simple field check, no logic.exec required
opts.context[statement.err] = statement.err;
}
throwTx.cb(null, statement.err);
Oops, something went wrong.

0 comments on commit 5815dd6

Please sign in to comment.