larpcc/sema.h
2026-10-09 02:57:39 +02:00

85 lines
1.4 KiB
C

#ifndef SEMA_H
#define SEMA_H
#include "ast.h"
#include "collection.h"
#include <stddef.h>
#include <stdio.h>
typedef enum {
Type_None,
Type_Int,
Type_Char,
Type_Float,
Type_Double,
Type_Bool,
Type_Void,
Type_Pointer,
Type_Function,
} TypeTy;
typedef enum {
TypeSpec_Const = 1 << 0,
TypeSpec_Short = 1 << 1,
TypeSpec_Long = 1 << 2,
TypeSpec_Long2 = 1 << 3,
TypeSpec_Unsigned = 1 << 4,
} TypeSpec;
typedef struct Type Type;
struct Type {
TypeTy ty;
TypeSpec spec;
union {
struct {
Type* inner;
TypeSpec spec;
} pointer;
struct {
Type* return_type;
ARRAY_FIELD(Type*, params);
} function;
};
};
void type_print(FILE* file, const Type* type);
typedef enum {
Sym_Declar,
Sym_Param,
} SymTy;
typedef struct {
SymTy ty;
union {
struct {
Type* type;
} declar;
struct {
Type* type;
size_t idx;
} param;
};
} Sym;
typedef struct {
int _;
} LabelSym;
typedef struct Sema Sema;
Sema* sema_new(void);
void sema_free(Sema* s);
void sema_scope_enter(Sema* s);
void sema_scope_leave(Sema* s);
void sema_function_enter(Sema* s, AstSpec spec, AstDeclar* declar);
void sema_function_leave(Sema* s);
void sema_visit_stmt(Sema* s, AstStmt* stmt);
void sema_visit_expr(Sema* s, AstExpr* expr);
#endif