177 lines
3.1 KiB
C
177 lines
3.1 KiB
C
#ifndef WRAITH_AST_H
|
|
#define WRAITH_AST_H
|
|
|
|
#include <stdint.h>
|
|
|
|
typedef enum
|
|
{
|
|
AccessExpression,
|
|
Assignment,
|
|
BinaryExpression,
|
|
Comment,
|
|
CustomTypeNode,
|
|
Declaration,
|
|
DeclarationSequence,
|
|
Expression,
|
|
ForLoop,
|
|
FunctionArgumentSequence,
|
|
FunctionCallExpression,
|
|
FunctionDeclaration,
|
|
FunctionModifiers,
|
|
FunctionSignature,
|
|
FunctionSignatureArguments,
|
|
Identifier,
|
|
Number,
|
|
PrimitiveTypeNode,
|
|
ReferenceTypeNode,
|
|
Return,
|
|
ReturnVoid,
|
|
StatementSequence,
|
|
StaticModifier,
|
|
StringLiteral,
|
|
StructDeclaration,
|
|
Type,
|
|
UnaryExpression
|
|
} SyntaxKind;
|
|
|
|
typedef enum
|
|
{
|
|
Negate
|
|
} UnaryOperator;
|
|
|
|
typedef enum
|
|
{
|
|
Add,
|
|
Subtract,
|
|
Multiply
|
|
} BinaryOperator;
|
|
|
|
typedef enum
|
|
{
|
|
Void,
|
|
Bool,
|
|
Int,
|
|
UInt,
|
|
Float,
|
|
Double,
|
|
String
|
|
} PrimitiveType;
|
|
|
|
typedef union
|
|
{
|
|
UnaryOperator unaryOperator;
|
|
BinaryOperator binaryOperator;
|
|
} Operator;
|
|
|
|
typedef struct Node
|
|
{
|
|
SyntaxKind syntaxKind;
|
|
struct Node **children;
|
|
uint32_t childCount;
|
|
union
|
|
{
|
|
UnaryOperator unaryOperator;
|
|
BinaryOperator binaryOperator;
|
|
} operator;
|
|
union
|
|
{
|
|
char *string;
|
|
uint64_t number;
|
|
} value;
|
|
PrimitiveType primitiveType;
|
|
} Node;
|
|
|
|
char* strdup (const char* s);
|
|
const char* SyntaxKindString(SyntaxKind syntaxKind);
|
|
|
|
uint8_t IsPrimitiveType(Node *typeNode);
|
|
Node* MakePrimitiveTypeNode(
|
|
PrimitiveType type
|
|
);
|
|
Node* MakeCustomTypeNode(
|
|
char *string
|
|
);
|
|
Node* MakeReferenceTypeNode(
|
|
Node *typeNode
|
|
);
|
|
Node* MakeTypeNode(
|
|
Node *typeNode /* can be primitive, custom, or reference */
|
|
);
|
|
Node* MakeIdentifierNode(
|
|
const char *id
|
|
);
|
|
Node* MakeNumberNode(
|
|
const char *numberString
|
|
);
|
|
Node* MakeStringNode(
|
|
const char *string
|
|
);
|
|
Node* MakeStaticNode();
|
|
Node* MakeFunctionModifiersNode(
|
|
Node **pModifierNodes,
|
|
uint32_t modifierCount
|
|
);
|
|
Node* MakeUnaryNode(
|
|
UnaryOperator operator,
|
|
Node *child
|
|
);
|
|
Node* MakeBinaryNode(
|
|
BinaryOperator operator,
|
|
Node *left,
|
|
Node *right
|
|
);
|
|
Node* MakeDeclarationNode(
|
|
Node* typeNode,
|
|
Node* identifierNode
|
|
);
|
|
Node* MakeAssignmentNode(
|
|
Node *left,
|
|
Node *right
|
|
);
|
|
Node* MakeStatementSequenceNode(
|
|
Node** pNodes,
|
|
uint32_t nodeCount
|
|
);
|
|
Node* MakeReturnStatementNode(
|
|
Node *expressionNode
|
|
);
|
|
Node* MakeReturnVoidStatementNode();
|
|
Node* MakeFunctionSignatureArgumentsNode(
|
|
Node **pArgumentNodes,
|
|
uint32_t argumentCount
|
|
);
|
|
Node* MakeFunctionSignatureNode(
|
|
Node *identifierNode,
|
|
Node* typeNode,
|
|
Node* arguments,
|
|
Node* modifiersNode
|
|
);
|
|
Node* MakeFunctionDeclarationNode(
|
|
Node* functionSignatureNode,
|
|
Node* functionBodyNode
|
|
);
|
|
Node* MakeStructDeclarationNode(
|
|
Node *identifierNode,
|
|
Node *declarationSequenceNode
|
|
);
|
|
Node* MakeDeclarationSequenceNode(
|
|
Node **pNodes,
|
|
uint32_t nodeCount
|
|
);
|
|
Node *MakeFunctionArgumentSequenceNode(
|
|
Node **pArgumentNodes,
|
|
uint32_t argumentCount
|
|
);
|
|
Node* MakeFunctionCallExpressionNode(
|
|
Node *identifierNode,
|
|
Node *argumentSequenceNode
|
|
);
|
|
Node* MakeAccessExpressionNode(
|
|
Node *accessee,
|
|
Node *accessor
|
|
);
|
|
|
|
void PrintTree(Node *node, uint32_t tabCount);
|
|
|
|
#endif /* WRAITH_AST_H */
|