Package weasel.compiler

Examples of weasel.compiler.WeaselCompilerReturnConstant


      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()));
              }
            }
            return new WeaselCompilerReturnInstructionList(instructions, wf.getGenericType());
          }else{
            if(write==null){
              instructions.add(token.line, new WeaselInstructionLoadVariable(wvi.pos));
            }else{
              instructions.add(token.line, new WeaselInstructionPlaceHolder());
              WeaselTree.autoCast(compiler, write, wvi.type, token.line, instructions, true);
              instructions.add(token.line, new WeaselInstructionSaveVariable(wvi.pos));
            }
            return new WeaselCompilerReturnInstructionList(instructions, wvi.type);
          }
        }else{
          WeaselGenericField wf = elementParent.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);
            }
            if(isVariable){
              throw new WeaselCompilerException(token.line, "Can't get class form variable", variable);
            }
            return new WeaselCompilerReturnInstructionList(instructions, new WeaselGenericClass(weaselClass), true);
          }
          if(isVariable){
            if(write==null){
              instructions.add(token.line, new WeaselInstructionReadField(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 WeaselInstructionWriteField(wf.getField().getDesk()));
            }
          }else{
            if(!WeaselModifier.isStatic(wf.getField().getModifier()))
              throw new WeaselCompilerException(token.line, "Filed %s isn't static", wf);
            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()));
            }
          }
          return new WeaselCompilerReturnInstructionList(instructions, wf.getGenericType());
        }
      case CHAR:
        if(write!=null){
          throw new WeaselCompilerException(token.line, "Can't write %s to constant %s", write, token);
        }
        String s = (String) token.param;
        if(s.length()!=1)
          throw new WeaselCompilerException(token.line, "Only one char expected");
        return new WeaselCompilerReturnConstant(compiler, token.line, s.charAt(0));
      default:
        throw new WeaselCompilerException(token.line, "Expect ident but got %s", token);
      }
    }
  }
View Full Code Here

TOP

Related Classes of weasel.compiler.WeaselCompilerReturnConstant

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.