utility.h
来自「用C++编写的一个编译器」· C头文件 代码 · 共 156 行
H
156 行
#ifndef UTILITY_H
#define UTILITY_H
#include "dccdef.h"
#define ERROR_MAPPER 64
#define ERR_CANTOPEN_FILE 0
#define ERR_UNKNOWN_CHAR 1
#define ERR_UNKNOWN_SIZE 2
#define ERR_SYNTAX_ERROR 3
#define ERR_UNKNOWN_PREPROC_CMD 4
#define ERR_WRONG_PREPROC_CMD 5
#define ERR_UNKNOWN_CONST 6
#define ERR_REDEF_VAR 7
#define ERR_WRONG_BASIC_TYPE 8
#define ERR_REDEF_TYPE 9
#define ERR_TYPE_CONFLICT 10
#define ERR_EXPECT_CONST 11
#define ERR_EXPECT_POSITIVE 12
#define ERR_REDEF_MEMBER 13
#define ERR_STRUCT_VACANT 14
#define ERR_ZERO_SIZE 15
#define ERR_UNKNOWN_ID 16
#define ERR_ARG_NOTMATCH 17
#define ERR_FEW_ARG 18
#define ERR_EXPECT_FUNC 19
#define ERR_EXPECT_POINTER 20
#define ERR_EXPECT_STRUCT 21
#define ERR_NOT_MEMBER 22
#define ERR_EXPECT_INT 23
#define ERR_EXPECT_VAR 24
#define ERR_STORAGE_CLASS 25
#define ERR_REDEF_FUNC 26
#define ERR_DECL_CONFLICT 27
#define ERR_ARRAY_FUNC 28
#define ERR_REDEF_LABEL 29
#define ERR_NOT_LOOP 30
#define ERR_NOT_FOUND 31
#define ERR_DEFAULT_MORE 32
typedef struct _listnode{
struct _listnode *next, *pre;
void *content;
}ListNode;
typedef struct _list{
struct _listnode *head;
struct _listnode *tail;
}List;
typedef struct _node{
struct _node *next;
char *name; //definition name, or type name, or variable name
int code;
void *val;
}HashNode;
typedef struct _memblk{
struct _memblk *next;
int blksize;
int rest; //the rest part measured in bytes
// char mem[4]; //set 4 just to avoid the influence of align
}Memblk;
#define MAX(a, b) ((a)>(b)?(a):(b))
typedef struct _definition
{
char *name;
char *expansion;
int arg_num; //the one less than 0 means it is special macro
uchar *arg_stack; //seems null-terminal string
} Definition;
typedef struct _directory
{
struct _directory *next;
char *path;
} SearchDir;
/**********************************************************************/
//memmgmt.c
#define PAGESIZE 4096
void *dmalloc(int size, bool auto_flag);//if auto is false, use global style
int release_local();
int release_global();
char *newstrcpy(const char *src, int size);
long align_add(long origin, long extra);
/*********************************************************************/
//report.c
extern int error_count, warning_count;
void generror(
int code,
const char *info);
void genwarning(
int code,
const char *info);
int report();
void debug(
const char *info,
...);
/*********************************************************************/
//location.c
//the only one who returns NULL means success
//if conflict occurs, give up to add and return the previous same;
HashNode *add_node(
HashNode **hashtab,
long tabsize,
const char *name,
void *target);
void remove_node(
HashNode **hashtab,
long tabsize,
const char *name);
/*
* Return the pointer to the hashnode, if no return null
*/
HashNode *lookup_node(
HashNode **hashtab,
long tabsize,
const char *name);
//not any check
void push_List(
List *list,
void *target);
void *popfront_List(
List *list);
void *popback_List(List *list);
void insert_List(List *list,
ListNode *lnode,
void *target);
typedef struct _object
{
struct _object *next;
}Object;
void appendObject(void **origin, void *extra);
extern char *currentfile;
extern int lineno;
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?