Skip to content

Commit

Permalink
Merge 28ec6f1 into 3790d23
Browse files Browse the repository at this point in the history
  • Loading branch information
npasserini committed Jul 3, 2019
2 parents 3790d23 + 28ec6f1 commit 97e9e6d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ class BasicTypeResolver {
extension WollokClassFinder classFinder = WollokClassFinder.getInstance

def dispatch WMethodContainer resolveType(WVariable variable) {
if (variable.declaration.right === null)
null
else
variable.declaration.right.resolveType
variable.declaration.initValue?.resolveType
}

def dispatch WMethodContainer resolveType(WListLiteral it) { listClass }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ class WollokModelExtensions {
// ** WReferenciable
// ************************************************************************
def static dispatch isModifiableFrom(WVariable v, WAssignment from) {
v.declaration.writeable || from.initializesInstanceValueFromConstructor(v)
v.declaration.isWriteable || from.initializesInstanceValueFromConstructor(v)
}

def static dispatch isModifiableFrom(WParameter v, WAssignment from) { false }

def static dispatch isModifiableFrom(WReferenciable v, WAssignment from) { true }

def static boolean initializesInstanceValueFromConstructor(WAssignment a, WVariable v) {
v.declaration.right === null && a.isWithinConstructor
v.declaration.initValue === null && a.isWithinConstructor
}

def static boolean isWithinConstructor(EObject e) {
Expand All @@ -160,14 +160,14 @@ class WollokModelExtensions {

/** A variable is global if its declaration (i.e. its eContainer) is direct child of a WFile element */
def static dispatch boolean isGlobal(WVariableDeclaration it) {
variable.isGlobal
eContainer instanceof WFile
}
def static dispatch boolean isGlobal(WVariable it) {
//eContainer instanceof WVariableDeclaration && eContainer.eContainer instanceof WFile
getContainer === null && EcoreUtil2.getContainerOfType(it, WProgram) === null
declaration.isGlobal
}
def static dispatch boolean isGlobal(WNamedObject it) { true }
def static dispatch boolean isGlobal(WParameter it) { false }
def static dispatch boolean isGlobal(WCatch it) { false }

// ************************************************************************
// ** Variable & parameter usage
Expand Down Expand Up @@ -205,7 +205,19 @@ class WollokModelExtensions {
reference.ref == referenciable
}

def static declaration(WVariable variable) { variable.eContainer as WVariableDeclaration }
// **************************************************************************************************************
// This is to allow WVariableDeclaration and WCatch to be polymorphic in the role of variable declarations.
// TODO I think we should change the definition of WCatch to use WParameter instead of WVariable.
def static declaration(WVariable variable) {
variable.eContainer // as WVariableDeclaration
}

def static dispatch isWriteable(WVariableDeclaration it) { writeable }
def static dispatch isWriteable(WCatch it) { false }
def static dispatch initValue (WVariableDeclaration it) { right }
def static dispatch initValue (WCatch it) { null }
// **************************************************************************************************************


def static dispatch declarationContext(WVariable variable) { variable.declaration.eContainer }
def static dispatch declarationContext(WParameter parameter) { parameter.eContainer }
Expand Down

0 comments on commit 97e9e6d

Please sign in to comment.