Skip to content

Commit

Permalink
fix for issue #36 : #36
Browse files Browse the repository at this point in the history
  • Loading branch information
miho committed May 6, 2014
1 parent 4e4c2ca commit 5a58443
Show file tree
Hide file tree
Showing 207 changed files with 57,797 additions and 73 deletions.
5 changes: 5 additions & 0 deletions VRL/VRL-Lang/groovy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 0.050154000000000004
11 0.044770000000000004
21 0.06586700000000001
31 0.041012
41 0.044516
5 changes: 5 additions & 0 deletions VRL/VRL-Lang/java.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 1.25957
11 2.935743
21 6.7125770000000005
31 11.131415
41 10.433807
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package eu.mihosoft.vrl.instrumentation;

/*
* Copyright 2003-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import groovy.transform.CompilationUnitAware;
import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.AnnotatedNode;
import org.codehaus.groovy.ast.AnnotationNode;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.expr.ConstantExpression;
import org.codehaus.groovy.ast.expr.Expression;
import org.codehaus.groovy.ast.expr.ListExpression;
import org.codehaus.groovy.control.CompilationUnit;
import org.codehaus.groovy.control.CompilePhase;
import org.codehaus.groovy.control.SourceUnit;
import org.codehaus.groovy.syntax.SyntaxException;
import org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport;
import org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor;

import java.util.Collections;
import java.util.Map;
import org.codehaus.groovy.transform.ASTTransformation;
import org.codehaus.groovy.transform.GroovyASTTransformation;
import org.codehaus.groovy.transform.StaticTypesTransformation;

/**
* Handles the implementation of the {@link groovy.transform.TypeChecked}
* transformation.
*
* @author <a href="mailto:blackdrag@gmx.org">Jochen "blackdrag" Theodorou</a>
* @author Cedric Champeau
* @author Guillaume Laforge
*/
@GroovyASTTransformation(phase = CompilePhase.INSTRUCTION_SELECTION)
public class TypeCheckingTransform extends StaticTypesTransformation {

public static final String STATIC_ERROR_PREFIX = "[Static type checking] - ";
private CompilationUnit compilationUnit;

public void visit(ClassNode node, SourceUnit source) {
visit(new ASTNode[]{new AnnotationNode(node), node}, source);
}

@Override
public void visit(ASTNode[] nodes, SourceUnit source) {
AnnotationNode annotationInformation = (AnnotationNode) nodes[0];
Map<String, Expression> members = annotationInformation.getMembers();
Expression extensions = members.get("extensions");
AnnotatedNode node = (AnnotatedNode) nodes[1];
StaticTypeCheckingVisitor visitor = null;
if (node instanceof ClassNode) {
ClassNode classNode = (ClassNode) node;
visitor = newVisitor(source, classNode);
addTypeCheckingExtensions(visitor, extensions);
visitor.initialize();
visitor.visitClass(classNode);
} else if (node instanceof MethodNode) {
MethodNode methodNode = (MethodNode) node;
visitor = newVisitor(source, methodNode.getDeclaringClass());
addTypeCheckingExtensions(visitor, extensions);
visitor.setMethodsToBeVisited(Collections.singleton(methodNode));
visitor.initialize();
visitor.visitMethod(methodNode);
} else {
source.addError(new SyntaxException(STATIC_ERROR_PREFIX + "Unimplemented node type",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()));
}
if (visitor != null) {
visitor.performSecondPass();
}
}

protected void addTypeCheckingExtensions(StaticTypeCheckingVisitor visitor, Expression extensions) {
if (extensions instanceof ConstantExpression) {
visitor.addTypeCheckingExtension(new GroovyTypeCheckingExtensionSupport(
visitor,
extensions.getText(),
compilationUnit
));
} else if (extensions instanceof ListExpression) {
ListExpression list = (ListExpression) extensions;
for (Expression ext : list.getExpressions()) {
addTypeCheckingExtensions(visitor, ext);
}
}
}

/**
* Allows subclasses to provide their own visitor. This is useful for
* example for transformations relying on the static type checker.
*
*
* @param unit the source unit
* @param node the current classnode
* @return a static type checking visitor
*/
protected StaticTypeCheckingVisitor newVisitor(SourceUnit unit, ClassNode node) {
return new StaticTypeCheckingVisitor(unit, node);
}

public void setCompilationUnit(final CompilationUnit unit) {
this.compilationUnit = unit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public class VRLVisualizationTransformation implements ASTTransformation {
@Override
public void visit(ASTNode[] astNodes, SourceUnit sourceUnit) {

StaticTypesTransformation transformation = new StaticTypesTransformation();
TypeCheckingTransform transformation = new TypeCheckingTransform();
transformation.visit(astNodes, sourceUnit);

VisualCodeBuilder_Impl codeBuilder = new VisualCodeBuilder_Impl();
Expand All @@ -149,6 +149,8 @@ public void visit(ASTNode[] astNodes, SourceUnit sourceUnit) {

// apply transformation for each class in the specified source unit
for (ClassNode clsNode : sourceUnit.getAST().getClasses()) {

transformation.visit(clsNode, sourceUnit);

// if (!scopes.containsKey(clsNode.getName())) {
//
Expand Down Expand Up @@ -569,7 +571,9 @@ public void visitMethodCallExpression(MethodCallExpression s) {

if (mTarget != null && mTarget.getReturnType() != null) {
isVoid = mTarget.getReturnType().getName().toLowerCase().equals("void");
System.out.println("TYPECHECKED!!!");
//System.out.println("TYPECHECKED!!!");
} else {
System.out.println("NO TYPECHECKING!!!");
}

IType returnType;
Expand All @@ -582,6 +586,8 @@ public void visitMethodCallExpression(MethodCallExpression s) {

if (!isIdCall) {
if (objectName != null) {

System.out.println("RET-TYPE: " + returnType);

Invocation invocation = codeBuilder.invokeMethod(
currentScope, objectName,
Expand All @@ -594,9 +600,6 @@ public void visitMethodCallExpression(MethodCallExpression s) {

stateMachine.addToList("variable-declaration:assignment-invocations", invocation);

// currentScope.getControlFlow().getInvocations().
// remove(invocation);

System.out.println("DECL-add-inv: " + invocation);

}
Expand Down Expand Up @@ -930,8 +933,15 @@ private Parameters convertMethodParameters(org.codehaus.groovy.ast.Parameter...

for (int i = 0; i < params.length; i++) {
org.codehaus.groovy.ast.Parameter p = params[i];

String pType = p.getType().getName();

if (pType.startsWith("[L")) {
System.err.print("convertMethodParameters(): array param not supported! " + pType);
pType=pType.replace("[L", "").replace(";", "");
}

result[i] = new Parameter(new Type(p.getType().getName(), true), p.getName());
result[i] = new Parameter(new Type(pType, true), p.getName());
}

return new Parameters(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ public boolean equals(Object obj) {
}

public static Type fromObject(Object o, boolean isReturnOrParamType) {

System.err.println("Type.fromObject() NOT SUPPORTED");

return null;
}

Expand Down
Loading

0 comments on commit 5a58443

Please sign in to comment.