Coco ecd6aa4: Accessor -> Access

This commit is contained in:
Jeremy Ashkenas 2010-11-20 20:09:36 -05:00
parent d3ae3525b8
commit 93cf3bd922
5 changed files with 42 additions and 42 deletions

View File

@ -157,13 +157,13 @@
],
Accessor: [
o('. Identifier', function() {
return new Accessor($2);
return new Access($2);
}), o('?. Identifier', function() {
return new Accessor($2, 'soak');
return new Access($2, 'soak');
}), o(':: Identifier', function() {
return new Accessor($2, 'proto');
return new Access($2, 'proto');
}), o('::', function() {
return new Accessor(new Literal('prototype'));
return new Access(new Literal('prototype'));
}), o('Index'), o('Slice', function() {
return new Slice($1);
})
@ -252,7 +252,7 @@
],
ThisProperty: [
o('@ Identifier', function() {
return new Value(new Literal('this'), [new Accessor($2)], 'this');
return new Value(new Literal('this'), [new Access($2)], 'this');
})
],
Array: [

View File

@ -1,5 +1,5 @@
(function() {
var Accessor, Arr, Assign, Base, Call, Class, Closure, Code, Comment, Existence, Expressions, Extends, For, IDENTIFIER, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, NEGATE, NO, NUMBER, Obj, Op, Param, Parens, Push, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, TRAILING_WHITESPACE, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref;
var Access, Arr, Assign, Base, Call, Class, Closure, Code, Comment, Existence, Expressions, Extends, For, IDENTIFIER, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, NEGATE, NO, NUMBER, Obj, Op, Param, Parens, Push, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, TRAILING_WHITESPACE, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref;
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
function ctor() { this.constructor = child; }
@ -449,7 +449,7 @@
this.base.front = this.front;
props = this.properties;
code = this.base.compile(o, props.length ? LEVEL_ACCESS : null);
if (props[0] instanceof Accessor && this.isSimpleNumber()) {
if (props[0] instanceof Access && this.isSimpleNumber()) {
code = "(" + code + ")";
}
for (_i = 0, _len = props.length; _i < _len; _i++) {
@ -644,21 +644,21 @@
};
return Extends;
}();
exports.Accessor = Accessor = function() {
function Accessor(_arg, tag) {
exports.Access = Access = function() {
function Access(_arg, tag) {
this.name = _arg;
this.proto = tag === 'proto' ? '.prototype' : '';
this.soak = tag === 'soak';
}
__extends(Accessor, Base);
Accessor.prototype.children = ['name'];
Accessor.prototype.compile = function(o) {
__extends(Access, Base);
Access.prototype.children = ['name'];
Access.prototype.compile = function(o) {
var name;
name = this.name.compile(o);
return this.proto + (IS_STRING.test(name) ? "[" + name + "]" : "." + name);
};
Accessor.prototype.isComplex = NO;
return Accessor;
Access.prototype.isComplex = NO;
return Access;
}();
exports.Index = Index = function() {
function Index(_arg) {
@ -941,7 +941,7 @@
if (!this.variable) {
return null;
}
decl = (tail = last(this.variable.properties)) ? tail instanceof Accessor && tail.name.value : this.variable.base.value;
decl = (tail = last(this.variable.properties)) ? tail instanceof Access && tail.name.value : this.variable.base.value;
return decl && (decl = IDENTIFIER.test(decl) && decl);
};
Class.prototype.setContext = function(name) {
@ -993,7 +993,7 @@
assign = null;
} else {
if (!assign.variable["this"]) {
assign.variable = new Value(new Literal(name), [new Accessor(base, 'proto')]);
assign.variable = new Value(new Literal(name), [new Access(base, 'proto')]);
}
if (func instanceof Code && func.bound) {
this.boundFuncs.push(base);
@ -1129,7 +1129,7 @@
}
acc = IDENTIFIER.test(idx.unwrap().value || 0);
value = new Value(value);
value.properties.push(new (acc ? Accessor : Index)(idx));
value.properties.push(new (acc ? Access : Index)(idx));
return new Assign(obj, value).compile(o);
}
vvar = value.compile(o, LEVEL_LIST);
@ -1174,7 +1174,7 @@
} else {
acc = isObject && IDENTIFIER.test(idx.unwrap().value || 0);
}
val = new Value(new Literal(vvar), [new (acc ? Accessor : Index)(idx)]);
val = new Value(new Literal(vvar), [new (acc ? Access : Index)(idx)]);
}
assigns.push(new Assign(obj, val).compile(o, LEVEL_TOP));
}
@ -2023,7 +2023,7 @@
if (exps.isEmpty() || last(exps.expressions).containsPureStatement()) {
return exps;
}
return exps.push(new Call(new Value(new Literal(name), [new Accessor(new Literal('push'))]), [exps.pop()]));
return exps.push(new Call(new Value(new Literal(name), [new Access(new Literal('push'))]), [exps.pop()]));
}
};
Closure = {
@ -2040,7 +2040,7 @@
if (mentionsArgs) {
args.push(new Literal('arguments'));
}
func = new Value(func, [new Accessor(meth)]);
func = new Value(func, [new Access(meth)]);
func.noReturn = noReturn;
}
call = new Call(func, args);

View File

@ -157,13 +157,13 @@ case 73:this.$ = new yy.Value($$[$0-1+1-1]);
break;
case 74:this.$ = $$[$0-1+1-1];
break;
case 75:this.$ = new yy.Accessor($$[$0-2+2-1]);
case 75:this.$ = new yy.Access($$[$0-2+2-1]);
break;
case 76:this.$ = new yy.Accessor($$[$0-2+2-1], 'soak');
case 76:this.$ = new yy.Access($$[$0-2+2-1], 'soak');
break;
case 77:this.$ = new yy.Accessor($$[$0-2+2-1], 'proto');
case 77:this.$ = new yy.Access($$[$0-2+2-1], 'proto');
break;
case 78:this.$ = new yy.Accessor(new yy.Literal('prototype'));
case 78:this.$ = new yy.Access(new yy.Literal('prototype'));
break;
case 79:this.$ = $$[$0-1+1-1];
break;
@ -227,7 +227,7 @@ case 106:this.$ = new yy.Value(new yy.Literal('this'));
break;
case 107:this.$ = new yy.Value(new yy.Literal('this'));
break;
case 108:this.$ = new yy.Value(new yy.Literal('this'), [new yy.Accessor($$[$0-2+2-1])], 'this');
case 108:this.$ = new yy.Value(new yy.Literal('this'), [new yy.Access($$[$0-2+2-1])], 'this');
break;
case 109:this.$ = new yy.Arr([]);
break;

View File

@ -240,10 +240,10 @@ grammar =
# The general group of accessors into an object, by property, by prototype
# or by array index or slice.
Accessor: [
o '. Identifier', -> new Accessor $2
o '?. Identifier', -> new Accessor $2, 'soak'
o ':: Identifier', -> new Accessor $2, 'proto'
o '::', -> new Accessor new Literal 'prototype'
o '. Identifier', -> new Access $2
o '?. Identifier', -> new Access $2, 'soak'
o ':: Identifier', -> new Access $2, 'proto'
o '::', -> new Access new Literal 'prototype'
o 'Index'
o 'Slice', -> new Slice $1
]
@ -313,7 +313,7 @@ grammar =
# A reference to a property on *this*.
ThisProperty: [
o '@ Identifier', -> new Value new Literal('this'), [new Accessor($2)], 'this'
o '@ Identifier', -> new Value new Literal('this'), [new Access($2)], 'this'
]
# The array literal.

View File

@ -383,7 +383,7 @@ exports.Value = class Value extends Base
@base.front = @front
props = @properties
code = @base.compile o, if props.length then LEVEL_ACCESS else null
code = "(#{code})" if props[0] instanceof Accessor and @isSimpleNumber()
code = "(#{code})" if props[0] instanceof Access and @isSimpleNumber()
code += prop.compile o for prop in props
code
@ -535,11 +535,11 @@ exports.Extends = class Extends extends Base
utility 'hasProp'
new Call(new Value(new Literal utility 'extends'), [@child, @parent]).compile o
#### Accessor
#### Access
# A `.` accessor into a property of a value, or the `::` shorthand for
# an accessor into the object's prototype.
exports.Accessor = class Accessor extends Base
# A `.` access into a property of a value, or the `::` shorthand for
# an access into the object's prototype.
exports.Access = class Access extends Base
constructor: (@name, tag) ->
@proto = if tag is 'proto' then '.prototype' else ''
@soak = tag is 'soak'
@ -554,7 +554,7 @@ exports.Accessor = class Accessor extends Base
#### Index
# A `[ ... ]` indexed accessor into an array or object.
# A `[ ... ]` indexed access into an array or object.
exports.Index = class Index extends Base
constructor: (@index) ->
@ -756,7 +756,7 @@ exports.Class = class Class extends Base
determineName: ->
return null unless @variable
decl = if tail = last @variable.properties
tail instanceof Accessor and tail.name.value
tail instanceof Access and tail.name.value
else
@variable.base.value
decl and= IDENTIFIER.test(decl) and decl
@ -800,7 +800,7 @@ exports.Class = class Class extends Base
assign = null
else
unless assign.variable.this
assign.variable = new Value(new Literal(name), [new Accessor(base, 'proto')])
assign.variable = new Value(new Literal(name), [new Access(base, 'proto')])
if func instanceof Code and func.bound
@boundFuncs.push base
func.bound = no
@ -910,7 +910,7 @@ exports.Assign = class Assign extends Base
new Literal 0
acc = IDENTIFIER.test idx.unwrap().value or 0
value = new Value value
value.properties.push new (if acc then Accessor else Index) idx
value.properties.push new (if acc then Access else Index) idx
return new Assign(obj, value).compile o
vvar = value.compile o, LEVEL_LIST
assigns = []
@ -950,7 +950,7 @@ exports.Assign = class Assign extends Base
acc = no
else
acc = isObject and IDENTIFIER.test idx.unwrap().value or 0
val = new Value new Literal(vvar), [new (if acc then Accessor else Index) idx]
val = new Value new Literal(vvar), [new (if acc then Access else Index) idx]
assigns.push new Assign(obj, val).compile o, LEVEL_TOP
assigns.push vvar unless top
code = assigns.join ', '
@ -1610,7 +1610,7 @@ exports.If = class If extends Base
Push =
wrap: (name, exps) ->
return exps if exps.isEmpty() or last(exps.expressions).containsPureStatement()
exps.push new Call new Value(new Literal(name), [new Accessor new Literal 'push']), [exps.pop()]
exps.push new Call new Value(new Literal(name), [new Access new Literal 'push']), [exps.pop()]
#### Closure
@ -1629,7 +1629,7 @@ Closure =
meth = new Literal if mentionsArgs then 'apply' else 'call'
args = [new Literal 'this']
args.push new Literal 'arguments' if mentionsArgs
func = new Value func, [new Accessor meth]
func = new Value func, [new Access meth]
func.noReturn = noReturn
call = new Call func, args
if statement then Expressions.wrap [call] else call