}
if(WeaselModifier.isStatic(wf.getField().getModifier())){
instructions.add(token.line, new WeaselInstructionReadStaticField(wf.getField().getDesk()));
}else{
wvi = compilerHelper.getVariable("this");
instructions.add(token.line, new WeaselInstructionReadFieldOf(wvi.pos, wf.getField().getDesk()));
}
arrayClass = wf.getGenericType();
}else{
arrayClass = wvi.type;
instructions.add(token.line, new WeaselInstructionLoadVariable(wvi.pos));
}
}else{
WeaselGenericField field = elementParent.getGenericField((String)token.param);
if(field==null)
throw new WeaselCompilerException(token.line, "Variable %s not declared in %s", token, elementParent);
arrayClass = field.getGenericType();
instructions.add(token.line, new WeaselInstructionReadField(field.getField().getDesk()));
}
if(!arrayClass.getBaseClass().isArray()){
throw new WeaselCompilerException(token.line, "%s is not an array", arrayClass);
}
WeaselCompilerReturn wcr = func.compile(compiler, compilerHelper, null, new WeaselGenericClass(compiler.baseTypes.intClass), null, false);
instructions.addAll(wcr.getInstructions(compiler, compiler.baseTypes.intClass));
if(write==null){
instructions.add(token.line, new WeaselInstructionReadIndex(WeaselPrimitive.getPrimitiveID(arrayClass.getBaseClass().getArrayClass())));
}else{
instructions.add(token.line, new WeaselInstructionPlaceHolder());
WeaselTree.autoCast(compiler, write, new WeaselGenericClass(arrayClass.getBaseClass().getArrayClass(), arrayClass.getGenerics()), token.line, instructions, true);
instructions.add(token.line, new WeaselInstructionWriteIndex(WeaselPrimitive.getPrimitiveID(arrayClass.getBaseClass().getArrayClass())));
}
return new WeaselCompilerReturnInstructionList(instructions, new WeaselGenericClass(arrayClass.getBaseClass().getArrayClass(), arrayClass.getGenerics()));
}else if(token==null){
return tree.compile(compiler, compilerHelper, write, expect, elementParent, isVariable);
}else{
switch(token.tokenType){
case BOOL:
case DOUBLE:
case INTEGER:
case NULL:
case STRING:
if(write!=null){
throw new WeaselCompilerException(token.line, "Can't write %s to constant %s", write, token);
}
return new WeaselCompilerReturnConstant(compiler, token.line, token.param);
case KEYWORD:
if(token.param!=WeaselKeyWord.THIS)
throw new WeaselCompilerException(token.line, "Expect ident but got %s", token);
case IDENT:
String variable = token.toString();
if(elementParent==null){
WeaselVariableInfo wvi = compilerHelper.getVariable(variable);
if(wvi==null){
WeaselGenericField wf = compilerHelper.getGenericField(variable);
if(wf==null){
WeaselClass weaselClass;
try{
weaselClass = compiler.getWeaselClass(WeaselClass.mapClassNames(variable));
}catch(WeaselNativeException e){
throw new WeaselCompilerException(token.line, "Variable not declared bevore %s", variable);
}
return new WeaselCompilerReturnInstructionList(instructions, new WeaselGenericClass(weaselClass), true);
}
if(WeaselModifier.isStatic(compilerHelper.getCompilingMethod().getMethod().getMethod().getModifier())){
if(!WeaselModifier.isStatic(wf.getField().getModifier())){
throw new WeaselCompilerException(token.line, "Variable %s is not static", variable);
}
}
if(WeaselModifier.isStatic(wf.getField().getModifier())){
if(write==null){
instructions.add(token.line, new WeaselInstructionReadStaticField(wf.getField().getDesk()));
}else{
instructions.add(token.line, new WeaselInstructionPlaceHolder());
WeaselTree.autoCast(compiler, write, wf.getGenericType(), token.line, instructions, true);
instructions.add(token.line, new WeaselInstructionWriteStaticField(wf.getField().getDesk()));
}
}else{
wvi = compilerHelper.getVariable("this");
if(write==null){
instructions.add(token.line, new WeaselInstructionReadFieldOf(wvi.pos, wf.getField().getDesk()));
}else{
instructions.add(token.line, new WeaselInstructionPlaceHolder());
WeaselTree.autoCast(compiler, write, wf.getGenericType(), token.line, instructions, true);
instructions.add(token.line, new WeaselInstructionWriteFieldOf(wvi.pos, wf.getField().getDesk()));
}