~groovestomp/c-parser

770051d0da79a556ec1d8472592585db79340210 — Aaron Oman 2 years ago 60559b3
Clean up parse tree naming
4 files changed, 16 insertions(+), 18 deletions(-)

M src/lexer.c
R src/{tree.c => parse_tree.c}
M src/parser.c
M src/test.c
M src/lexer.c => src/lexer.c +1 -3
@@ 3,8 3,6 @@

#include "gs.h"

#define ArraySize(Array) (sizeof((Array)) / sizeof((Array)[0]))

/* GCC-specific defines that let us remove compiler size warnings below. */
#if __LP64__
#define CastSizeIntTo32Bits(x) (int)(x)


@@ 446,7 444,7 @@ bool GetKeyword(struct tokenizer *Tokenizer, struct token *Token) {
                "union", "unsigned", "void", "volatile", "while"
        };

        for (int i = 0; i < ArraySize(Keywords); ++i) {
        for (int i = 0; i < GSArraySize(Keywords); ++i) {
                if (GSStringIsEqual(Tokenizer->At, Keywords[i], GSStringLength(Keywords[i]))) {
                        CopyToTokenAndAdvance(Tokenizer, Token, GSStringLength(Keywords[i]), Token_Keyword);


R src/tree.c => src/parse_tree.c +11 -11
@@ 1,5 1,5 @@
#ifndef TREE
#define TREE
#ifndef PARSE_TREE
#define PARSE_TREE

#include <stdint.h>
#include <errno.h>


@@ 36,12 36,12 @@ void ParseTreeSet(parse_tree_node *Self, char *Name, token Token);
void ParseTreeNewChildren(parse_tree_node *Self, u32 Count);
void ParseTreePrint(parse_tree_node *Self, u32 IndentLevel, u32 IndentIncrement);

parse_tree_node *__tree_Alloc(parse_tree_allocator Allocator) {
parse_tree_node *__ParseTree_Alloc(parse_tree_allocator Allocator) {
        parse_tree_node *Node = (parse_tree_node *)Allocator.Alloc(sizeof(*Node));
        return Node;
}

void __tree_Init(parse_tree_node *Node, parse_tree_allocator Allocator) {
void __ParseTree_Init(parse_tree_node *Node, parse_tree_allocator Allocator) {
        Node->Allocator = Allocator;

        Node->Token.Text = NULL;


@@ 60,8 60,8 @@ void __tree_Init(parse_tree_node *Node, parse_tree_allocator Allocator) {
}

parse_tree_node *ParseTreeInit(parse_tree_allocator Allocator) {
        parse_tree_node *Node = __tree_Alloc(Allocator);
        __tree_Init(Node, Allocator);
        parse_tree_node *Node = __ParseTree_Alloc(Allocator);
        __ParseTree_Init(Node, Allocator);
        return Node;
}



@@ 91,7 91,7 @@ void ParseTreeSet(parse_tree_node *Self, char *Name, token Token) {
        ParseTreeSetToken(Self, Token);
}

void __tree_AddChild(parse_tree_node *Self, char *Name) {
void __ParseTree_AddChild(parse_tree_node *Self, char *Name) {
        u32 NameLength = GSStringLength(Name);
        u32 AllocCount = DEFAULT_ALLOC_COUNT;



@@ 107,7 107,7 @@ void __tree_AddChild(parse_tree_node *Self, char *Name) {
                }
                Self->Capacity = AllocCount;
                for (int i=0; i<AllocCount; i++) {
                        __tree_Init(&Self->Children[i], Self->Allocator);
                        __ParseTree_Init(&Self->Children[i], Self->Allocator);
                }
        } else if (Self->Capacity <= Self->NumChildren) {
                if (Self->Capacity > 0) {


@@ 123,7 123,7 @@ void __tree_AddChild(parse_tree_node *Self, char *Name) {
                        }
                        Self->Capacity = AllocCount;
                        for (int i=Self->NumChildren; i<AllocCount; i++) {
                                __tree_Init(&Self->Children[i], Self->Allocator);
                                __ParseTree_Init(&Self->Children[i], Self->Allocator);
                        }
                }
        }


@@ 134,7 134,7 @@ void __tree_AddChild(parse_tree_node *Self, char *Name) {

void ParseTreeNewChildren(parse_tree_node *Self, u32 Count) {
        for (int i=0; i<Count; i++) {
                __tree_AddChild(Self, "Empty");
                __ParseTree_AddChild(Self, "Empty");
        }
}



@@ 186,4 186,4 @@ void ParseTreePrint(parse_tree_node *Self, u32 IndentLevel, u32 IndentIncrement)
        }
}

#endif // TREE
#endif // PARSE_TREE

M src/parser.c => src/parser.c +3 -3
@@ 4,7 4,7 @@
#include <stdio.h>
#include "gs.h"
#include "lexer.c"
#include "tree.c"
#include "parse_tree.c"

void __Parser_ParseTreeUpdate(parse_tree_node *ParseTree, char *Name, u32 NumChildren) {
        ParseTreeSetName(ParseTree, Name);


@@ 2645,7 2645,7 @@ bool ParseTypeSpecifier(struct tokenizer *Tokenizer, parse_tree_node *ParseTree)
        struct token Token = GetToken(Tokenizer);
        if(Token.Type == Token_Keyword)
        {
                for(int Index = 0; Index < ArraySize(Keywords); Index++)
                for(int Index = 0; Index < GSArraySize(Keywords); Index++)
                {
                        if(GSStringIsEqual(Token.Text, Keywords[Index], Token.TextLength))
                        {


@@ 2690,7 2690,7 @@ bool ParseStorageClassSpecifier(struct tokenizer *Tokenizer, parse_tree_node *Pa
        struct token Token = GetToken(Tokenizer);
        if(Token.Type == Token_Keyword)
        {
                for(int Index = 0; Index < ArraySize(Keywords); Index++)
                for(int Index = 0; Index < GSArraySize(Keywords); Index++)
                {
                        if(GSStringIsEqual(Token.Text, Keywords[Index], Token.TextLength))
                        {

M src/test.c => src/test.c +1 -1
@@ 6,7 6,7 @@
#include "gstest.h"
#include "lexer.c"
#include "parser.c"
#include "tree.c"
#include "parse_tree.c"

typedef gs_bool (*parser_function)(struct tokenizer *, parse_tree_node *);