Files
corelang/decl.h
2022-04-29 23:28:41 +02:00

129 lines
2.1 KiB
C

#pragma once
typedef struct Note Note;
typedef struct Decl Decl;
typedef struct Decl_Enum_Child Decl_Enum_Child;
typedef enum Decl_Kind{
DK_None,
DK_Variable,
DK_Typedef,
DK_Struct,
DK_Union,
DK_Enum,
DK_Function,
}Decl_Kind;
struct Note{
Intern_String string;
Token *token;
Expr *expr;
Note *next;
Note *first;
Note *last;
};
struct Decl_Enum_Child{
Decl_Enum_Child *next;
Token *token; // name
Expr *expr;
};
struct Decl{
Decl_Kind kind;
Decl *next;
Intern_String name;
Token *token;
Note *first_note;
Note *last_note;
union{
struct{
Decl_Enum_Child *first;
Decl_Enum_Child *last;
} enum_val;
struct{
Decl *first;
Decl *last;
} aggregate_val;
struct{
Decl *first;
Decl *last;
Type *return_type;
}func_val;
struct{
Type *type;
Expr *expr;
}var_val;
struct{
Type *type;
}typedef_val;
};
};
//-----------------------------------------------------------------------------
// Idea
//-----------------------------------------------------------------------------
typedef struct AST_Node AST_Node;
typedef enum AST_Kind{
AK_None,
AK_Undefined,
AK_BaseType,
AK_Typedef,
AK_Pointer,
AK_Struct,
AK_Union,
AK_Array,
AK_Function,
AK_Variable,
AK_EnumChild,
}AST_Kind;
struct AST_Node{
AST_Kind kind;
Intern_String name;
Expr *expr;
Token *pos;
AST_Node *next;
AST_Node *first_note;
AST_Node *last_note;
union{
AST_Node *pointer;
struct{
SizeU size;
}base_type_val;
struct{
AST_Node *type;
}typedef_val;
struct{
AST_Node *return_type;
AST_Node *first;
AST_Node *last;
}func_val;
struct{
AST_Node *first;
AST_Node *last;
}aggregate;
struct{
AST_Node *first;
AST_Node *last;
}enum_val;
};
};
// Then I can yoink the entire idea of a symbol
// cause AST_Node is THE symbol
typedef struct Scope{
Scope *next;
AST_Node *first;
AST_Node *last;
}Scope;
{
Scope *first;
Scope *last;
}
scope_pop(Parser *p)