MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / doReturn

Method doReturn

ij/src/main/java/ij/macro/Interpreter.java:541–601  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

539
540 // Handle return statement
541 void doReturn() {
542 double value = 0.0;
543 String str = null;
544 Variable[] array = null;
545 int arraySize = 0;
546 getToken();
547 if (token=='(') {
548 int next = pgm.code[pc+1];
549 if ((next&TOK_MASK)==STRING_CONSTANT || (next&TOK_MASK)==STRING_FUNCTION || isString(pc+1))
550 error("String enclosed in parens");
551 }
552 if (token!=';') {
553 boolean isString = token==STRING_CONSTANT || token==STRING_FUNCTION;
554 boolean isArrayFunction = token==ARRAY_FUNCTION;
555 if (token==WORD) {
556 Variable v = lookupLocalVariable(tokenAddress);
557 if (v!=null && nextToken()==';') {
558 array = v.getArray();
559 if (array!=null) arraySize=v.getArraySize();
560 isString = v.getString()!=null;
561 } else if (v!=null && nextToken()=='+')
562 isString = v.getType()==Variable.STRING;
563 }
564 putTokenBack();
565 if (isString)
566 str = getString();
567 else if (isArrayFunction) {
568 getToken();
569 array = func.getArrayFunction(pgm.table[tokenAddress].type);
570 } else if (array==null) {
571 if ((pgm.code[pc+2]&0xff)=='[' && nextToken()==WORD) {
572 int savePC = pc;
573 getToken();
574 Variable v = lookupVariable();
575 v = getArrayElement(v);
576 pc = savePC;
577 if (v.getString()!=null)
578 str = getString();
579 else
580 value = getExpression();
581 } else
582 value = getExpression();
583 }
584 }
585 if (inFunction) {
586 if (returnException==null)
587 returnException = new ReturnException();
588 returnException.value = value;
589 returnException.str = str;
590 returnException.array = array;
591 returnException.arraySize = arraySize;
592 //throw new ReturnException(value, str, array);
593 throw returnException;
594 } else {
595 finishUp();
596 if (value!=0.0 || array!=null)
597 error("Macros can only return strings");
598 returnValue = str;

Callers 1

doStatementMethod · 0.95

Calls 15

getTokenMethod · 0.95
isStringMethod · 0.95
errorMethod · 0.95
lookupLocalVariableMethod · 0.95
nextTokenMethod · 0.95
getArrayMethod · 0.95
getArraySizeMethod · 0.95
getStringMethod · 0.95
getTypeMethod · 0.95
putTokenBackMethod · 0.95
getStringMethod · 0.95
lookupVariableMethod · 0.95

Tested by

no test coverage detected