CompileContext class
Пакет: com.hypixel.hytale.server.npc.util.expression.compile
Файл: com/hypixel/hytale/server/npc/util/expression/compile/CompileContext.java
implements: Parser.ParsedTokenConsumer
Поля (5)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
Parser |
parser |
|
AST |
var1 |
|
ValueType |
var5 |
|
Scope |
var5 |
|
Scope |
var6 |
Методы (19)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("There must be 1 element on stack to get as operand") |
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("Result type can't be void") |
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("Compiled expression result type can't be void") |
abstract |
throw new |
IllegalStateExceptionthrow new IllegalStateException("Result type expected is " + var1 + " but got " + this.resultType) |
abstract |
throw new |
IllegalStateExceptionthrow new IllegalStateException("Need exactly one returned value in expression") |
public |
void |
checkResultTypevoid checkResultType(ValueType var1) |
public |
ValueType |
compileValueType compile(@Nonnull String var1, Scope var2, boolean var3) |
public |
ValueType |
compileValueType compile(@Nonnull String var1, Scope var2, boolean var3, List<ExecutionContext.Instruction> var4) |
public |
ValueType |
compileValueType compile(@Nonnull String var1, boolean var2) |
protected |
ValueType |
compile0ValueType compile0(@Nonnull String var1, Scope var2, boolean var3, List<ExecutionContext.Instruction> var4) |
public |
List<ExecutionContext.Instruction> |
getInstructionsList<ExecutionContext.Instruction> getInstructions() |
public |
ValueType |
getResultTypeValueType getResultType() |
public |
Scope |
getScopeScope getScope() |
|
|
if if(this.instructions == null) |
|
|
if if(var1 == ValueType.VOID) |
|
|
if if(this.resultType == ValueType.VOID) |
|
|
if if(var1 != this.resultType) |
public |
void |
setInstructionsvoid setInstructions(List<ExecutionContext.Instruction> var1) |
abstract |
|
this this() |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.npc.util.expression.compile;
class="kw">import com.hypixel.hytale.server.npc.util.expression.ExecutionContext;
class="kw">import com.hypixel.hytale.server.npc.util.expression.Expression;
class="kw">import com.hypixel.hytale.server.npc.util.expression.Scope;
class="kw">import com.hypixel.hytale.server.npc.util.expression.ValueType;
class="kw">import com.hypixel.hytale.server.npc.util.expression.compile.ast.AST;
class="kw">import com.hypixel.hytale.server.npc.util.expression.compile.ast.ASTOperand;
class="kw">import com.hypixel.hytale.server.npc.util.expression.compile.ast.ASTOperator;
class="kw">import com.hypixel.hytale.server.npc.util.expression.compile.ast.ASTOperatorFunctionCall;
class="kw">import com.hypixel.hytale.server.npc.util.expression.compile.ast.ASTOperatorTuple;
class="kw">import it.unimi.dsi.fastutil.objects.ObjectArrayList;
class="kw">import java.text.ParseException;
class="kw">import java.util.List;
class="kw">import java.util.Stack;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class CompileContext class="kw">implements Parser.ParsedTokenConsumer {
class="kw">private class="kw">final Parser parser = new Parser(Expression.getLexerInstance());
class="kw">private class="kw">final Stack<AST> operandStack = new Stack<>();
@Nonnull
class="kw">private class="kw">final ExecutionContext executionContext;
class="kw">private Scope scope;
class="kw">private List<ExecutionContext.Instruction> instructions;
class="kw">private ValueType resultType = ValueType.VOID;
class="kw">public CompileContext() {
this.executionContext = new ExecutionContext();
}
class="kw">public CompileContext(Scope var1) {
this();
this.scope = var1;
}
class="kw">public Scope getScope() {
class="kw">return this.scope;
}
@Nonnull
class="kw">public Stack<AST> getOperandStack() {
class="kw">return this.operandStack;
}
@Nonnull
class="kw">public ExecutionContext getExecutionContext() {
class="kw">return this.executionContext;
}
class="kw">public ValueType compile(@Nonnull String var1, Scope var2, boolean var3) {
class="kw">return this.compile0(var1, var2, var3, null);
}
class="kw">public ValueType compile(@Nonnull String var1, Scope var2, boolean var3, List<ExecutionContext.Instruction> var4) {
ValueType var5 = this.compile0(var1, var2, var3, var4);
this.setInstructions(null);
class="kw">return var5;
}
class="kw">protected ValueType compile0(@Nonnull String var1, Scope var2, boolean var3, List<ExecutionContext.Instruction> var4) {
Scope var5 = this.scope;
Scope var6 = this.executionContext.setScope(var2);
this.scope = var2;
this.setInstructions(var4);
this.compile(var1, var3);
this.executionContext.setScope(var6);
this.scope = var5;
class="kw">return this.resultType;
}
class="kw">public ValueType compile(@Nonnull String var1, boolean var2) {
try {
this.operandStack.clear();
this.resultType = ValueType.VOID;
if (this.instructions == null) {
this.instructions = new ObjectArrayList();
}
this.instructions.clear();
this.parser.parse(var1, this);
this.resultType = this.operandStack.getFirst().genCode(this.instructions, var2 ? this.scope : null);
class="kw">return this.resultType;
} catch (Throwable var4) {
throw new IllegalStateException("Error compiling expression '" + var1 + "': " + var4.getMessage(), var4);
}
}
class="kw">public List<ExecutionContext.Instruction> getInstructions() {
class="kw">return this.instructions;
}
class="kw">public void setInstructions(List<ExecutionContext.Instruction> var1) {
this.instructions = var1;
}
class="kw">public ValueType getResultType() {
class="kw">return this.resultType;
}
@Nullable
class="kw">public ExecutionContext.Operand getAsOperand() {
if (this.operandStack.size() != 1) {
throw new IllegalArgumentException("There must be 1 element on stack to get as operand");
}
AST var1 = this.operandStack.getFirst();
class="kw">return var1.isConstant() ? var1.asOperand() : null;
}
class="kw">public void checkResultType(ValueType var1) {
if (var1 == ValueType.VOID) {
throw new IllegalArgumentException("Result type can't be void");
}
if (this.resultType == ValueType.VOID) {
throw new IllegalArgumentException("Compiled expression result type can't be void");
}
if (var1 != this.resultType) {
throw new IllegalStateException("Result type expected is " + var1 + " but got " + this.resultType);
}
}
@Override
class="kw">public void pushOperand(@Nonnull Parser.ParsedToken var1) {
this.operandStack.push(ASTOperand.createFromParsedToken(var1, this));
}
@Override
class="kw">public void processOperator(@Nonnull Parser.ParsedToken var1) class="kw">throws ParseException {
ASTOperator.fromParsedOperator(var1, this);
}
@Override
class="kw">public void processFunction(int var1) class="kw">throws ParseException {
ASTOperatorFunctionCall.fromParsedFunction(var1, this);
}
@Override
class="kw">public void processTuple(@Nonnull Parser.ParsedToken var1, int var2) {
ASTOperatorTuple.fromParsedTuple(var1, var2, this);
}
@Override
class="kw">public void done() {
if (this.operandStack.size() != 1) {
throw new IllegalStateException("Need exactly one returned value in expression");
}
}
}