// File: menhits[P]phplus/src/AstNode.cpp
// Function: AstToken::resolveAction()
void AstToken::resolveAction()
{
	//error.log("resolveAction called for token "+token->getText(), JSYK, token);
	
	if (token->getType()==TokenData::IDENTIFIER || token->getType()==TokenData::OPERATOR)
	{
		if (token->getOp() && !token->getOp()->isOverloadable())
		{
			throw PhplusError("non overloadable operator in AstToken, it should have been removed and processed by the parser", INTERNAL_ERROR, token);
		}
		
		/*
		if (inLeftType->getType()==TypeBase::TUPLE && inLeftType->getSubType(token->getText()).type!=nullptr)
		{
			if (inRightType->isVoid())
			{
				action=getElemFromTupleAction(inLeftType, token->getText());
				return;
			}
			else
			{
				throw PhplusError("sorry, Phplus does not yet support mutating tuples", SOURCE_ERROR, token);
			}
		}
		*/
		
		action=ns->getActionForTokenWithInput(token, inLeftType, inRightType, dynamic, true, token);
		
		/*
		try
		{
			//error.log("looking for "+token->getText()+" in\n"+ns->getStringWithParents(), JSYK, token);
			action=ns->getActionForTokenWithInput(token, inLeftType, inRightType, dynamic);
		}
		catch (IdNotFoundError err)
		{
			if (token->getType()==TokenData::OPERATOR)
			{
				throw PhplusError("unknown overload for "+inLeftType->getString()+" "+token->getText()+" "+inRightType->getString()+"'", SOURCE_ERROR, token);
			}
			else if (token->getType()==TokenData::IDENTIFIER)
			{
				vector<Action> actions;
				ns->getActions(token->getText(), actions, dynamic);
				
				if (actions.size()>0) // if there are actions with the requested name that didn't match the type
				{
					string posibleInputs="the following is the inputs it can take:";
					
					for (int i=0; i<(int)actions.size(); i++)
					{
						posibleInputs+="\n    ";
						posibleInputs+=actions[i]->getInLeftType()->getString()+" . "+actions[i]->getInRightType()->getString()+" -> "+actions[i]->getReturnType()->getString();
					}
					
					throw PhplusError(
						"'"+token->getText()+"' can not take input of type "+
						inLeftType->getString()+" . "+inRightType->getString()+"\n"+
						posibleInputs,
						SOURCE_ERROR, token);
				}
			}
			
			if (inRightType->getType()==TypeBase::METATYPE)
			{
				throw PhplusError("metatype handeling in "+FUNC+" not yet implemented", INTERNAL_ERROR, token);
			}
			else if (inRightType->isVoid())
			{
				//throw PhplusError("unknown identifier '"+token->getText()+"' (var can not be made bc right in type is "+type->getString()+")", SOURCE_ERROR, token);
				throw PhplusError("unknown identifier '"+token->getText()+"'", SOURCE_ERROR, token);
			}
			else if (!inRightType->isCreatable())
			{
				throw PhplusError("cannot create variable '"+token->getText()+"' of type {"+inRightType->getString()+"}", SOURCE_ERROR, token);
			}
			
			ns->addVar(inRightType, token->getText());
			
			try
			{
				action=ns->getActionForTokenWithInput(token, inLeftType, inRightType, dynamic);
			}
			catch (IdNotFoundError err)
			{
				throw err.toPhplusError(token);
			}
		}
		*/
	}
	else if (token->getType()==TokenData::LITERAL || token->getType()==TokenData::STRING_LITERAL)
	{
		if (!inLeftType->isVoid() || !inRightType->isVoid())
		{
			throw PhplusError("a literal can not be given an input", SOURCE_ERROR, token);
		}
		
		action=resolveLiteral(token);
	}
	else
	{
		throw PhplusError("AstToken givin invalid token '"+token->getText()+"' of type "+TokenData::typeToString(token->getType()), INTERNAL_ERROR, token);
	}
}

