Exemplo n.º 1
0
 private void passStacktraceParams(
     final Multimap<ImFunction, ImFunctionCall> calls, Set<ImFunction> affectedFuncs) {
   // pass the stacktrace parameter at all cals
   for (ImFunction f : affectedFuncs) {
     for (ImFunctionCall call : calls.get(f)) {
       ImFunction caller = call.getNearestFunc();
       ImExpr stExpr;
       if (isMainOrConfig(caller)) {
         stExpr = str("   " + f.getName());
       } else {
         ImVar stackTraceVar = getStackTraceVar(caller);
         WPos source = call.attrTrace().attrSource();
         String callPos;
         if (source.getFile().startsWith("<")) {
           callPos = "";
         } else {
           callPos = "\n   " + source.printShort();
         }
         stExpr =
             JassIm.ImOperatorCall(
                 WurstOperator.PLUS,
                 JassIm.ImExprs(str(callPos), JassIm.ImVarAccess(stackTraceVar)));
       }
       call.getArguments().add(stExpr);
     }
   }
 }
Exemplo n.º 2
0
 private static LineOffsets getLineOffsets(WPos p) {
   LineOffsets lineOffsets;
   if (p.getLineOffsets() instanceof LineOffsets) {
     lineOffsets = (LineOffsets) p.getLineOffsets();
   } else {
     lineOffsets = new LineOffsets();
   }
   return lineOffsets;
 }
Exemplo n.º 3
0
 /**
  * makes a best effort to get a precise position for this element
  *
  * @param e
  * @return
  */
 public static WPos getPos(AstElement e) {
   if (e instanceof AstElementWithSource) {
     AstElementWithSource ws = (AstElementWithSource) e;
     return ws.getSource();
   }
   if (e.size() > 0) { // try to find the position by examining the childs
     int min = Integer.MAX_VALUE;
     int max = Integer.MIN_VALUE;
     for (int i = 0; i < e.size(); i++) {
       AstElement child = e.get(i);
       WPos childSource = child.attrSource();
       min = Math.min(min, childSource.getLeftPos());
       max = Math.max(max, childSource.getRightPos());
     }
     return new WPos(
         e.get(0).attrSource().getFile(), e.get(0).attrSource().getLineOffsets(), min, max);
   }
   // if no childs exist, search a parent element with a explicit position
   AstElement parent = e.getParent();
   while (parent != null) {
     if (parent instanceof AstElementWithSource) {
       WPos parentSource = ((AstElementWithSource) parent).getSource();
       // use parent position but with size -1, so we do not go into this
       return new WPos(
           parentSource.getFile(),
           parentSource.getLineOffsets(),
           parentSource.getLeftPos(),
           parentSource.getLeftPos() - 1);
     }
     parent = parent.getParent();
   }
   return new WPos("<source of " + e + " not found>", new LineOffsets(), 0, 0);
 }
Exemplo n.º 4
0
 private static CompileError makeCompileError(
     AstElement e, String msg, ErrorHandler handler, CompileError.ErrorType errorType)
     throws CompileError {
   WPos pos = e.attrErrorPos();
   if (handler.isUnitTestMode()) {
     throw new CompileError(pos, msg);
   }
   ListIterator<CompileError> it = handler.getErrors().listIterator();
   while (it.hasNext()) {
     CompileError err = it.next();
     if (err.getSource().getFile().equals(pos.getFile())) {
       if (bigger(err.getSource(), pos)) {
         // remove bigger errors
         it.remove();
       } else if (bigger(pos, err.getSource()) || equal(pos, err.getSource())) {
         // do not add smaller or equal errors
         return null;
       }
     }
   }
   return new CompileError(pos, msg, errorType);
 }
Exemplo n.º 5
0
 public static WPos getErrorPos(FuncDef e) {
   WPos pos = e.getSource();
   return pos.withRightPos(pos.getLeftPos() + ("function " + e.getName()).length());
 }
Exemplo n.º 6
0
 public static WPos getErrorPos(WPackage e) {
   WPos pos = e.getSource();
   return pos.withRightPos(pos.getLeftPos() + ("package " + e.getName()).length());
 }
Exemplo n.º 7
0
 public static int getEndLine(WPos p) {
   LineOffsets lineOffsets = getLineOffsets(p);
   return lineOffsets.getLine(p.getRightPos()) + 1;
 }
Exemplo n.º 8
0
 public static int getEndColumn(WPos p) {
   LineOffsets lineOffsets = getLineOffsets(p);
   return p.getRightPos() - lineOffsets.get(p.getEndLine() - 1);
 }
Exemplo n.º 9
0
 public static WPos getErrorPos(StructureDef e) {
   WPos pos = e.getSource();
   return pos.withRightPos(pos.getLeftPos() + 5 + e.getName().length());
 }
Exemplo n.º 10
0
 public static WPos getErrorPos(OnDestroyDef e) {
   WPos pos = e.getSource();
   return pos.withRightPos(pos.getLeftPos() + ("ondestroy").length());
 }
Exemplo n.º 11
0
 public static WPos getErrorPos(InitBlock e) {
   WPos pos = e.getSource();
   return pos.withRightPos(pos.getLeftPos() + ("init").length());
 }
Exemplo n.º 12
0
 public static WPos getErrorPos(ConstructorDef e) {
   WPos pos = e.getSource();
   return pos.withRightPos(pos.getLeftPos() + ("construct").length());
 }
Exemplo n.º 13
0
 public static WPos getErrorPos(ClassDef e) {
   WPos pos = e.getSource();
   return pos.withRightPos(pos.getLeftPos() + ("class " + e.getName()).length());
 }
Exemplo n.º 14
0
 public static WPos getErrorPos(ExtensionFuncDef e) {
   WPos pos = e.getSource();
   return pos.withRightPos(
       e.getExtendedType().getSource().getRightPos() + (".function " + e.getName()).length());
 }
Exemplo n.º 15
0
 private static boolean bigger(WPos a, WPos b) {
   return a.getLeftPos() <= b.getLeftPos() && a.getRightPos() > b.getRightPos()
       || a.getLeftPos() < b.getLeftPos() && a.getRightPos() >= b.getRightPos();
 }
Exemplo n.º 16
0
 private static boolean equal(WPos a, WPos b) {
   return a.getLeftPos() == b.getLeftPos() && a.getRightPos() == b.getRightPos();
 }