// File: /workspace/github_cpp_makefile_star2_O2/menhits[P]phplus/src/Parser.cpp
// Function: parseType(std::vector<std::shared_ptr<TokenData>, std::allocator<std::shared_ptr<TokenData>>> const&, int, int)
unique_ptr<AstType> parseType(const vector<Token>& tokens, int left, int right)
{
	vector<AstTupleType::NamedType> types;
	
	while (left<=right)
	{
		//	skip commas
		while (left<=right && tokens[left]->getOp()==ops->comma)
		{
			left++;
		}
		
		//	if this is a named subtype
		if (left+2<=right && tokens[left+1]->getOp()==ops->colon)
		{
			if (tokens[left]->getType()!=TokenData::IDENTIFIER)
			{
				throw PhplusError("identifier must be to the left of ':' in type", SOURCE_ERROR, tokens[left]);
			}
			
			Token name=tokens[left];
			unique_ptr<AstType> type;
			
			if (tokens[left+2]->getType()==TokenData::IDENTIFIER)
			{
				type=AstTokenType::make(tokens[left+2]);
				left+=3;
			}
			else if (tokens[left+2]->getOp()==ops->openCrBrac)
			{
				int j=skipBrace(tokens, left+2);
				
				if (j>right)
				{
					throw PhplusError(FUNC+" skipping brance went outside of range", INTERNAL_ERROR, tokens[left+1]);
				}
				
				type=parseType(tokens, left+2+1, j-1);
				left=j+1;
			}
			else
			{
				throw PhplusError("invalid thingy '"+tokens[left+2]->getText()+"' in type", SOURCE_ERROR, tokens[left+2]);
			}
			
			types.push_back(AstTupleType::NamedType{name, move(type)});
		}
		else //	this is an unnamed subtype
		{
			types.push_back(AstTupleType::NamedType{nullptr, AstTokenType::make(tokens[left])});
			left+=1;
		}
	}
	
	if (types.size()==0)
		return AstVoidType::make();
	else if (types.size()==1 && !types[0].name)
		return move(types[0].type);
	else
		return AstTupleType::make(types);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, 0x58(%rsp)
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %rax
andq $0x0, 0x10(%rax)
movaps %xmm0, (%rax)
movl %ecx, 0xc(%rsp)
movslq %ecx, %rbp
leal 0x1(%rbp), %eax
movl %eax, 0x54(%rsp)
leaq 0x10(%rsp), %r13
cmpl 0xc(%rsp), %r15d
jg 0x213e5
movslq %r15d, %r15
movq %r15, %r12
shlq $0x4, %r12
cmpq %rbp, %r15
jg 0x21187
movq (%r14), %rax
movq (%rax,%r12), %rsi
addq $0x40, %rsi
movq %r13, %rdi
callq 0xc950
leaq 0x59192(%rip), %rax     # 0x7a2f0
movq (%rax), %rax
movq 0x10(%rsp), %rbx
movq 0x50(%rax), %r13
leaq 0x18(%rsp), %rdi
callq 0xc984
cmpq %r13, %rbx
jne 0x21190
incq %r15
addq $0x10, %r12
leaq 0x10(%rsp), %r13
jmp 0x2113f
movl 0x54(%rsp), %eax
movl %eax, %r15d
jmp 0x21195
leaq 0x10(%rsp), %r13
leal 0x2(%r15), %eax
movslq %r15d, %r12
cmpl 0xc(%rsp), %eax
jg 0x211ef
movl %eax, 0x44(%rsp)
movq (%r14), %rax
movq %r12, %rbx
shlq $0x4, %rbx
movq 0x10(%rax,%rbx), %rsi
addq $0x40, %rsi
movq %r13, %rdi
callq 0xc950
leaq 0x59128(%rip), %rax     # 0x7a2f0
movq (%rax), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x48(%rsp)
movq 0x30(%rax), %r13
leaq 0x18(%rsp), %rdi
callq 0xc984
cmpq %r13, 0x48(%rsp)
leaq 0x10(%rsp), %r13
je 0x2126e
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
shlq $0x4, %r12
addq (%r14), %r12
leaq 0xb8(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x12e2e
leaq 0x80(%rsp), %rdi
movq %rbx, %rsi
callq 0x21f8c
movq 0x80(%rsp), %rax
andq $0x0, 0x80(%rsp)
movq %rax, 0x20(%rsp)
leaq 0x60(%rsp), %rdi
movq %r13, %rsi
callq 0x13300
movq %r13, %rdi
callq 0x132e6
leaq 0x80(%rsp), %rdi
callq 0x21fde
leaq 0xc0(%rsp), %rdi
callq 0xc984
incl %r15d
jmp 0x2112a
movq (%r14), %rsi
movq (%rsi,%rbx), %rax
cmpl $0x2, 0x38(%rax)
jne 0x21485
addq %rbx, %rsi
leaq 0xa8(%rsp), %rdi
callq 0x12e2e
andq $0x0, 0x38(%rsp)
movslq 0x44(%rsp), %rcx
movq (%r14), %rsi
shlq $0x4, %rcx
movq (%rsi,%rcx), %rax
cmpl $0x2, 0x38(%rax)
jne 0x212fc
addq %rcx, %rsi
leaq 0xc8(%rsp), %rbx
movq %rbx, %rdi
callq 0x12e2e
movq %r13, %rdi
movq %rbx, %rsi
callq 0x21f8c
movq 0x10(%rsp), %rsi
andq $0x0, 0x10(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x22324
movq %r13, %rdi
callq 0x21fde
leaq 0xd0(%rsp), %rdi
callq 0xc984
addl $0x3, %r15d
jmp 0x21394
movq %rcx, 0x48(%rsp)
movq %rbx, 0xa0(%rsp)
addq $0x40, %rax
movq %r13, %rdi
movq %rax, %rsi
callq 0xc950
leaq 0x58fd1(%rip), %rax     # 0x7a2f0
movq (%rax), %rax
movq 0x10(%rsp), %rbx
movq 0x1d0(%rax), %r12
leaq 0x18(%rsp), %rdi
callq 0xc984
cmpq %r12, %rbx
jne 0x214f4
movq %r14, %rdi
movl 0x44(%rsp), %esi
callq 0x1f29d
movl %eax, %r12d
cmpl 0xc(%rsp), %eax
jg 0x21597
addl $0x3, %r15d
leal -0x1(%r12), %ecx
movq %r13, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x210eb
movq 0x10(%rsp), %rsi
andq $0x0, 0x10(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x22324
movq %r13, %rdi
callq 0x134e8
incl %r12d
movl %r12d, %r15d
movq %r13, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x12e2e
movq 0x38(%rsp), %rax
movq %rax, 0x20(%rsp)
andq $0x0, 0x38(%rsp)
leaq 0x60(%rsp), %rdi
movq %r13, %rsi
callq 0x13300
movq %r13, %rdi
callq 0x132e6
leaq 0x38(%rsp), %rdi
callq 0x134e8
leaq 0xb0(%rsp), %rdi
callq 0xc984
jmp 0x2112a
movq 0x60(%rsp), %rcx
movq 0x68(%rsp), %rax
subq %rcx, %rax
pushq $0x18
popq %rsi
cqto
idivq %rsi
cmpq $0x1, %rax
je 0x2142a
testq %rax, %rax
movq 0x58(%rsp), %rbx
jne 0x21435
leaq 0x10(%rsp), %rdi
callq 0x21f2c
leaq 0x10(%rsp), %rdi
movq (%rdi), %rax
andq $0x0, (%rdi)
movq %rax, (%rbx)
callq 0x21f6a
jmp 0x21458
cmpq $0x0, (%rcx)
movq 0x58(%rsp), %rbx
je 0x21477
leaq 0x10(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x21ff8
leaq 0x10(%rsp), %rdi
movq (%rdi), %rax
andq $0x0, (%rdi)
movq %rax, (%rbx)
callq 0x2204a
leaq 0x60(%rsp), %rdi
callq 0x22064
movq %rbx, %rax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rcx), %rax
movq %rax, (%rbx)
andq $0x0, 0x10(%rcx)
jmp 0x21458
pushq $0x38
popq %rdi
callq 0xa1b0
movq %rax, %r15
leaq 0x341ae(%rip), %rsi     # 0x55645
leaq 0x148(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0xa150
movq %rbx, %rsi
addq (%r14), %rsi
leaq 0xf8(%rsp), %rbx
movq %rbx, %rdi
callq 0x12e2e
movb $0x1, %bpl
leaq 0x148(%rsp), %rsi
movq %r15, %rdi
xorl %edx, %edx
movq %rbx, %rcx
callq 0x19f06
xorl %ebp, %ebp
leaq 0x560b8(%rip), %rsi     # 0x77598
leaq -0xfe55(%rip), %rdx     # 0x11692
movq %r15, %rdi
callq 0xa4e0
jmp 0x21628
pushq $0x38
popq %rdi
callq 0xa1b0
movq %rax, %r15
movq (%r14), %rax
movq 0x48(%rsp), %rcx
movq (%rax,%rcx), %rsi
leaq 0x80(%rsp), %rdi
callq 0xa3b0
leaq 0x34185(%rip), %rsi     # 0x556a4
leaq 0x10(%rsp), %rdi
leaq 0x80(%rsp), %rdx
callq 0x11ff8
leaq 0x34131(%rip), %rdx     # 0x55669
leaq 0x108(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xc882
movq 0x48(%rsp), %rsi
addq (%r14), %rsi
leaq 0xd8(%rsp), %rbx
movq %rbx, %rdi
callq 0x12e2e
movb $0x1, %bpl
leaq 0x108(%rsp), %rsi
movq %r15, %rdi
xorl %edx, %edx
movq %rbx, %rcx
callq 0x19f06
xorl %ebp, %ebp
leaq 0x56015(%rip), %rsi     # 0x77598
leaq -0xfef8(%rip), %rdx     # 0x11692
movq %r15, %rdi
callq 0xa4e0
jmp 0x21628
pushq $0x38
popq %rdi
callq 0xa1b0
movq %rax, %r15
leaq 0x340ca(%rip), %rsi     # 0x55673
leaq 0x10(%rsp), %rdi
leaq 0x80(%rsp), %rdx
callq 0xa150
leaq 0x340bb(%rip), %rdx     # 0x5567d
leaq 0x128(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xc882
movq (%r14), %rax
movq 0xa0(%rsp), %rcx
leaq (%rax,%rcx), %rsi
addq $0x10, %rsi
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
callq 0x12e2e
movb $0x1, %bpl
leaq 0x128(%rsp), %rsi
pushq $0x3
popq %rdx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x19f06
xorl %ebp, %ebp
leaq 0x55f7f(%rip), %rsi     # 0x77598
leaq -0xff8e(%rip), %rdx     # 0x11692
movq %r15, %rdi
callq 0xa4e0
jmp 0x2165b
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0xc984
leaq 0x108(%rsp), %rdi
callq 0xa558
jmp 0x2164f
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x10(%rsp), %rdi
callq 0xa558
jmp 0x21695
movq %rax, %rbx
jmp 0x21766
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0xc984
leaq 0x128(%rsp), %rdi
callq 0xa558
jmp 0x21688
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x10(%rsp), %rdi
jmp 0x2169d
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x80(%rsp), %rdi
callq 0xa558
testb %bpl, %bpl
jne 0x216ae
jmp 0x21712
jmp 0x216ab
movq %rax, %rbx
movq %r15, %rdi
callq 0xa230
jmp 0x21712
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0xc984
leaq 0x148(%rsp), %rdi
callq 0xa558
testb %bpl, %bpl
jne 0x216e2
jmp 0x21766
movq %rax, %rbx
movq %r15, %rdi
callq 0xa230
jmp 0x21766
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0xc984
jmp 0x21712
jmp 0x21700
movq %rax, %rbx
jmp 0x21712
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x132e6
leaq 0x38(%rsp), %rdi
callq 0x134e8
leaq 0xb0(%rsp), %rdi
jmp 0x21761
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x132e6
leaq 0x80(%rsp), %rdi
callq 0x21fde
xorl %ebp, %ebp
jmp 0x2174a
movq %rax, %rbx
movb $0x1, %bpl
leaq 0xc0(%rsp), %rdi
callq 0xc984
testb %bpl, %bpl
je 0x21766
leaq 0x18(%rsp), %rdi
callq 0xc984
leaq 0x60(%rsp), %rdi
callq 0x22064
movq %rbx, %rdi
callq 0xa500