]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/space-pen/node_modules/grim/node_modules/coffeestack/node_modules/coffee-script/lib/coffee-script/scope.js
cb43b024fe1cf9a3c27e8237741c9d68f1ca63e6
1 // Generated by CoffeeScript 1.8.0
3 var Scope
, extend
, last
, _ref
;
5 _ref
= require('./helpers'), extend
= _ref
.extend
, last
= _ref
.last
;
7 exports
.Scope
= Scope
= (function() {
10 function Scope(parent
, expressions
, method
) {
12 this.expressions
= expressions
;
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 (((_ref1
= this.method
) != null ? _ref1
.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
) || ((_ref1
= this.parent
) != null ? _ref1
.check(name
) : void 0));
68 Scope
.prototype.temporary = function(name
, index
) {
69 if (name
.length
> 1) {
70 return '_' + name
+ (index
> 1 ? index
- 1 : '');
72 return '_' + (index
+ parseInt(name
, 36)).toString(36).replace(/\d/g, 'a');
76 Scope
.prototype.type = function(name
) {
77 var v
, _i
, _len
, _ref1
;
78 _ref1
= this.variables
;
79 for (_i
= 0, _len
= _ref1
.length
; _i
< _len
; _i
++) {
81 if (v
.name
=== name
) {
88 Scope
.prototype.freeVariable = function(name
, reserve
) {
90 if (reserve
== null) {
94 while (this.check((temp
= this.temporary(name
, index
)))) {
98 this.add(temp
, 'var', true);
103 Scope
.prototype.assign = function(name
, value
) {
108 return this.hasAssignments
= true;
111 Scope
.prototype.hasDeclarations = function() {
112 return !!this.declaredVariables().length
;
115 Scope
.prototype.declaredVariables = function() {
116 var realVars
, tempVars
, v
, _i
, _len
, _ref1
;
119 _ref1
= this.variables
;
120 for (_i
= 0, _len
= _ref1
.length
; _i
< _len
; _i
++) {
122 if (v
.type
=== 'var') {
123 (v
.name
.charAt(0) === '_' ? tempVars : realVars
).push(v
.name
);
126 return realVars
.sort().concat(tempVars
.sort());
129 Scope
.prototype.assignedVariables = function() {
130 var v
, _i
, _len
, _ref1
, _results
;
131 _ref1
= this.variables
;
133 for (_i
= 0, _len
= _ref1
.length
; _i
< _len
; _i
++) {
135 if (v
.type
.assigned
) {
136 _results
.push("" + v
.name
+ " = " + v
.type
.value
);