-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype.c
50 lines (43 loc) · 1.32 KB
/
type.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*************************************************************************
* File Name: type.c
* Author: Li Peng
* Mail: [email protected]
* Created Time: 2013-11-08 16:13:38
* Description:
************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "include/token.h"
#include "include/tag.h"
#include "include/global.h"
#define isequal(p1,p2) \
((p1->tag == p2->tag) && \
(p1->detail.type.width == p2->detail.type.width) && \
!strcmp(p1->detail.type.name,p2->detail.type.name))
var_type Type(char* s,int t,int w){
var_type v = (var_type)malloc(sizeof(struct _token));
v->tag = t;
v->detail.type.width = w;
v->detail.type.name = (char*)malloc(strlen(s) + 1);
strcpy(v->detail.type.name,s);
return v;
}
/*
static int isequal(var_type p1,var_type p2){
return (p1->tag == p2->tag) && (p1->width == p2->width) && !strcmp(p1->name,p2->name);
}
*/
static int isnumeric(var_type p){
return isequal(p,TYPE_CHAR) || isequal(p,TYPE_INT) || isequal(p,TYPE_FLOAT);
}
var_type max(var_type p1,var_type p2){
if(!isnumeric(p1) || !isnumeric(p2))
return NULL;
else if(isequal(p1,TYPE_FLOAT) || isequal(p2,TYPE_FLOAT))
return TYPE_FLOAT;
else if(isequal(p1,TYPE_INT) || isequal(p2,TYPE_INT))
return TYPE_INT;
else
return TYPE_CHAR;
}