Skip to content

Commit

Permalink
Virtual properties don't create instance struct members anymore. Bump…
Browse files Browse the repository at this point in the history
…ed tests.
  • Loading branch information
fredreichbier committed Apr 25, 2010
1 parent a91ecf0 commit 7783210
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 18 deletions.
3 changes: 2 additions & 1 deletion source/rock/backend/cnaughty/ClassDeclWriter.ooc
Expand Up @@ -72,7 +72,8 @@ ClassDeclWriter: abstract class extends Skeleton {
}

for(vDecl in cDecl variables) {
if(vDecl isExtern()) continue;
// ignore extern and virtual variables (usually properties)
if(vDecl isExtern() || vDecl isVirtual()) continue;

current nl(). app(vDecl getType()). app(" "). app(vDecl getName()). app(';')
}
Expand Down
16 changes: 10 additions & 6 deletions source/rock/middle/BinaryOp.ooc
Expand Up @@ -148,13 +148,17 @@ BinaryOp: class extends Expression {

// Left side is a property access? Replace myself with a setter call.
// Make sure we're not in the getter/setter.
if(left instanceOf(VariableAccess) && left as VariableAccess ref instanceOf(PropertyDecl) \
&& left as VariableAccess ref as PropertyDecl inOuterSpace(trail)) {
if(left instanceOf(VariableAccess) && left as VariableAccess ref instanceOf(PropertyDecl)) {
leftProperty := left as VariableAccess ref as PropertyDecl
fCall := FunctionCall new(left as VariableAccess expr, leftProperty getSetterName(), token)
fCall getArguments() add(right)
trail peek() replace(this, fCall)
return Responses OK
if(leftProperty inOuterSpace(trail)) {
fCall := FunctionCall new(left as VariableAccess expr, leftProperty getSetterName(), token)
fCall getArguments() add(right)
trail peek() replace(this, fCall)
return Responses OK
} else {
// We're in a setter/getter. This means the property is not virtual.
leftProperty setVirtual(false)
}
}

cast : Cast = null
Expand Down
4 changes: 4 additions & 0 deletions source/rock/middle/PropertyDecl.ooc
Expand Up @@ -10,11 +10,15 @@ PropertyDecl: class extends VariableDecl {
setter: FunctionDecl = null
cls: ClassDecl = null
resolved := false
virtual := true // see `VariableAccess resolve` and `BinaryOp resolve`

init: func ~pDecl (.type, .name, .token) {
init(type, name, null, token)
}

isVirtual: func -> Bool { virtual }
setVirtual: func (=virtual) {}

setSetter: func (=setter) {}
setGetter: func (=getter) {}

Expand Down
26 changes: 16 additions & 10 deletions source/rock/middle/VariableAccess.ooc
Expand Up @@ -160,16 +160,22 @@ VariableAccess: class extends Expression {
}

// Simple property access? Replace myself with a getter call.
// Make sure we're not in a getter/setter yet (the trail would
// contain `ref` then)
if(ref && ref instanceOf(PropertyDecl) && ref as PropertyDecl inOuterSpace(trail)) {
// Test that we're not part of an assignment (which will be replaced by a setter call)
// TODO: This should be nicer.
if(!(trail peek() instanceOf(BinaryOp) && trail peek() as BinaryOp type == OpTypes ass)) {
property := ref as PropertyDecl
fCall := FunctionCall new(expr, property getGetterName(), token)
trail peek() replace(this, fCall)
return Responses OK
if(ref && ref instanceOf(PropertyDecl)) {
// Make sure we're not in a getter/setter yet (the trail would
// contain `ref` then)
if(ref as PropertyDecl inOuterSpace(trail)) {
// Test that we're not part of an assignment (which will be replaced by a setter call)
// TODO: This should be nicer.
if(!(trail peek() instanceOf(BinaryOp) && trail peek() as BinaryOp type == OpTypes ass)) {
property := ref as PropertyDecl
fCall := FunctionCall new(expr, property getGetterName(), token)
trail peek() replace(this, fCall)
return Responses OK
}
} else {
// We are in a setter/getter and we're having a variable access. That means
// the property is not virtual.
ref as PropertyDecl setVirtual(false)
}
}

Expand Down
5 changes: 5 additions & 0 deletions source/rock/middle/VariableDecl.ooc
Expand Up @@ -51,6 +51,11 @@ VariableDecl: class extends Declaration {
)
}

/** If `true`, the property should not be added to the instance struct as a member.
Ordinary variables never are virtual. Properties can be.
*/
isVirtual: func -> Bool { false }

setOwner: func (=owner) {}

setExpr: func (=expr) {}
Expand Down
2 changes: 1 addition & 1 deletion tests
Submodule tests updated from 82b0fd to a36318

0 comments on commit 7783210

Please sign in to comment.