Skip to content

Commit

Permalink
Fail on duplicate declarations
Browse files Browse the repository at this point in the history
When compiling source code we will get errors here but for byte code
we will load the code but in some cases it will be doing the wrong thing.
  • Loading branch information
pontusmelke committed Oct 5, 2018
1 parent e2a0c4d commit 3cc447e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Expand Up @@ -32,8 +32,12 @@ public class LocalVariables
private final AtomicInteger counter = new AtomicInteger( 0 ); private final AtomicInteger counter = new AtomicInteger( 0 );
private final Map<String,LocalVariable> localVariables = new HashMap<>(); private final Map<String,LocalVariable> localVariables = new HashMap<>();


public LocalVariable createNew( TypeReference type, String name ) LocalVariable createNew( TypeReference type, String name )
{ {
if ( localVariables.containsKey( name ) )
{
throw new IllegalStateException( String.format( "Local variable %s already in scope", name ) );
}
LocalVariable localVariable = new LocalVariable( type, name, counter.getAndIncrement() ); LocalVariable localVariable = new LocalVariable( type, name, counter.getAndIncrement() );
localVariables.put( name, localVariable ); localVariables.put( name, localVariable );
//if 64 bit types we need to give it one more index //if 64 bit types we need to give it one more index
Expand Down
Expand Up @@ -63,13 +63,11 @@ class MethodByteCodeEmitter implements MethodEmitter
private final MethodVisitor methodVisitor; private final MethodVisitor methodVisitor;
private final MethodDeclaration declaration; private final MethodDeclaration declaration;
private final ExpressionVisitor expressionVisitor; private final ExpressionVisitor expressionVisitor;
private final TypeReference base;
private Deque<Block> stateStack = new LinkedList<>(); private Deque<Block> stateStack = new LinkedList<>();


MethodByteCodeEmitter( ClassVisitor classVisitor, MethodDeclaration declaration, TypeReference base ) MethodByteCodeEmitter( ClassVisitor classVisitor, MethodDeclaration declaration, TypeReference ignore )
{ {
this.declaration = declaration; this.declaration = declaration;
this.base = base;
for ( Parameter parameter : declaration.parameters() ) for ( Parameter parameter : declaration.parameters() )
{ {
TypeReference type = parameter.type(); TypeReference type = parameter.type();
Expand Down

0 comments on commit 3cc447e

Please sign in to comment.