// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.server.npc.util.expression.compile.ast;

import java.util.function.Function;
import com.hypixel.hytale.server.npc.util.expression.Scope;
import java.text.ParseException;
import com.hypixel.hytale.server.npc.util.expression.compile.CompileContext;
import com.hypixel.hytale.server.npc.util.expression.ExecutionContext;
import com.hypixel.hytale.server.npc.util.expression.compile.Token;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.npc.util.expression.ValueType;

public class ASTOperatorFunctionCall extends ASTOperator
{
    private final String functionName;
    
    public ASTOperatorFunctionCall(@Nonnull final ValueType returnType, final String functionName, final int tokenPosition) {
        super(returnType, Token.FUNCTION_CALL, tokenPosition);
        this.functionName = functionName;
        this.codeGen = (Function<Scope, ExecutionContext.Instruction>)(scope -> ExecutionContext.genCALL(this.functionName, this.getArguments().size(), scope));
    }
    
    @Override
    public boolean isConstant() {
        return false;
    }
    
    public static void fromParsedFunction(final int argumentCount, @Nonnull final CompileContext compileContext) throws ParseException {
        // 
        // This method could not be decompiled.
        // 
        // Original Bytecode:
        // 
        //     1: invokevirtual   com/hypixel/hytale/server/npc/util/expression/compile/CompileContext.getOperandStack:()Ljava/util/Stack;
        //     4: astore_2        /* operandStack */
        //     5: aload_2         /* operandStack */
        //     6: invokevirtual   java/util/Stack.size:()I
        //     9: istore_3        /* len */
        //    10: aload_2         /* operandStack */
        //    11: iload_3         /* len */
        //    12: iload_0         /* argumentCount */
        //    13: isub           
        //    14: iconst_1       
        //    15: isub           
        //    16: invokevirtual   java/util/Stack.get:(I)Ljava/lang/Object;
        //    19: checkcast       Lcom/hypixel/hytale/server/npc/util/expression/compile/ast/AST;
        //    22: astore          functionNameAST
        //    24: aload           functionNameAST
        //    26: instanceof      instanceof     !!! ERROR
        //    29: ifeq            42
        //    32: aload           functionNameAST
        //    34: checkcast       checkcast      !!! ERROR
        //    37: astore          identifier
        //    39: goto            68
        //    42: new             Ljava/text/ParseException;
        //    45: dup            
        //    46: aload           functionNameAST
        //    48: invokevirtual   com/hypixel/hytale/server/npc/util/expression/compile/ast/AST.getValueType:()Lcom/hypixel/hytale/server/npc/util/expression/ValueType;
        //    51: invokestatic    java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;
        //    54: invokedynamic   BootstrapMethod #1, makeConcatWithConstants:(Ljava/lang/String;)Ljava/lang/String;
        //    59: aload           functionNameAST
        //    61: invokevirtual   com/hypixel/hytale/server/npc/util/expression/compile/ast/AST.getTokenPosition:()I
        //    64: invokespecial   java/text/ParseException.<init>:(Ljava/lang/String;I)V
        //    67: athrow         
        //    68: new             Ljava/lang/StringBuilder;
        //    71: dup            
        //    72: aload           identifier
        //    74: invokevirtual   invokevirtual  !!! ERROR
        //    77: invokespecial   java/lang/StringBuilder.<init>:(Ljava/lang/String;)V
        //    80: bipush          64
        //    82: invokevirtual   java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
        //    85: astore          name
        //    87: iconst_1       
        //    88: istore          isConstant
        //    90: iload_3         /* len */
        //    91: iload_0         /* argumentCount */
        //    92: isub           
        //    93: istore          firstArgument
        //    95: iload           firstArgument
        //    97: istore          i
        //    99: iload           i
        //   101: iload_3         /* len */
        //   102: if_icmpge       146
        //   105: aload_2         /* operandStack */
        //   106: iload           i
        //   108: invokevirtual   java/util/Stack.get:(I)Ljava/lang/Object;
        //   111: checkcast       Lcom/hypixel/hytale/server/npc/util/expression/compile/ast/AST;
        //   114: astore          ast
        //   116: aload           name
        //   118: aload           ast
        //   120: invokevirtual   com/hypixel/hytale/server/npc/util/expression/compile/ast/AST.getValueType:()Lcom/hypixel/hytale/server/npc/util/expression/ValueType;
        //   123: invokestatic    com/hypixel/hytale/server/npc/util/expression/Scope.encodeType:(Lcom/hypixel/hytale/server/npc/util/expression/ValueType;)C
        //   126: invokevirtual   java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
        //   129: pop            
        //   130: iload           isConstant
        //   132: aload           ast
        //   134: invokevirtual   com/hypixel/hytale/server/npc/util/expression/compile/ast/AST.isConstant:()Z
        //   137: iand           
        //   138: istore          isConstant
        //   140: iinc            i, 1
        //   143: goto            99
        //   146: aload           name
        //   148: invokevirtual   java/lang/StringBuilder.toString:()Ljava/lang/String;
        //   151: astore          functionName
        //   153: aload_1         /* compileContext */
        //   154: invokevirtual   com/hypixel/hytale/server/npc/util/expression/compile/CompileContext.getScope:()Lcom/hypixel/hytale/server/npc/util/expression/Scope;
        //   157: astore          scope
        //   159: aload           scope
        //   161: aload           functionName
        //   163: invokeinterface com/hypixel/hytale/server/npc/util/expression/Scope.getType:(Ljava/lang/String;)Lcom/hypixel/hytale/server/npc/util/expression/ValueType;
        //   168: astore          resultType
        //   170: aload           resultType
        //   172: ifnonnull       190
        //   175: new             Ljava/lang/IllegalStateException;
        //   178: dup            
        //   179: aload           functionName
        //   181: invokedynamic   BootstrapMethod #2, makeConcatWithConstants:(Ljava/lang/String;)Ljava/lang/String;
        //   186: invokespecial   java/lang/IllegalStateException.<init>:(Ljava/lang/String;)V
        //   189: athrow         
        //   190: iload           isConstant
        //   192: aload           scope
        //   194: aload           functionName
        //   196: invokeinterface com/hypixel/hytale/server/npc/util/expression/Scope.isConstant:(Ljava/lang/String;)Z
        //   201: iand           
        //   202: istore          isConstant
        //   204: iload           isConstant
        //   206: ifeq            336
        //   209: aload_1         /* compileContext */
        //   210: invokevirtual   com/hypixel/hytale/server/npc/util/expression/compile/CompileContext.getInstructions:()Ljava/util/List;
        //   213: astore          instructionList
        //   215: aload_1         /* compileContext */
        //   216: invokevirtual   com/hypixel/hytale/server/npc/util/expression/compile/CompileContext.getExecutionContext:()Lcom/hypixel/hytale/server/npc/util/expression/ExecutionContext;
        //   219: astore          executionContext
        //   221: aload           instructionList
        //   223: invokeinterface java/util/List.clear:()V
        //   228: iload           firstArgument
        //   230: istore          i
        //   232: iload           i
        //   234: iload_3         /* len */
        //   235: if_icmpge       260
        //   238: aload_2         /* operandStack */
        //   239: iload           i
        //   241: invokevirtual   java/util/Stack.get:(I)Ljava/lang/Object;
        //   244: checkcast       Lcom/hypixel/hytale/server/npc/util/expression/compile/ast/AST;
        //   247: aload           instructionList
        //   249: aconst_null    
        //   250: invokevirtual   com/hypixel/hytale/server/npc/util/expression/compile/ast/AST.genCode:(Ljava/util/List;Lcom/hypixel/hytale/server/npc/util/expression/Scope;)Lcom/hypixel/hytale/server/npc/util/expression/ValueType;
        //   253: pop            
        //   254: iinc            i, 1
        //   257: goto            232
        //   260: aload           instructionList
        //   262: aload           functionName
        //   264: iload_0         /* argumentCount */
        //   265: aconst_null    
        //   266: invokestatic    com/hypixel/hytale/server/npc/util/expression/ExecutionContext.genCALL:(Ljava/lang/String;ILcom/hypixel/hytale/server/npc/util/expression/Scope;)Lcom/hypixel/hytale/server/npc/util/expression/ExecutionContext$Instruction;
        //   269: invokeinterface java/util/List.add:(Ljava/lang/Object;)Z
        //   274: pop            
        //   275: aload           executionContext
        //   277: aload           instructionList
        //   279: aload           scope
        //   281: invokevirtual   com/hypixel/hytale/server/npc/util/expression/ExecutionContext.execute:(Ljava/util/List;Lcom/hypixel/hytale/server/npc/util/expression/Scope;)Lcom/hypixel/hytale/server/npc/util/expression/ValueType;
        //   284: astore          ret
        //   286: aload           ret
        //   288: getstatic       com/hypixel/hytale/server/npc/util/expression/ValueType.VOID:Lcom/hypixel/hytale/server/npc/util/expression/ValueType;
        //   291: if_acmpne       304
        //   294: new             Ljava/lang/IllegalStateException;
        //   297: dup            
        //   298: ldc             "Failed to evaluate constant function AST"
        //   300: invokespecial   java/lang/IllegalStateException.<init>:(Ljava/lang/String;)V
        //   303: athrow         
        //   304: aload_2         /* operandStack */
        //   305: iload           firstArgument
        //   307: iconst_1       
        //   308: isub           
        //   309: invokevirtual   java/util/Stack.setSize:(I)V
        //   312: aload_2         /* operandStack */
        //   313: aload           functionNameAST
        //   315: invokevirtual   com/hypixel/hytale/server/npc/util/expression/compile/ast/AST.getToken:()Lcom/hypixel/hytale/server/npc/util/expression/compile/Token;
        //   318: aload           functionNameAST
        //   320: invokevirtual   com/hypixel/hytale/server/npc/util/expression/compile/ast/AST.getTokenPosition:()I
        //   323: aload           executionContext
        //   325: invokevirtual   com/hypixel/hytale/server/npc/util/expression/ExecutionContext.top:()Lcom/hypixel/hytale/server/npc/util/expression/ExecutionContext$Operand;
        //   328: invokestatic    invokestatic   !!! ERROR
        //   331: invokevirtual   java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
        //   334: pop            
        //   335: return         
        //   336: new             Lcom/hypixel/hytale/server/npc/util/expression/compile/ast/ASTOperatorFunctionCall;
        //   339: dup            
        //   340: aload           resultType
        //   342: aload           functionName
        //   344: aload           functionNameAST
        //   346: invokevirtual   com/hypixel/hytale/server/npc/util/expression/compile/ast/AST.getTokenPosition:()I
        //   349: invokespecial   com/hypixel/hytale/server/npc/util/expression/compile/ast/ASTOperatorFunctionCall.<init>:(Lcom/hypixel/hytale/server/npc/util/expression/ValueType;Ljava/lang/String;I)V
        //   352: astore          function
        //   354: iload           firstArgument
        //   356: istore          i
        //   358: iload           i
        //   360: iload_3         /* len */
        //   361: if_icmpge       384
        //   364: aload           function
        //   366: aload_2         /* operandStack */
        //   367: iload           i
        //   369: invokevirtual   java/util/Stack.get:(I)Ljava/lang/Object;
        //   372: checkcast       Lcom/hypixel/hytale/server/npc/util/expression/compile/ast/AST;
        //   375: invokevirtual   com/hypixel/hytale/server/npc/util/expression/compile/ast/ASTOperatorFunctionCall.addArgument:(Lcom/hypixel/hytale/server/npc/util/expression/compile/ast/AST;)V
        //   378: iinc            i, 1
        //   381: goto            358
        //   384: aload_2         /* operandStack */
        //   385: iload           firstArgument
        //   387: iconst_1       
        //   388: isub           
        //   389: invokevirtual   java/util/Stack.setSize:(I)V
        //   392: aload_2         /* operandStack */
        //   393: aload           function
        //   395: invokevirtual   java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
        //   398: pop            
        //   399: return         
        //    Exceptions:
        //  throws java.text.ParseException
        //    StackMapTable: 00 0B FE 00 2A 07 00 22 01 07 00 2B FC 00 19 07 00 2D FF 00 1E 00 0A 01 07 00 1C 07 00 22 01 07 00 2B 07 00 2D 07 00 45 01 01 01 00 00 FA 00 2E FE 00 2B 07 00 36 07 00 53 07 00 8E FE 00 29 07 00 77 07 00 81 01 FA 00 1B FC 00 2B 07 00 8E F8 00 1F FD 00 15 07 00 0E 01 FA 00 19
        // 
        // The error that occurred was:
        // 
        // java.lang.ClassCastException
        // 
        throw new IllegalStateException("An error occurred while decompiling this method.");
    }
}
