Examples of WeaselCompilerException


Examples of weasel.compiler.WeaselCompilerException

          lwtge = null;
        }
        genericList.add(new WeaselGenericInformation(generic, genericClass, -1));
      }while(token.tokenType == WeaselTokenType.COMMA);
      if(!(lwtge!=null && lwtge.close) && !(token.tokenType==WeaselTokenType.OPERATOR && token.param == WeaselOperator.GREATER)){
        throw new WeaselCompilerException(token.line, "WeaselCompiler.expect > at end of generic declaration but got %s", token);
      }
    }else{
      setNextToken(token);
    }
    genericInformation = genericList.toArray(new WeaselGenericInformation[0]);
View Full Code Here

Examples of weasel.compiler.WeaselCompilerException

    WeaselField field = null;
    try{
      field = getField(name);
    }catch(WeaselNativeException e){}
    if(field!=null && field.getParentClass()==this)
      throw new WeaselCompilerException(nameToken.line, "Duplicated declaration of filed %s", field);
    int id;
    if(WeaselModifier.isStatic(modifier)){
      if(typeInfo.genericClass.isPrimitive()){
        id = ids.staticEasyType++;
        if(WeaselPrimitive.getPrimitiveID(typeInfo.genericClass)==WeaselPrimitive.LONG||WeaselPrimitive.getPrimitiveID(typeInfo.genericClass)==WeaselPrimitive.DOUBLE){
View Full Code Here

Examples of weasel.compiler.WeaselCompilerException

    }
    if(genericID==-1){
      try{
        interpreter.getWeaselClass(className);
      }catch(WeaselNativeException e){
        throw new WeaselCompilerException(token.line, e.getMessage());
      }
    }
    token = iterator.next();
    List<WeaselGenericClassInfo> genericObjects = new ArrayList<WeaselGenericClassInfo>();
    if(token.tokenType==WeaselTokenType.OPERATOR && token.param == WeaselOperator.LESS){
      do{
        token = iterator.next();
        WeaselCompiler.expect(token, WeaselTokenType.IDENT);
        genericObjects.add(readGenericClass(token, iterator));
        token = iterator.next();
      }while(token.tokenType == WeaselTokenType.COMMA);
      if(!(token.tokenType==WeaselTokenType.OPERATOR && token.param == WeaselOperator.GREATER)){
        if(!(token.tokenType==WeaselTokenType.OPERATOR && token.param == WeaselOperator.RSHIFT)){
          onException(token.line, "WeaselCompiler.expect > at end of generic");
        }else{
          token = new WeaselToken(WeaselTokenType.OPERATOR, token.line, WeaselOperator.GREATER);
        }
      }else{
        token = iterator.next();
      }
    }
    while(token.tokenType==WeaselTokenType.OPENINDEX){
      token = iterator.next();
      WeaselCompiler.expect(token, WeaselTokenType.CLOSEINDEX);
      token = iterator.next();
      className = "["+className;
    }
    iterator.previous();
    if(genericID==-1){
      try{
        weaselClass = interpreter.getWeaselClass(className);
      }catch(WeaselNativeException e){
        throw new WeaselCompilerException(token.line, e.getMessage());
      }
      return new WeaselGenericClassInfo(weaselClass, -1, genericObjects.toArray(new WeaselGenericClassInfo[0]));
    }else{
      while(className.charAt(0)=='['){
        weaselClass = new WeaselClass(interpreter, weaselClass, className, null);
View Full Code Here

Examples of weasel.compiler.WeaselCompilerException

        if(tge.close)
          return;
        token = iterator.next();
      }while(token.tokenType==WeaselTokenType.COMMA);
      if(!(token.tokenType==WeaselTokenType.OPERATOR && (token.param==WeaselOperator.GREATER || token.param==WeaselOperator.RSHIFT))){
        throw new WeaselCompilerException(token.line, "Expect > but got %s", token);
      }
    }
    close = token.tokenType==WeaselTokenType.OPERATOR && token.param==WeaselOperator.RSHIFT;
  }
View Full Code Here

Examples of weasel.compiler.WeaselCompilerException

  public static WeaselInstructionList parseAndCompileWhithVarDec(WeaselCompiler compiler, WeaselKeyWordCompilerHelper compilerHelper, ListIterator<WeaselToken> iterator) throws WeaselCompilerException {
   
    WeaselToken token = iterator.next();
    if(token.tokenType==WeaselTokenType.KEYWORD && ((WeaselKeyWord)token.param).compiler!=null){
      throw new WeaselCompilerException(token.line, "Unexpect keyword %s", token);
    }
    if(token.tokenType==WeaselTokenType.MODIFIER){
      return compileVarDec(token, compiler, compilerHelper, iterator);
    }
    if(token.tokenType==WeaselTokenType.IDENT){
View Full Code Here

Examples of weasel.compiler.WeaselCompilerException

  private static int getModifier(List<WeaselToken> modifiers, int allowed) throws WeaselCompilerException{
    int modifier = 0;
    for(WeaselToken modifierToken:modifiers){
      int m = (Integer) modifierToken.param;
      if((m&allowed)==0){
        throw new WeaselCompilerException(modifierToken.line, "Modifier %s is not allowed, only %s %s permitted", WeaselModifier.toString(m),
              WeaselModifier.toString(allowed), WeaselModifier.count(allowed)==1?"is":"are");
      }else if((m&modifier)!=0){
        throw new WeaselCompilerException(modifierToken.line, "Duplicated modifier %s", WeaselModifier.toString(m));
      }else{
        modifier |= m;
        try {
          WeaselChecks.checkModifier(modifier, allowed);
        } catch (WeaselNativeException e) {
          throw new WeaselCompilerException(modifierToken.line, e.getMessage());
        }
      }
    }
    return modifier;
  }
View Full Code Here

Examples of weasel.compiler.WeaselCompilerException

      WeaselToken token = iterator.next();
     
      if(Arrays.asList(end).contains(token.tokenType)){
       
        if(generic!=null)
          throw new WeaselCompilerException(token.line, "Expect Ident but got %s", token);
       
        while(!tokenCache.isEmpty() && ((Properties)tokenCache.get(0).param).suffix!=null){
          tokenSuffix.add(tokenCache.remove(0));
        }
       
        if(tokenCache.size()!=0){
          throw new WeaselCompilerException(token.line, "Expect suffix but got %s", tokenCache.get(0));
        }
       
        if(!tokenSuffix.isEmpty()){
          WeaselTreeAddResult wtar = bottom.add(tokenSuffix, null, null, null, iterator);
          bottom = wtar.newTree;
        }
       
        tokenPrefix.clear();
        tokenSuffix.clear();
        tokenCache.clear();
       
        break;
       
      }else{
     
        if(token.tokenType==WeaselTokenType.KEYWORD && token.param==WeaselKeyWord.INSTANCEOF){
          WeaselToken t = iterator.next();
          WeaselCompiler.expect(t, WeaselTokenType.IDENT);
          String className = (String)t.param;
          t = iterator.next();
          while(t.tokenType==WeaselTokenType.OPERATOR && t.param==WeaselOperator.ELEMENT){
            t = iterator.next();
            WeaselCompiler.expect(t, WeaselTokenType.IDENT);
            className += "."+(String)t.param;
            t = iterator.next();
          }
          if(t.tokenType==WeaselTokenType.OPERATOR && t.param==WeaselOperator.LESS){
            generic = new WeaselTreeGeneric(iterator);
            if(generic.close)
              throw new WeaselCompilerException(t.line, "To many >");
          }else{
            iterator.previous();
          }
          token = new WeaselInstanceofToken(token.line, className, generic);
          generic = null;
        }
       
        if(token.tokenType==WeaselTokenType.COMMA){
          token = new WeaselToken(WeaselTokenType.OPERATOR, token.line, WeaselOperator.COMMA);
        }
       
        if(token.tokenType==WeaselTokenType.QUESTIONMARK){
         
          if(generic!=null)
            throw new WeaselCompilerException(token.line, "Expect Ident but got ?:");
         
          while(!tokenCache.isEmpty() && ((Properties)tokenCache.get(0).param).suffix!=null){
            tokenSuffix.add(tokenCache.remove(0));
          }
         
          if(tokenCache.size()!=0){
            throw new WeaselCompilerException(token.line, "Expect suffix but got %s", tokenCache.get(0));
          }
         
          if(!tokenSuffix.isEmpty()){
            WeaselTreeAddResult wtar = bottom.add(tokenSuffix, null, null, null, iterator);
            bottom = wtar.newTree;
          }
         
          WeaselTree tree = parse(iterator, WeaselTokenType.COLON);
         
          WeaselTreeCondition wtc = new WeaselTreeCondition(tree, token);
         
          WeaselTreeAddResult wtar = wtc.setLeft(bottom);
         
          bottom = wtar.newTree;
         
          start = true;
         
        }else if(token.tokenType == WeaselTokenType.OPERATOR){
         
          if(generic!=null)
            throw new WeaselCompilerException(token.line, "Expect Ident but got %s", token);
         
          tokenCache.add(token);
       
          if(token.param == WeaselOperator.ELEMENT){
            WeaselToken wtoken = iterator.next();
            if(wtoken.tokenType == WeaselTokenType.OPERATOR && wtoken.param ==WeaselOperator.LESS) {
              generic = new WeaselTreeGeneric(iterator);
              token = iterator.previous();
              if(generic.close){
                throw new WeaselCompilerException(token.line, "Expect Ident but got >");
              }
            }else{
              iterator.previous();
            }
          }
         
        }else{
         
          if(generic!=null && token.tokenType != WeaselTokenType.IDENT)
            throw new WeaselCompilerException(token.line, "Expect ident after generic but got %s", token);
         
          boolean isCast = false;
         
          if(token.tokenType==WeaselTokenType.OPENBRACKET){
            WeaselToken token2 = iterator.next();
            String className = "";
            if(token2.tokenType==WeaselTokenType.IDENT){
              isCast = true;
              className = (String)token2.param;
              token2 = iterator.next();
              while(token2.tokenType==WeaselTokenType.OPERATOR && token2.param == WeaselOperator.ELEMENT){
                token2 = iterator.next();
                if(token2.tokenType!=WeaselTokenType.IDENT){
                  isCast = false;
                  break;
                }
                className += "."+(String)token2.param;
                token2 = iterator.next();
              }
              if(token2.tokenType==WeaselTokenType.OPERATOR && token2.param == WeaselOperator.LESS){
                try{
                  generic = new WeaselTreeGeneric(iterator);
                  token2 = iterator.next();
                }catch(WeaselCompilerException e){
                  isCast = false;
                }
              }
              if(isCast && token2.tokenType!=WeaselTokenType.CLOSEBRACKET){
                isCast = false;
              }
            }
            if(isCast){
              tokenCache.add(new WeaselCastToken(token.line, className, generic));
            }else{
              while(iterator.previous() != token);
              iterator.next();
            }
            generic = null;
          }
         
          if(!isCast){
           
            if(start){
             
              while(!tokenCache.isEmpty() && ((Properties)tokenCache.get(tokenCache.size()-1).param).prefix!=null){
                tokenPrefix.add(tokenCache.remove(tokenCache.size()-1));
              }
             
              if(!tokenCache.isEmpty()){
                throw new WeaselCompilerException(token.line, "Expect prefix but got %s", tokenCache.get(0));
              }
             
              if(token.tokenType==WeaselTokenType.OPENBRACKET){
                WeaselTree add = parse(iterator, WeaselTokenType.CLOSEBRACKET);
                if(tokenPrefix.isEmpty()){
                  if(bottom==null){
                    bottom = new WeaselTreeTop(add, iterator);
                  }else{
                    bottom.add(null, null, null, new WeaselTreeTop(add, iterator), iterator);
                  }
                }else{
                  if(bottom==null){
                    bottom = new WeaselTreeLevel(((Properties)tokenPrefix.get(0).param).priority);
                  }
                  WeaselTreeAddResult wtar = bottom.add(null, null, tokenPrefix, add, iterator);
                  bottom = wtar.newTree;
                }
              }else{
                WeaselTree add = new WeaselTreeTop(token, null, iterator);
                if(tokenPrefix.isEmpty()){
                  if(bottom==null){
                    bottom = add;
                  }else{
                    bottom.add(null, null, null, add, iterator);
                  }
                }else{
                  if(bottom==null){
                    bottom = new WeaselTreeLevel(((Properties)tokenPrefix.get(0).param).priority);
                  }
                  WeaselTreeAddResult wtar = bottom.add(null, null, tokenPrefix, add, iterator);
                  bottom = wtar.newTree;
                }
              }
             
              tokenPrefix.clear();
              tokenSuffix.clear();
              tokenCache.clear();
             
              start = false;
             
            }else{
             
              if(tokenCache.size()==0){
                throw new WeaselCompilerException(token.line, "Expect %s before %s", Arrays.toString(end), token);
              }
             
              while(!tokenCache.isEmpty() && ((Properties)tokenCache.get(0).param).suffix!=null){
                tokenSuffix.add(tokenCache.remove(0));
              }
             
              if(tokenCache.isEmpty() && !tokenPrefix.isEmpty()){
                while(true){
                  tokenCache.add(0, tokenPrefix.remove(tokenPrefix.size()-1));
                  if(((Properties)tokenCache.get(0).param).infix!=null){
                    break;
                  }
                }
              }
             
              while(tokenCache.size()>1 && ((Properties)tokenCache.get(tokenCache.size()-1).param).prefix!=null){
                tokenPrefix.add(0, tokenCache.remove(tokenCache.size()-1));
              }
             
              if(tokenCache.size()==0){
                throw new WeaselCompilerException(token.line, "Expect %s before %s", Arrays.toString(end), token);
              }
             
              if(tokenCache.size()>1){
                throw new WeaselCompilerException(tokenCache.get(1).line, "Expect suffix or variable but got %s", tokenCache.get(1));
              }
             
              for(WeaselToken token1:tokenSuffix){
                token1.param = ((Properties)token1.param).suffix;
                if(token1.param==null)
View Full Code Here

Examples of weasel.compiler.WeaselCompilerException

        boolean canCast = WeaselPrimitive.canCastAutoTo(wc1.getBaseClass(), wc2.getBaseClass());
        if(canCast){
          instructions.add(line, new WeaselInstructionCastPrimitive(WeaselPrimitive.getPrimitiveID(wc2.getBaseClass())));
          return wc2;
        }else if(b){
          throw new WeaselCompilerException(line, "Types %s and %s are not compatible", wc1, wc2);
        }
      }
    }
    return wc1;
  }
View Full Code Here

Examples of weasel.compiler.WeaselCompilerException

          if(iterator.next().getGenericParams().length!=param)
            iterator.remove();
        }
        WeaselGenericClass expect = null;
        if(methods.isEmpty())
          throw new WeaselCompilerException(line, "No method %s found with %s params", param);
        List<WeaselGenericClass> params = new ArrayList<WeaselGenericClass>();
        for(int i=0; i<param; i++){
          if(methods.size()==1)
            expect = methods.get(0).getGenericParams()[i];
          wcr = treeLevel.level.get(i).compile(compiler, compilerHelper, null, expect, null, false);
          instructions.addAll(wcr.getInstructions());
          params.add(wcr.getReturnType());
        }
        iterator = methods.iterator();
        while(iterator.hasNext()){
          WeaselGenericMethod2 m=iterator.next();
          for(int i=0; i<param; i++){
            if(params.get(i)!=null && !params.get(i).canCastTo(m.getGenericParams()[i]))
              iterator.remove();
          }
        }
        if(methods.isEmpty()){
          throw new WeaselCompilerException(line, "No method %s found with for params %s", methodName, params);
        }
        if(methods.size()==1){
          method = methods.get(0);
        }else{
          throw new WeaselCompilerException(line, "Not supported now");
        }
        return new WeaselParameterCompileReturn(instructions, method);
      }
    }
    if(func==null){
      method = null;
      for(WeaselGenericMethod2 m:methods){
        if(m.getGenericParams().length==0){
          method = m;
          break;
        }
      }
      if(method==null){
        throw new WeaselCompilerException(line, "No method %s found with no params", methodName);
      }
    }else{
      Iterator<WeaselGenericMethod2> iterator = methods.iterator();
      while(iterator.hasNext()){
        if(iterator.next().getGenericParams().length!=1)
          iterator.remove();
      }
      WeaselGenericClass expect = null;
      if(methods.isEmpty())
        throw new WeaselCompilerException(line, "No method %s found with one param", methodName);
      if(methods.size()==1)
        expect = methods.get(0).getGenericParams()[0];
      wcr = func.compile(compiler, compilerHelper, null, expect, null, false);
      instructions.addAll(wcr.getInstructions());
      iterator = methods.iterator();
      while(iterator.hasNext()){
        WeaselGenericMethod2 m=iterator.next();
        if(!wcr.getReturnType().canCastTo(m.getGenericParams()[0]))
          iterator.remove();
      }
      if(methods.isEmpty()){
        throw new WeaselCompilerException(line, "No method %s found with for param %s", methodName, wcr.getReturnType());
      }
      if(methods.size()==1){
        method = methods.get(0);
      }else{
        throw new WeaselCompilerException(line, "Not supported now");
      }
    }
    return new WeaselParameterCompileReturn(instructions, method);
  }
View Full Code Here

Examples of weasel.compiler.WeaselCompilerException

  }

  @Override
  public WeaselCompilerReturn compile(WeaselCompiler compiler, WeaselKeyWordCompilerHelper compilerHelper, WeaselGenericClass write, WeaselGenericClass expect, WeaselGenericClass elementParent, boolean isVariable) throws WeaselCompilerException {
    if(write!=null){
      throw new WeaselCompilerException(token.line, "Can't write any value to Condition");
    }
    WeaselInstructionList instructions;
    WeaselCompilerReturn wcr = condition.compile(compiler, compilerHelper, null, new WeaselGenericClass(compiler.baseTypes.booleanClass), null, false);
    instructions = wcr.getInstructions(compiler, compiler.baseTypes.booleanClass);
    WeaselInstructionJump j1;
    WeaselInstructionJump j2;
    instructions.add(token.line, j1 = new WeaselInstructionIf());
    wcr = tree1.compile(compiler, compilerHelper, null, expect, elementParent, isVariable);
    WeaselGenericClass wc = wcr.getReturnType();
    instructions.addAll(wcr.getInstructions());
    wcr = tree2.compile(compiler, compilerHelper, null, expect, elementParent, isVariable);
    if(wc.getBaseClass()==compiler.baseTypes.voidClass || wcr.getReturnType().getBaseClass()==compiler.baseTypes.voidClass){
      throw new WeaselCompilerException(token.line, "Can't return void");
    }
    WeaselGenericClass wc2 = wcr.getReturnType();
    wc = WeaselTree.autoCast(compiler, wc, wc2, token.line, instructions, false);
    instructions.add(token.line, j2 = new WeaselInstructionJump());
    j1.setTarget(j2);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.