1 // Generated by CoffeeScript 1.10.0
4 indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
6 exports.Scope = Scope = (function() {
7 function Scope(parent, expressions, method, referencedVars) {
10 this.expressions = expressions;
12 this.referencedVars = referencedVars;
23 this.root = (ref = (ref1 = this.parent) != null ? ref1.root : void 0) != null ? ref : this;
26 Scope.prototype.add = function(name, type, immediate) {
27 if (this.shared && !immediate) {
28 return this.parent.add(name, type, immediate);
30 if (Object.prototype.hasOwnProperty.call(this.positions, name)) {
31 return this.variables[this.positions[name]].type = type;
33 return this.positions[name] = this.variables.push({
40 Scope.prototype.namedMethod = function() {
42 if (((ref = this.method) != null ? ref.name : void 0) || !this.parent) {
45 return this.parent.namedMethod();
48 Scope.prototype.find = function(name) {
49 if (this.check(name)) {
52 this.add(name, 'var');
56 Scope.prototype.parameter = function(name) {
57 if (this.shared && this.parent.check(name, true)) {
60 return this.add(name, 'param');
63 Scope.prototype.check = function(name) {
65 return !!(this.type(name) || ((ref = this.parent) != null ? ref.check(name) : void 0));
68 Scope.prototype.temporary = function(name, index, single) {
73 return (index + parseInt(name, 36)).toString(36).replace(/\d/g, 'a');
75 return name + (index || '');
79 Scope.prototype.type = function(name) {
82 for (i = 0, len = ref.length; i < len; i++) {
84 if (v.name === name) {
91 Scope.prototype.freeVariable = function(name, options) {
93 if (options == null) {
98 temp = this.temporary(name, index, options.single);
99 if (!(this.check(temp) || indexOf.call(this.root.referencedVars, temp) >= 0)) {
104 if ((ref = options.reserve) != null ? ref : true) {
105 this.add(temp, 'var', true);
110 Scope.prototype.assign = function(name, value) {
115 return this.hasAssignments = true;
118 Scope.prototype.hasDeclarations = function() {
119 return !!this.declaredVariables().length;
122 Scope.prototype.declaredVariables = function() {
124 return ((function() {
125 var i, len, ref, results;
126 ref = this.variables;
128 for (i = 0, len = ref.length; i < len; i++) {
130 if (v.type === 'var') {
131 results.push(v.name);
135 }).call(this)).sort();
138 Scope.prototype.assignedVariables = function() {
139 var i, len, ref, results, v;
140 ref = this.variables;
142 for (i = 0, len = ref.length; i < len; i++) {
144 if (v.type.assigned) {
145 results.push(v.name + " = " + v.type.value);