Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/uqbar-project/wollok into ad…
Browse files Browse the repository at this point in the history
…d-wko-parent-constructor-to-ts
  • Loading branch information
PalumboN committed Mar 4, 2019
2 parents 1c537dd + 842505c commit c72fdba
Show file tree
Hide file tree
Showing 159 changed files with 3,575 additions and 1,638 deletions.
3 changes: 2 additions & 1 deletion org.uqbar.project.wollok.launch/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Bundle-ClassPath: lib/lipermi-0-4-2.jar,
lib/gson-2.4.jar,
lib/jetty-all-9.3.9.v20160517-uber.jar,
.
Export-Package: org.uqbar.project.wollok.debugger.server,
Export-Package: org.uqbar.project.wollok.contextState.server,
org.uqbar.project.wollok.debugger.server,
org.uqbar.project.wollok.debugger.server.out,
org.uqbar.project.wollok.debugger.server.rmi,
org.uqbar.project.wollok.launch,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.uqbar.project.wollok.contextState.server

import java.util.List
import org.uqbar.project.wollok.debugger.server.rmi.XDebugStackFrameVariable

/**
* Listens to the state of a certain context of execution
*/
interface XContextStateListener {

def void stateChanged(List<XDebugStackFrameVariable> variables)

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class XDebuggerImpl implements XDebugger {
* Send started event, then wait paused for the debugger to install breakpoints and perform initialization.
* He will call us the "resume" command once he's ready.
*/
override started() {
override started() {
debuggingThread = interpreter.currentThread
eventSender.started
sleep
//sleep
}

override aboutToEvaluate(EObject element) {
Expand All @@ -69,7 +69,7 @@ class XDebuggerImpl implements XDebugger {

def checkBreakpointsAndSuspendIfHit(EObject element) {
val bp = breakpoints.findFirst[ hits(element) ]
if (bp != null && bp != lastBreakpointHit) {
if (bp !== null && bp != lastBreakpointHit) {
eventSender.breakpointHit(bp.fileURI, bp.lineNumber)
lastBreakpointHit = bp
sleep(false) // avoid sending two events (suspended by BP, suspended by step)
Expand Down Expand Up @@ -101,7 +101,7 @@ class XDebuggerImpl implements XDebugger {
override setBreakpoint(String fileURI, int line) { breakpoints.add(new XBreakpoint(fileURI, line)) }
override clearBreakpoint(String fileURI, int line) {
val bp = breakpoints.findFirst[it.fileURI == fileURI && it.lineNumber == line]
if (bp != null)
if (bp !== null)
breakpoints.remove(bp)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.uqbar.project.wollok.interpreter.api.XDebugger
*
* @author jfernandes
*/
class CommandHandlerFactory {
class DebuggerCommandHandlerFactory {

def static Server createCommandHandler(XDebugger debugger, int port, ()=>void onReady) {
val server = new Server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package org.uqbar.project.wollok.debugger.server.rmi

import com.google.common.collect.Lists
import java.io.Serializable
import java.util.ArrayList
import java.util.List
import java.util.Map
import org.eclipse.xtend.lib.annotations.Accessors
import org.uqbar.project.wollok.WollokConstants
import org.uqbar.project.wollok.interpreter.context.EvaluationContext
import org.uqbar.project.wollok.interpreter.context.WVariable
import org.uqbar.project.wollok.interpreter.core.WollokObject
import org.uqbar.project.wollok.interpreter.stack.SourceCodeLocation
import org.uqbar.project.wollok.interpreter.stack.XStackFrame
import org.uqbar.project.wollok.sdk.WollokDSK

/**
*
Expand All @@ -20,20 +21,46 @@ import org.uqbar.project.wollok.interpreter.stack.XStackFrame
class XDebugStackFrame implements Serializable {
SourceCodeLocation sourceLocation
List<XDebugStackFrameVariable> variables

new(XStackFrame frame) {
public static Map<WVariable, WollokObject> allValues
public static List<WVariable> allVariables

new(XStackFrame<WollokObject> frame) {
sourceLocation = frame.currentLocation
variables = frame.context.debugVariables
}

def static ArrayList<XDebugStackFrameVariable> debugVariables(EvaluationContext<WollokObject> context) {
Lists.newArrayList(context.allReferenceNames.filter[name != WollokConstants.SELF].map[

def static unwantedObjects() {
#[WollokConstants.SELF, WollokDSK.VOID, WollokDSK.CONSOLE]
}

def static List<XDebugStackFrameVariable> debugVariables(EvaluationContext<WollokObject> context) {
val vars = Lists.newArrayList(context.allReferenceNames.filter [
!local && context.showableInDynamicDiagram(name) && !unwantedObjects.exists [ unwanted |
name.toLowerCase.contains(unwanted)
]
])
Lists.newArrayList(vars.map [
toVariable(context)
])
}

def static toVariable(WVariable variable, EvaluationContext<WollokObject> context) {
new XDebugStackFrameVariable(variable, context.resolve(variable.name))
if (allVariables.contains(variable)) {
return new XDebugStackFrameVariable(variable, null) // Evita que el listener entre en loop infinito por referencias circulares. Luego el diagrama de objetos enlaza los objetos por id interno.
}
val value = allValues.get(variable)
if (value !== null) {
return new XDebugStackFrameVariable(variable, value)
}
allVariables.add(variable)
val newValue = context.resolve(variable.name)
allValues.put(variable, newValue)
new XDebugStackFrameVariable(variable, newValue)
}

def static initAllVariables() {
allVariables = newArrayList
allValues = newHashMap
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.uqbar.project.wollok.debugger.server.rmi

import java.io.Serializable
import java.util.Map
import org.eclipse.xtend.lib.annotations.Accessors
import org.uqbar.project.wollok.interpreter.context.WVariable
import org.uqbar.project.wollok.interpreter.core.WollokObject
Expand All @@ -16,19 +17,46 @@ import static org.uqbar.project.wollok.sdk.WollokDSK.*
class XDebugStackFrameVariable implements Serializable {
WVariable variable
XDebugValue value

new(WVariable variable, WollokObject value) {
this.variable = variable
this.value = if (value == null) null else value.asRemoteValue
this.value = if(value === null) null else value.asRemoteValue
}

def asRemoteValue(WollokObject object) {
if (object.hasNativeType(LIST))
new XWollokListDebugValue(object, LIST)
new XWollokListDebugValue(object, LIST)
else if (object.hasNativeType(SET))
new XWollokListDebugValue(object, SET)
new XWollokSetDebugValue(object, SET)
else if (object.hasNativeType(DICTIONARY))
new XWollokDictionaryDebugValue(object, DICTIONARY)
else
new XWollokObjectDebugValue(variable.name, object)
}

override equals(Object obj) {
try {
val other = obj as XDebugStackFrameVariable
return other.variable.toString.equals(variable.toString)
} catch (ClassCastException e) {
return false
}
}

override hashCode() {
this.variable.toString.hashCode
}

override toString() {
val valueToString = if (this.value === null) "null" else this.value.toString
this.variable.toString + " = " + valueToString
}

def void collectValues(Map<String, XDebugStackFrameVariable> variableValues) {
if (this.value !== null) {
variableValues.put(this.variable.id.toString, this)
this.value.variables.forEach [ variable | variable.collectValues(variableValues) ]
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@ import org.eclipse.xtend.lib.annotations.Accessors

/**
* @author jfernandes
* @author dodain Added id
*/
@Accessors
class XDebugValue implements Serializable {
static val ArrayList<XDebugStackFrameVariable> EMPTY_LIST = newArrayList
@Accessors String stringValue

new(String stringValue) {
List<XDebugStackFrameVariable> variables = EMPTY_LIST
String stringValue
Integer id

new(String stringValue, Integer id) {
this.stringValue = stringValue
this.id = id
}

def List<XDebugStackFrameVariable> getVariables() { EMPTY_LIST }
override toString() {
val variablesToString = if (variables.isEmpty) "" else " " + variables.map [ toString ].join(", ")
(this.stringValue ?: "") + (if (id === null) "" else " (" + id + ")") + variablesToString
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.uqbar.project.wollok.debugger.server.rmi

import java.util.Collection
import java.util.Collections
import org.uqbar.project.wollok.interpreter.context.WVariable
import org.uqbar.project.wollok.interpreter.core.WollokObject
import wollok.lang.WCollection
import wollok.lang.WDictionary

import static extension org.uqbar.project.wollok.utils.WollokObjectUtils.*

/**
* Special value for wollok collection.
* Shows its content as children
*
* @author jfernandes
*/
abstract class XWollokCollectionDebugValue extends XDebugValue {

new(WollokObject collection, String concreteNativeType, String collectionType) {
super(collectionType, System.identityHashCode(collection))
var i = 0
val result = newArrayList
val elements = collection.getElements(concreteNativeType)
for (e : elements) {
result.add(new XDebugStackFrameVariable(new WVariable(i.getVariableName(collection, concreteNativeType), System.identityHashCode(e), false), e))
i++
}
variables = newArrayList(result)
}

def getElements(WollokObject collection, String concreteNativeType) {
val native = collection.getNativeObject(concreteNativeType) as WCollection<Collection<WollokObject>>
if (native.wrapped === null) Collections.EMPTY_LIST else native.wrapped
}

def String getVariableName(int i, WollokObject collection, String concreteNativeType)
}

class XWollokListDebugValue extends XWollokCollectionDebugValue {

new(WollokObject collection, String concreteNativeType) {
super(collection, concreteNativeType, "List")
}

override getVariableName(int i, WollokObject collection, String concreteNativeType) {
String.valueOf(i)
}

}

class XWollokSetDebugValue extends XWollokCollectionDebugValue {

new(WollokObject collection, String concreteNativeType) {
super(collection, concreteNativeType, "Set")
}

override getVariableName(int i, WollokObject collection, String concreteNativeType) {
""
}

}

class XWollokDictionaryDebugValue extends XWollokCollectionDebugValue {

new(WollokObject collection, String concreteNativeType) {
super(collection, concreteNativeType, "Dictionary")
}

override getVariableName(int i, WollokObject collection, String concreteNativeType) {
val wrapped = collection.getNativeObject(concreteNativeType) as WDictionary
wrapped.keys.get(i).asString
}

override def getElements(WollokObject collection, String concreteNativeType) {
val wrapped = collection.getNativeObject(concreteNativeType) as WDictionary
if (wrapped === null) Collections.EMPTY_LIST else wrapped.values
}

}

This file was deleted.

Loading

0 comments on commit c72fdba

Please sign in to comment.