Skip to content

Commit

Permalink
Combinator step updated and added some logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ikuraj committed Jun 18, 2012
1 parent 3ee665f commit efd7d79
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ object Combinator extends ((InSynth.SimpleNode, Int) => Node) {
// logging
logApply.entering(getClass.getName, "apply")
logApply.info("Entering combinator step (root: "+ FormatNode(root) + ", combinations: " + neededCombinations)

// import transformer from InSynth to intermediate declaration
import DeclarationTransformer.fromInSynthDeclaration

// reset so that pruning is not done
Rules.doPruning = false

// TODO change this temporary weight for leaves
val WeightForLeafs = 0.5d

Expand Down Expand Up @@ -74,6 +77,10 @@ object Combinator extends ((InSynth.SimpleNode, Int) => Node) {

// add explored declaration to its associated tree as explored
currentDeclaration.getAssociatedTree addDeclaration(currentDeclaration)

// logging
logApply.fine("Adding expression " + currentDeclaration.toString + " to its tree")

// check the type of the current declaration
currentDeclaration match {
// Composite represents a declaration with children
Expand Down Expand Up @@ -108,6 +115,9 @@ object Combinator extends ((InSynth.SimpleNode, Int) => Node) {
// new pair of simple expression and extended path
val newPair =
(Simple(paramTree, fromInSynthDeclaration(dec), node), visited + c)

// logging
logApply.fine("Adding simple " + dec.getSimpleName + " to the queue")
// add new pair to the queue
pq += newPair
}
Expand All @@ -119,6 +129,9 @@ object Combinator extends ((InSynth.SimpleNode, Int) => Node) {
// new pair of simple expression and extended path
val newPair =
(Composite(paramTree, fromInSynthDeclaration(dec), node), visited + c)

// logging
logApply.fine("Adding composite " + dec.getSimpleName + " to the queue")
// add new pair to the queue
pq += newPair
}
Expand All @@ -144,7 +157,14 @@ object Combinator extends ((InSynth.SimpleNode, Int) => Node) {
logApply.exiting(getClass.getName, "apply")

// return transformed pruned tree as a result
rootDeclaration.toTreeNode
val result = rootDeclaration.toTreeNode

// log
logger.info("Returning from apply with result (reconstruction structures): " + FormatCombinations(rootDeclaration) )
logger.info("Returning from apply with result: " + FormatPrNode(result) )
logger.info("Number of combinations found: " + rootDeclaration.getNumberOfCombinations )

result
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ object Rules {

{
Logger.getLogger("reconstruction.combination").setLevel(Level.FINEST)
// Logger.getLogger("reconstruction.combination.apply").setLevel(Level.OFF)
// Logger.getLogger("reconstruction.combination.structures").setLevel(Level.FINEST)
Logger.getLogger("reconstruction.combination.apply").setLevel(Level.FINEST)
Logger.getLogger("reconstruction.combination.structures").setLevel(Level.FINEST)
}

var doPruning = false
Expand Down Expand Up @@ -256,6 +256,9 @@ extends Expression(origDecl.getWeight, associatedTree, associatedNode) {
}
)
}

override def toString =
"Composite(" + origDecl.getSimpleName + ")"
}

/**
Expand All @@ -278,6 +281,9 @@ extends Expression(origDecl.getWeight, associatedTree, associatedNode) {
}

override def isDone = !isPruned

override def toString =
"Simple(" + origDecl.getSimpleName + ")"
}

/**
Expand All @@ -295,4 +301,34 @@ extends Expression(weight, associatedTree, associatedNode) {
}

override def isDone = !isPruned

override def toString =
"LeafExpression"
}

case class FormatCombinations(comb: Combinations) extends ch.epfl.insynth.print.Formatable {
override def toDocument = toDocument(comb)

def toDocument(comb: Combinations): scala.text.Document = {
import ch.epfl.insynth.print.FormatHelpers._
import scala.text.Document._

comb match {
case tree:Tree =>
"Tree" :: paren(FormatType(tree.tpe).toDocument) :/:
"[Done?" :: tree.isDone.toString :: "]" ::
nestedBrackets(
seqToDoc(tree.decls.toList, ", ", { e:Expression => toDocument(e) })
)
//associatedTree: Tree, origDecl: Declaration, associatedNode: InSynth.SimpleNode
case composite:Composite =>
"Composite" :: paren(composite.origDecl.getSimpleName) :/:
"[Done?" :: composite.isDone.toString :: "]" ::
nestedBrackets(seqToDoc(composite.children.toList, ", ", { e:Tree => toDocument(e) }))
case simple:Simple =>
"Simple" :: paren(simple.origDecl.getSimpleName)
case leaf:LeafExpression =>
"Leaf"
}
}
}

0 comments on commit efd7d79

Please sign in to comment.