Permalink
Browse files

cleaned inner (deprecated) projects and added some old files to git

  • Loading branch information...
ivankuraj committed Feb 21, 2013
1 parent 6bdaa11 commit b43a65a26981eb895f896953da49d9b6fa3cdce6
View
@@ -1,6 +1,12 @@
*.class
*.log
+# project specific ignores
+**/.cache
+**/.classpath
+**/.settings
+SAV_Project_Report/document.pdf
+
# sbt specific
dist/*
target/
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>InSynth_CompilerPlugin</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>ch.epfl.lamp.sdt.core.scalabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>ch.epfl.lamp.sdt.core.scalanature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,68 @@
+Scala compiler plugin template
+------------------------------
+
+This project is a template that can be used for creating compiler
+plugins for the Scala compiler.
+
+
+Installation
+------------
+To install the compiler plugin, run "ant install". This will create
+an sbaz package for the template plugin and install it in the scala
+installation available in your PATH.
+The install command will also create a script for running the plugin
+as standalone application. The command is called "runplugintemplate"
+and available in your scala installation as well.
+To uninstall the plugin again, run "and uninstall".
+
+Alternatively, copy the file build/pack/plugintemplate.jar, generated
+by "ant pack", to the directory misc/scala-devel/plugins of your
+scala distribution. The scala compiler will then find and integrate
+the new plugin.
+
+Customization
+-------------
+The following files need to be edited when creating a new plugin
+- plugin.properties
+- misc/scalac-plugin.xml
+- src / test / doc/examples: The source files of the template plugin
+ are located a package called "plugintemplate". This will most likely
+ be changed for new plugins.
+
+When using eclipse for development, make sure "scala-compiler.jar" is
+in the Java Build Path: Right-Click the project and select "Properties".
+Then go to "Java Build Path" -> "Libraries" and add the jar file
+"eclipse/plugins/ch.epfl.lamp.sdt.core[..]/lib/scala-compiler.jar".
+
+Traverse, Transform, Check
+--------------------------
+There are several pre-defined components that can be used to code
+the behavior of a plugin:
+- TemplateTraverseComponent: a template for tree traversers. Used
+ to analyze and collect data about compiler trees.
+ -> implement the "check" method
+
+- TemplateTransformComponent: a template for tree transformers.
+ -> implement "preTransform" and / or "postTransform"
+
+- TemplateInfoTransformComponent: also a tree transformer, which
+ additionally is an InfoTransformer. Allows changing the type
+ of some symbols for later phases.
+ -> implement "preTransform" and / or "postTransform", and the
+ "apply" method of the "infoTransformer".
+
+- TemplateAnnotationChecker: a plugin for the typechecker, useful
+ for pluggable type systems. Computes the subtyping between two
+ annotated types, and allows providing inferred type information.
+ -> implement "annotationsConform" and optionally "addAnnotations"
+
+- TemplateComponent: the most general component. Can do anything it
+ likes with the CompilationUnits.
+ -> implement the "run" method
+
+Ant tasks
+---------
+"build.xml" defines Ant tasks for building, testing and packing a
+plugin. The tests are written using the ScalaTest framework
+(http://www.artima.com/scalatest/).
+Run the tests using "ant test", or "ant guitest".
@@ -0,0 +1,30 @@
+package plugintemplate.examples
+
+class ApplicationInfoTest {
+
+ def m1(i:Int)(i2: Int) = 5
+
+ // this throws and exception with m2("bla")
+ //def m2: String => Int = _ => 5
+
+ def m2: String => Int = (_:String) => 5
+
+ def m3(a1:Char)(a2: Int)(a3: Float): (String, Boolean) => (Int, Double) => Char =
+ (_, _) => (_,_) => 'c'
+ def m3(a1:Float)(a2: Int): (String, Boolean) => (Int, Double) => Char =
+ (_, _) => (_,_) => 'c'
+
+ def main(args: Array[String]) {
+ m1(5)(6)
+
+ m2("bla")
+
+ m3('5')(6)(3.0f)("bla", true)(5, 6d)
+ m3('5')(6)(3.0f)("bla", true)
+ m3('5')(6)(3.0f)
+
+ m3(1.0f)(5)("bla", true)(5, 6d)
+ m3(1.0f)(5)("bla", true)
+ m3(1.0f)(5)
+ }
+}
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,222 @@
+package org.ensime.examplecollector
+
+import java.io._
+import org.ensime.server.RichPresentationCompiler
+
+/*
+ *
+ * Main ExampleCollector class.
+ * Learns examples.
+ *
+ */
+trait ExampleCollector {
+ self: RichPresentationCompiler=>
+
+ def loadFiles(){
+ map = Map[String, Long]()
+ appl = 0
+ val files = loadFiles(new File(config.root.getAbsolutePath()+"\\src\\main\\scala"))
+ files.foreach {
+ x =>
+ try {
+ val sourceFile = this.getSourceFile(x.getAbsolutePath())
+ typedTree(sourceFile, true)
+ val unit = this.unitOf(sourceFile)
+ //println(x.getAbsolutePath())
+ traverse(unit.body)
+ } catch {
+ case _ =>
+ }
+ }
+
+ //println(map.mkString("\n"))
+
+ val fw = new FileWriter(config.root.getAbsolutePath()+"\\Examples.txt", false)
+ map.foreach {x => fw.write(x._1+";"+x._2+"\n")}
+ fw.flush
+ fw.close
+ }
+
+ def loadFiles(dir:File):List[File] = {
+ var files = List[File]()
+ dir.listFiles.foreach {
+ x =>
+ if (x.isDirectory()){
+ files = loadFiles(x) ::: files
+ } else if (x.getName().endsWith(".scala")) files = x :: files
+ }
+ files
+ }
+
+ var appl:Long = 0
+ var map = Map[String, Long]()
+
+ def collect(sym:Symbol) {
+ if(sym != null && sym.toString != "<none>" && sym.isMethod && checkName(sym.fullName)){
+ val name = fullName(sym)
+ if (map.contains(name)){
+ map += name -> (map(name)+1)
+ } else {
+ map += name -> 1
+ }
+ appl+=1
+ }
+ }
+
+ val forbidden = List("examples.tralalala", "super.","java.lang.Object.<init>","scala.Predef.exit", "$plus", "$minus", "$less", "$eq", "$greater", "$div", "$percent")
+
+ def checkName(name:String) = (name.startsWith("scala.") || name.startsWith("java.") || name.startsWith("javax.")|| name.startsWith("swing.")|| name.startsWith("org.omg.") || name.startsWith("org.w3c.") || name.startsWith("org.xml.") || name.startsWith("org.ietf.")) && (!name.startsWith("scala.tools.")) && !forbidden.exists(x => name.contains(x))
+
+ def fullName(sym:Symbol) = "method " + sym.fullName + sym.tpe.paramTypes.map(x => x.typeSymbol.fullName).mkString(" ",",","")
+
+ protected var currentOwner: Symbol = null
+ def traverse(tree: Tree): Unit = {
+/* println("Class "+tree.getClass().getName())
+ println("--------------------------------------------------------")
+ println(tree)
+ println("--------------------------------------------------------")
+*/
+ tree match {
+ case EmptyTree =>
+ ;
+ case PackageDef(pid, stats) =>
+ traverse(pid)
+ atOwner(tree.symbol.moduleClass) {
+ traverseTrees(stats)
+ }
+ case ClassDef(mods, name, tparams, impl) =>
+ atOwner(tree.symbol) {
+ traverseTrees(mods.annotations); traverseTrees(tparams); traverse(impl)
+ }
+ case ModuleDef(mods, name, impl) =>
+ atOwner(tree.symbol.moduleClass) {
+ traverseTrees(mods.annotations); traverse(impl)
+ }
+ case ValDef(mods, name, tpt, rhs) =>
+ atOwner(tree.symbol) {
+ traverseTrees(mods.annotations); traverse(tpt); traverse(rhs)
+ }
+ case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
+ atOwner(tree.symbol) {
+ traverseTrees(mods.annotations); traverseTrees(tparams); traverseTreess(vparamss); traverse(tpt); traverse(rhs)
+ }
+ case TypeDef(mods, name, tparams, rhs) =>
+ atOwner(tree.symbol) {
+ traverseTrees(mods.annotations); traverseTrees(tparams); traverse(rhs)
+ }
+ case LabelDef(name, params, rhs) =>
+ traverseTrees(params); traverse(rhs)
+ case Import(expr, selectors) =>
+ traverse(expr)
+ case Annotated(annot, arg) =>
+ traverse(annot); traverse(arg)
+ case Template(parents, self, body) =>
+ traverseTrees(parents)
+ if (!self.isEmpty) traverse(self)
+ traverseStats(body, tree.symbol)
+ case Block(stats, expr) =>
+ traverseTrees(stats); traverse(expr)
+ case CaseDef(pat, guard, body) =>
+ traverse(pat); traverse(guard); traverse(body)
+ case Alternative(trees) =>
+ traverseTrees(trees)
+ case Star(elem) =>
+ traverse(elem)
+ case Bind(name, body) =>
+ print("Bind "+ name)
+ traverse(body)
+ case UnApply(fun, args) =>
+ print("UnApply "+ fun)
+ traverse(fun); traverseTrees(args)
+ case ArrayValue(elemtpt, trees) =>
+ traverse(elemtpt); traverseTrees(trees)
+ case Function(vparams, body) =>
+ atOwner(tree.symbol) {
+ traverseTrees(vparams); traverse(body)
+ }
+ case Assign(lhs, rhs) =>
+ traverse(lhs); traverse(rhs)
+ case If(cond, thenp, elsep) =>
+ traverse(cond); traverse(thenp); traverse(elsep)
+ case Match(selector, cases) =>
+ traverse(selector); traverseTrees(cases)
+ case Return(expr) =>
+ traverse(expr)
+ case Try(block, catches, finalizer) =>
+ traverse(block); traverseTrees(catches); traverse(finalizer)
+ case Throw(expr) =>
+ traverse(expr)
+ case New(tpt) =>
+ traverse(tpt)
+ case Typed(expr, tpt) =>
+ traverse(expr); traverse(tpt)
+ case TypeApply(fun, args) =>
+// println("TypeApply "+ fun)
+ traverse(fun); traverseTrees(args)
+ case a @ Apply(fun, args) =>
+ //println("fun = "+ fun +" sym = "+fun.symbol)
+ try{
+ this.collect(fun.symbol)
+ } catch{
+ case _=>
+ }
+ traverse(fun); traverseTrees(args)
+ case a @ ApplyDynamic(qual, args) =>
+ //println("qual = "+ qual +" sym = "+qual.symbol)
+ try{
+ this.collect(qual.symbol)
+ } catch{
+ case _=>
+ }
+ traverse(qual); traverseTrees(args)
+ case Super(_, _) =>
+ ;
+ case This(_) =>
+ ;
+ case Select(qualifier, selector) =>
+ traverse(qualifier)
+ case Ident(_) =>
+ ;
+ case Literal(_) =>
+ ;
+ case TypeTree() =>
+ ;
+ case SingletonTypeTree(ref) =>
+ traverse(ref)
+ case SelectFromTypeTree(qualifier, selector) =>
+ traverse(qualifier)
+ case CompoundTypeTree(templ) =>
+ traverse(templ)
+ case AppliedTypeTree(tpt, args) =>
+ traverse(tpt); traverseTrees(args)
+ case TypeBoundsTree(lo, hi) =>
+ traverse(lo); traverse(hi)
+ case ExistentialTypeTree(tpt, whereClauses) =>
+ traverse(tpt); traverseTrees(whereClauses)
+ case SelectFromArray(qualifier, selector, erasure) =>
+ traverse(qualifier)
+ }
+
+ def traverseTrees(trees: List[Tree]) {
+ trees foreach traverse
+ }
+
+ def traverseTreess(treess: List[List[Tree]]) {
+ treess foreach traverseTrees
+ }
+
+ def traverseStats(stats: List[Tree], exprOwner: Symbol) {
+ stats foreach (stat =>
+ if (exprOwner != currentOwner) atOwner(exprOwner)(traverse(stat))
+ else traverse(stat)
+ )
+ }
+
+ def atOwner(owner: Symbol)(traverse: => Unit) {
+ val prevOwner = currentOwner
+ currentOwner = owner
+ traverse
+ currentOwner = prevOwner
+ }
+ }
+}
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>InSynth_HoFSearchPlugin</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>ch.epfl.lamp.sdt.core.scalabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>ch.epfl.lamp.sdt.core.scalanature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,15 @@
+package plugintemplate.examples
+
+class TwoMethods {
+
+ val bla = 6
+
+ def foo(): Int = {
+ bla
+ }
+
+ def foo2() = {
+ bla
+ }
+
+}
Oops, something went wrong.

0 comments on commit b43a65a

Please sign in to comment.