// Assembly:
subq $0x288, %rsp            # imm = 0x288
movq %rdi, 0x280(%rsp)
movq 0x280(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
addq $0x88, %rdi
callq 0x1bb70
movq %rax, %rdi
callq 0x1bee0
cmpl $0x2, %eax
je 0x18ffd
movq 0xa0(%rsp), %rdi
addq $0x88, %rdi
callq 0x1bb70
movq %rax, %rdi
callq 0x1bee0
cmpl $0x5, %eax
jne 0x193f4
movq 0xa0(%rsp), %rdi
addq $0x88, %rdi
callq 0x1bb70
movq %rax, %rsi
leaq 0x270(%rsp), %rdi
callq 0x1bc10
leaq 0x270(%rsp), %rdi
callq 0x1bef0
movb %al, %cl
movb $0x0, 0x253(%rsp)
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x9f(%rsp)
jne 0x19048
jmp 0x190a4
movq 0xa0(%rsp), %rdi
addq $0x88, %rdi
callq 0x1bb70
movq %rax, %rsi
leaq 0x260(%rsp), %rdi
callq 0x1bc10
jmp 0x1906e
movb $0x1, 0x253(%rsp)
leaq 0x260(%rsp), %rdi
callq 0xf9f0
movq %rax, %rdi
callq 0x1bf10
movb %al, 0x9e(%rsp)
jmp 0x19094
movb 0x9e(%rsp), %al
xorb $-0x1, %al
movb %al, 0x9f(%rsp)
movb 0x9f(%rsp), %al
movb %al, 0x9d(%rsp)
testb $0x1, 0x253(%rsp)
jne 0x190be
jmp 0x190cb
leaq 0x260(%rsp), %rdi
callq 0xf9a0
leaq 0x270(%rsp), %rdi
callq 0xf9a0
movb 0x9d(%rsp), %al
testb $0x1, %al
jne 0x190e8
jmp 0x1926b
movb $0x1, 0x217(%rsp)
movl $0x38, %edi
callq 0xb1f0
movq %rax, 0x88(%rsp)
leaq 0x22f(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0xb690
movq 0x90(%rsp), %rdx
leaq 0xb82f3(%rip), %rsi     # 0xd1419
leaq 0x230(%rsp), %rdi
callq 0xb4c0
jmp 0x19135
movq 0xa0(%rsp), %rsi
addq $0x88, %rsi
leaq 0x218(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x1bc90
movq 0x88(%rsp), %rdi
movq 0x80(%rsp), %rcx
leaq 0x230(%rsp), %rsi
movl $0x3, %edx
callq 0x35600
jmp 0x1917d
movq 0x88(%rsp), %rdi
movb $0x0, 0x217(%rsp)
leaq 0xfc434(%rip), %rsi     # 0x1155c8
leaq 0x14d5(%rip), %rdx      # 0x1a670
callq 0xb640
jmp 0x19856
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x191ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
testb $0x1, 0x253(%rsp)
jne 0x191db
jmp 0x191e8
leaq 0x260(%rsp), %rdi
callq 0xf9a0
jmp 0x191ea
leaq 0x270(%rsp), %rdi
callq 0xf9a0
jmp 0x19849
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x19240
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x218(%rsp), %rdi
callq 0xfc00
leaq 0x230(%rsp), %rdi
callq 0xb6e8
leaq 0x22f(%rsp), %rdi
callq 0xb3f0
testb $0x1, 0x217(%rsp)
jne 0x19259
jmp 0x19266
movq 0x88(%rsp), %rdi
callq 0xb2d0
jmp 0x19849
movq 0xa0(%rsp), %rdi
addq $0x70, %rdi
callq 0x1a6a0
movq 0xa0(%rsp), %rsi
movq %rax, 0x60(%rsp)
addq $0x88, %rsi
movq %rsi, 0x48(%rsp)
leaq 0x1f0(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x1bc90
movq 0xa0(%rsp), %rsi
addq $0x28, %rsi
leaq 0x1e0(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x1a920
movq 0xa0(%rsp), %rsi
addq $0x38, %rsi
leaq 0x1d0(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x1a920
movq 0xa0(%rsp), %rax
movq 0x48(%rsp), %rsi
movzbl 0x68(%rax), %eax
movl %eax, 0x5c(%rsp)
leaq 0x1c0(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x1bc90
movq 0x50(%rsp), %rdi
movl 0x5c(%rsp), %r9d
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %r8
movq %rsp, %rax
movq %rdi, 0x8(%rax)
movl $0x1, (%rax)
andl $0x1, %r9d
leaq 0x200(%rsp), %rdi
callq 0x3cbb0
jmp 0x19348
movq 0xa0(%rsp), %rdi
addq $0x48, %rdi
leaq 0x200(%rsp), %rsi
callq 0x1ac90
leaq 0x200(%rsp), %rdi
callq 0x1acc0
leaq 0x1c0(%rsp), %rdi
callq 0xfc00
leaq 0x1d0(%rsp), %rdi
callq 0x1a950
leaq 0x1e0(%rsp), %rdi
callq 0x1a950
leaq 0x1f0(%rsp), %rdi
callq 0xfc00
jmp 0x19841
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0xfc00
leaq 0x1d0(%rsp), %rdi
callq 0x1a950
leaq 0x1e0(%rsp), %rdi
callq 0x1a950
leaq 0x1f0(%rsp), %rdi
callq 0xfc00
jmp 0x19849
movq 0xa0(%rsp), %rdi
addq $0x88, %rdi
callq 0x1bb70
movq %rax, %rdi
callq 0x1bee0
cmpl $0x3, %eax
je 0x1943a
movq 0xa0(%rsp), %rdi
addq $0x88, %rdi
callq 0x1bb70
movq %rax, %rdi
callq 0x1bee0
cmpl $0x4, %eax
jne 0x19620
movq 0xa0(%rsp), %rdi
addq $0x28, %rdi
callq 0x1a660
movq %rax, %rdi
movq (%rdi), %rax
callq *0x28(%rax)
testb $0x1, %al
jne 0x1945a
jmp 0x1947c
movq 0xa0(%rsp), %rdi
addq $0x38, %rdi
callq 0x1a660
movq %rax, %rdi
movq (%rdi), %rax
callq *0x28(%rax)
testb $0x1, %al
jne 0x1958d
movb $0x1, 0x187(%rsp)
movl $0x38, %edi
callq 0xb1f0
movq %rax, 0x38(%rsp)
leaq 0x19f(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0xb690
movq 0x40(%rsp), %rdx
leaq 0xb7fc7(%rip), %rsi     # 0xd1478
leaq 0x1a0(%rsp), %rdi
callq 0xb4c0
jmp 0x194c0
movq 0xa0(%rsp), %rsi
addq $0x88, %rsi
leaq 0x188(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x1bc90
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rcx
leaq 0x1a0(%rsp), %rsi
xorl %edx, %edx
callq 0x35600
jmp 0x194fc
movq 0x38(%rsp), %rdi
movb $0x0, 0x187(%rsp)
leaq 0xfc0b8(%rip), %rsi     # 0x1155c8
leaq 0x1159(%rip), %rdx      # 0x1a670
callq 0xb640
jmp 0x19856
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x19565
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x188(%rsp), %rdi
callq 0xfc00
leaq 0x1a0(%rsp), %rdi
callq 0xb6e8
leaq 0x19f(%rsp), %rdi
callq 0xb3f0
testb $0x1, 0x187(%rsp)
jne 0x1957e
jmp 0x19588
movq 0x38(%rsp), %rdi
callq 0xb2d0
jmp 0x19849
movq 0xa0(%rsp), %rsi
addq $0x88, %rsi
leaq 0x160(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x1bc90
movq 0x28(%rsp), %rsi
leaq 0x170(%rsp), %rdi
callq 0x9adc0
jmp 0x195c2
movq 0xa0(%rsp), %rdi
addq $0x48, %rdi
leaq 0x170(%rsp), %rsi
callq 0x1ac90
leaq 0x170(%rsp), %rdi
callq 0x1acc0
leaq 0x160(%rsp), %rdi
callq 0xfc00
jmp 0x1983f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x160(%rsp), %rdi
callq 0xfc00
jmp 0x19849
movb $0x1, 0xaf(%rsp)
movl $0x38, %edi
callq 0xb1f0
movq 0xa0(%rsp), %rdi
movq %rax, 0x20(%rsp)
addq $0x88, %rdi
callq 0x1bb70
movq %rax, %rsi
leaq 0xe0(%rsp), %rdi
callq 0x1bb80
jmp 0x1965d
leaq 0xb7e38(%rip), %rsi     # 0xd149c
leaq 0x100(%rsp), %rdi
leaq 0xe0(%rsp), %rdx
callq 0x1bcf0
jmp 0x1967b
leaq 0xb7e39(%rip), %rdx     # 0xd14bb
leaq 0x120(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0xfa60
jmp 0x19699
movq 0xa0(%rsp), %rdi
addq $0x88, %rdi
callq 0x1bb70
movq %rax, %rdi
callq 0x1bee0
movl %eax, 0x1c(%rsp)
jmp 0x196bb
movl 0x1c(%rsp), %esi
leaq 0xc0(%rsp), %rdi
callq 0x9d240
jmp 0x196ce
leaq 0x140(%rsp), %rdi
leaq 0x120(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
callq 0x1bf20
jmp 0x196ed
movq 0xa0(%rsp), %rsi
addq $0x88, %rsi
leaq 0xb0(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x1bc90
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rcx
leaq 0x140(%rsp), %rsi
movl $0x3, %edx
callq 0x35600
jmp 0x1972c
movq 0x20(%rsp), %rdi
movb $0x0, 0xaf(%rsp)
leaq 0xfbe88(%rip), %rsi     # 0x1155c8
leaq 0xf29(%rip), %rdx       # 0x1a670
callq 0xb640
jmp 0x19856
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x19827
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x1981a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x1980d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x19800
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x197f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0xfc00
leaq 0x140(%rsp), %rdi
callq 0xb6e8
leaq 0xc0(%rsp), %rdi
callq 0xb6e8
leaq 0x120(%rsp), %rdi
callq 0xb6e8
leaq 0x100(%rsp), %rdi
callq 0xb6e8
leaq 0xe0(%rsp), %rdi
callq 0xb6e8
testb $0x1, 0xaf(%rsp)
jne 0x19833
jmp 0x1983d
movq 0x20(%rsp), %rdi
callq 0xb2d0
jmp 0x19849
jmp 0x19841
addq $0x288, %rsp            # imm = 0x288
retq
movq 0x258(%rsp), %rdi
callq 0xb680
nopw %cs:(%rax,%rax)