128 lines
2.9 KiB
C
128 lines
2.9 KiB
C
/**
|
|
* Holds the AST model
|
|
*/
|
|
#ifndef AST_H
|
|
#define AST_H
|
|
|
|
#include "bool.h"
|
|
#include "token.h"
|
|
|
|
#include <stddef.h>
|
|
|
|
typedef struct {
|
|
/** @brief The name of the module being imported. */
|
|
char* module_name;
|
|
|
|
/** @brief Whether the import is public or not. */
|
|
bool is_public;
|
|
} ImportDeclaration;
|
|
|
|
typedef enum {
|
|
EXPRESSION_INTEGER,
|
|
EXPRESSION_STRING,
|
|
EXPRESSION_BOOLEAN
|
|
} ExpressionTag;
|
|
|
|
typedef struct {
|
|
ExpressionTag tag;
|
|
union {
|
|
int integer;
|
|
const char* string;
|
|
bool boolean;
|
|
};
|
|
} Expression;
|
|
|
|
typedef enum {
|
|
TYPE_EXPRESSION_BUILTIN,
|
|
TYPE_EXPRESSION_ARRAY
|
|
} TypeExpressionTag;
|
|
|
|
/**
|
|
* An expression that evaluates to a type.
|
|
*/
|
|
typedef struct TypeExpression TypeExpression;
|
|
struct TypeExpression {
|
|
/** @brief defines which entry in the union is valid */
|
|
TypeExpressionTag tag;
|
|
union {
|
|
/** @brief Evaluates to an array of the given type. */
|
|
struct {
|
|
/** @brief A pointer to the type of the elements stored in the array. */
|
|
TypeExpression* array;
|
|
} array;
|
|
/** @brief Evaluates to a builtin integer type.*/
|
|
struct {
|
|
/**
|
|
* @brief The number of bits in the integer.
|
|
* Typical values are 8, 16, 32, and 64.
|
|
*/
|
|
int bitSize;
|
|
/** @brief `true` if the type is signed, `false` if it's unsigned. */
|
|
bool isSigned;
|
|
} builtin;
|
|
};
|
|
};
|
|
|
|
/**
|
|
* A declaration that aliases one type to another.
|
|
*/
|
|
typedef struct {
|
|
/** @brief The name of the alias. */
|
|
const char* name;
|
|
|
|
/** @brief The value of the alias. */
|
|
TypeExpression value;
|
|
} AliasDeclaration;
|
|
|
|
/**
|
|
* A declaration of a variable, which may be a constant or not, and may be static or not.
|
|
*/
|
|
typedef struct {
|
|
/** @brief The name of the variable. */
|
|
char* name;
|
|
|
|
/** @brief The type of the variable. */
|
|
TypeExpression type;
|
|
|
|
/** @brief The optional initializer expression. */
|
|
Expression* initializer;
|
|
|
|
/** @brief Whether the variable is public or not. */
|
|
bool is_public;
|
|
|
|
/** @brief Whether the variable is static or not. */
|
|
bool is_static;
|
|
|
|
/** @brief Whether the variable is a constant or not. */
|
|
bool is_const;
|
|
} VariableDeclaration;
|
|
|
|
/**
|
|
* The top-level model.
|
|
* Every file matches an entire Module.
|
|
*/
|
|
typedef struct {
|
|
/** @brief The name of the module. */
|
|
char* name;
|
|
|
|
/** @brief The list of imports in the module. */
|
|
ImportDeclaration* imports;
|
|
|
|
/** @brief The number of imports in the module. */
|
|
size_t import_count;
|
|
|
|
/** @brief The list of aliases in the module. */
|
|
AliasDeclaration* aliases;
|
|
|
|
/** @brief The number of aliases in the module. */
|
|
size_t alias_count;
|
|
|
|
/** @brief The list of variables in the module. */
|
|
VariableDeclaration* variables;
|
|
|
|
/** @brief The number of variables in the module. */
|
|
size_t variable_count;
|
|
} Module;
|
|
|
|
#endif
|