// File: /workspace/github_c_makefile_star2_O2/anuwu[P]ERPLAG-Compiler/typeChecker.c
// Function: getExpressionType
tokenID getExpressionType (moduleST *baseModule, astNode *exprNode)
{
	if (exprNode->child == NULL || exprNode->child->next == NULL)	// constant value, integer, or array[index]
	{
		if (exprNode->id != TK_ID)
		{
			if (exprNode->id == TK_NUM)
				return TK_INTEGER ;
			else if (exprNode->id == TK_RNUM)
			{
				realPresent = 1 ;
				return TK_REAL ;
			}
			else
				return TK_BOOLEAN ;
		}
		else
			return validateVar (baseModule, exprNode, NULL) ;
	}
	else
	{
		tokenID typeLeft , typeRight ;
		typeLeft = getExpressionType (baseModule, exprNode->child) ;
		typeRight = getExpressionType (baseModule, exprNode->child->next) ;

		if (typeLeft == TK_ARRAY || typeRight == TK_ARRAY)
		{
			errSemantic () ;
			#ifdef _WIN64
				printf ("In module \"%s\" at line %d, array variable(s) \"%s\" and \"%s\" cannot occur in an expression\n", getParentModuleName (baseModule), exprNode->tok->lineNumber, exprNode->child->tok->lexeme, exprNode->child->next->tok->lexeme) ;
			#endif
			#if defined __linux__ || defined __MACH__
				printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", " ANSI_BOLD ANSI_BLACK "array" ANSI_RESET " variable(s) " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " and " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " cannot occur in an expression\n", getParentModuleName (baseModule), exprNode->tok->lineNumber, exprNode->child->tok->lexeme, exprNode->child->next->tok->lexeme) ;
			#endif
			return (tokenID)0 ;
		}

		if (!typeLeft || !typeRight)
			return (tokenID)0 ;
		else if (typeLeft != typeRight)
		{
			errSemantic () ;
			#ifdef _WIN64
				printf ("In module \"%s\" at line %d, the operator \"%s\" is not allowed between types \"%s\" and \"%s\" respectively\n", getParentModuleName (baseModule), exprNode->tok->lineNumber,  exprNode->tok->lexeme, typeIDToString(typeLeft), typeIDToString(typeRight)) ;
			#endif
			#if defined __linux__ || defined __MACH__
				printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", the operator " ANSI_BOLD ANSI_CYAN "%s" ANSI_RESET " is not allowed between types " ANSI_BOLD ANSI_GREEN "%s" ANSI_RESET " and " ANSI_BOLD ANSI_GREEN "%s" ANSI_RESET " respectively\n", getParentModuleName (baseModule), exprNode->tok->lineNumber,  exprNode->tok->lexeme, typeIDToString(typeLeft), typeIDToString(typeRight)) ;
			#endif
			return (tokenID)0 ;
		}
		else
		{
			if (isArithmeticType(typeLeft) && isArithmeticOp (exprNode->id))
				return typeLeft ;
			else if (isArithmeticType(typeLeft) && isRelationalOp(exprNode->id))
				return TK_BOOLEAN ;
			else if (typeLeft == TK_BOOLEAN && isLogicalOp(exprNode->id))
				return typeLeft ;
			else
			{
				errSemantic () ;
				#ifdef _WIN64
					printf ("In module \"%s\" at line %d, the operator \"%s\" cannot be executed between two operands of type \"%s\"\n", getParentModuleName (baseModule), exprNode->tok->lineNumber, exprNode->tok->lexeme, typeIDToString(typeLeft)) ;
				#endif
				#if defined __linux__ || defined __MACH__
					printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", the operator " ANSI_BOLD ANSI_CYAN "%s" ANSI_RESET " cannot be executed between two operands of type " ANSI_BOLD ANSI_GREEN "%s" ANSI_RESET "\n", getParentModuleName (baseModule), exprNode->tok->lineNumber, exprNode->tok->lexeme, typeIDToString(typeLeft)) ;
				#endif
				realBase->semanticError = 1 ;
				return (tokenID)0 ;
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %r15
movq 0x30(%rsi), %rsi
testq %rsi, %rsi
je 0xd125
cmpq $0x0, 0x38(%rsi)
je 0xd125
movq %r15, %rdi
callq 0xd08f
movl %eax, %r12d
movq 0x30(%r14), %rax
movq 0x38(%rax), %rsi
movq %r15, %rdi
callq 0xd08f
cmpl $0x3b, %r12d
je 0xd14f
movl %eax, %r13d
cmpl $0x3b, %eax
je 0xd14f
xorl %ebx, %ebx
testl %r12d, %r12d
je 0xd279
testl %r13d, %r13d
je 0xd279
cmpl %r13d, %r12d
jne 0xd1b7
leal -0x39(%r12), %eax
cmpl $-0x2, %eax
jae 0xd20b
cmpl $0x39, %r12d
jne 0xd21e
movl (%r14), %eax
andl $-0x2, %eax
cmpl $0x4e, %eax
jne 0xd21e
jmp 0xd276
movl (%r14), %eax
cmpl $0x40, %eax
je 0xd19c
cmpl $0x71, %eax
je 0xd195
cmpl $0x72, %eax
jne 0xd276
leaq 0x22ed2(%rip), %rax     # 0x30014
movl $0x1, (%rax)
pushq $0x38
jmp 0xd278
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xd671
movq %r15, %rdi
callq 0xb395
movq 0x8(%r14), %rcx
movq 0x30(%r14), %rsi
movl 0x10(%rcx), %edx
movq 0x8(%rsi), %rcx
movq 0x38(%rsi), %rsi
movq 0x8(%rcx), %rcx
movq 0x8(%rsi), %rsi
movq 0x8(%rsi), %r8
leaq 0x50c3(%rip), %rdi      # 0x12249
movq %rax, %rsi
xorl %eax, %eax
callq 0x10b0
jmp 0xd279
pushq $0x37
jmp 0xd278
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xced0
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xd671
movq %r15, %rdi
callq 0xb395
movq %rax, -0x30(%rbp)
movq 0x8(%r14), %rax
movl 0x10(%rax), %r14d
movq 0x8(%rax), %r15
movl %r12d, %edi
callq 0xbb77
movq %rax, %r12
movl %r13d, %edi
callq 0xbb77
leaq 0x50e7(%rip), %rdi      # 0x122d9
movq -0x30(%rbp), %rsi
movl %r14d, %edx
movq %r15, %rcx
movq %r12, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x10b0
jmp 0xd279
movl (%r14), %eax
leal -0x5b(%rax), %ecx
cmpl $-0x5, %ecx
ja 0xd28a
addl $-0x61, %eax
cmpl $-0x6, %eax
jae 0xd276
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xd671
movq %r15, %rdi
callq 0xb395
movq %rax, %r15
movq 0x8(%r14), %rax
movl 0x10(%rax), %r14d
movq 0x8(%rax), %r13
movl %r12d, %edi
callq 0xbb77
leaq 0x5126(%rip), %rdi      # 0x12373
movq %r15, %rsi
movl %r14d, %edx
movq %r13, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x10b0
leaq 0x22db1(%rip), %rax     # 0x30018
movq (%rax), %rax
movl $0x1, 0xd8(%rax)
jmp 0xd279
pushq $0x39
popq %rbx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r12d, %ebx
jmp 0xd279