From 6a32fecab2ccd02493c3345af731bd3c59384603 Mon Sep 17 00:00:00 2001 From: Gigabyte-Giant Date: Sat, 24 Sep 2016 00:19:59 -0500 Subject: [PATCH] Started trying to improve AST - Got rid of all original AST node types - Re-implemented the 'BurstASTNode' type - Re-implemented the 'BurstLiteralExpressionNode' type Originally, when I started this, I was just going to remove the 'BurstValueExpressionNode', however, in my doing so, I found that the AST is designed quite poorly. I still have a lot of work left to do on this; I'm not even sure if the contents of this commit will remain, but it's a start. Signed-off-by: Gigabyte-Giant --- .../Frontend/Parser/AST/Nodes/BurstASTNode.h | 32 +++++----- .../AST/Nodes/BurstArithmeticExpressionNode.h | 48 --------------- .../AST/Nodes/BurstFunctionDeclarationNode.h | 49 --------------- .../AST/Nodes/BurstLiteralExpressionNode.h | 11 +--- .../AST/Nodes/BurstReferenceExpressionNode.h | 43 ------------- .../AST/Nodes/BurstValueExpressionNode.h | 45 -------------- .../AST/Nodes/BurstVariableDeclarationNode.h | 46 -------------- .../Frontend/Parser/AST/Nodes/BurstASTNode.c | 61 +++++++++---------- .../AST/Nodes/BurstArithmeticExpressionNode.c | 56 ----------------- .../AST/Nodes/BurstFunctionDeclarationNode.c | 54 ---------------- .../AST/Nodes/BurstLiteralExpressionNode.c | 4 +- .../AST/Nodes/BurstReferenceExpressionNode.c | 43 ------------- .../AST/Nodes/BurstValueExpressionNode.c | 48 --------------- .../AST/Nodes/BurstVariableDeclarationNode.c | 55 ----------------- 14 files changed, 48 insertions(+), 547 deletions(-) delete mode 100644 Include/Frontend/Parser/AST/Nodes/BurstArithmeticExpressionNode.h delete mode 100644 Include/Frontend/Parser/AST/Nodes/BurstFunctionDeclarationNode.h delete mode 100644 Include/Frontend/Parser/AST/Nodes/BurstReferenceExpressionNode.h delete mode 100644 Include/Frontend/Parser/AST/Nodes/BurstValueExpressionNode.h delete mode 100644 Include/Frontend/Parser/AST/Nodes/BurstVariableDeclarationNode.h delete mode 100644 Source/Frontend/Parser/AST/Nodes/BurstArithmeticExpressionNode.c delete mode 100644 Source/Frontend/Parser/AST/Nodes/BurstFunctionDeclarationNode.c delete mode 100644 Source/Frontend/Parser/AST/Nodes/BurstReferenceExpressionNode.c delete mode 100644 Source/Frontend/Parser/AST/Nodes/BurstValueExpressionNode.c delete mode 100644 Source/Frontend/Parser/AST/Nodes/BurstVariableDeclarationNode.c diff --git a/Include/Frontend/Parser/AST/Nodes/BurstASTNode.h b/Include/Frontend/Parser/AST/Nodes/BurstASTNode.h index 662f2ed..d6d3968 100644 --- a/Include/Frontend/Parser/AST/Nodes/BurstASTNode.h +++ b/Include/Frontend/Parser/AST/Nodes/BurstASTNode.h @@ -10,19 +10,22 @@ #include #include -#include - #include "BurstCommons.h" #include "BurstErrorCodes.h" #include "BurstErrorMessages.h" -#define BURST_VARIABLE_DECLARATION_NODE 0x00 -#define BURST_VALUE_EXPRESSION_NODE 0x01 -#define BURST_LITERAL_EXPRESSION_NODE 0x02 -#define BURST_ARITHMETIC_EXPRESSION_NODE 0x03 -#define BURST_REFERENCE_EXPRESSION_NODE 0x04 -#define BURST_FUNCTION_DECLARATION_NODE 0x05 +#define BURST_AST_GENERIC_NODE 0x00 +#define BURST_AST_LITERAL_EXPRESSION_NODE 0x01 +// The 'BurstASTNode' struct is a generic AST node, designed to store +// information about other AST nodes. +// +// The information contained within this struct, will be the type of AST node +// being contained, as well as a pointer to said AST node. +// +// We take this approach, as it allows us to have one central node that we can +// use to reference other AST nodes with. The usefulness of this will +// [hopefully] become more apparent in the future. struct burstASTNode; typedef struct burstASTNode { @@ -30,19 +33,14 @@ typedef struct burstASTNode void *pNode; } BurstASTNode; -// These are placed below the definition of the 'BurstASTNode' type, because -// there's a chance that one of the following files might require the use of -// that type. -#include "BurstVariableDeclarationNode.h" -#include "BurstValueExpressionNode.h" +// These includes are placed below the definition of the 'BurstASTNode' type, as +// there's a good chance that one of the following files might require the use +// of the aforementioned type. #include "BurstLiteralExpressionNode.h" -#include "BurstArithmeticExpressionNode.h" -#include "BurstReferenceExpressionNode.h" -#include "BurstFunctionDeclarationNode.h" int ast_node_create ( - int astNodeType, // IN + int nodeType, // IN void *pNode, // IN BurstASTNode **ppASTNode // OUT ); diff --git a/Include/Frontend/Parser/AST/Nodes/BurstArithmeticExpressionNode.h b/Include/Frontend/Parser/AST/Nodes/BurstArithmeticExpressionNode.h deleted file mode 100644 index 7b8e7aa..0000000 --- a/Include/Frontend/Parser/AST/Nodes/BurstArithmeticExpressionNode.h +++ /dev/null @@ -1,48 +0,0 @@ -// -// Burst -// Include/Frontend/Parser/AST/Nodes/BurstArithmeticExpressionNode.h -// -#ifndef __BURST_AST_ARITHMETIC_EXPRESSION_NODE_H__ -#define __BURST_AST_ARITHMETIC_EXPRESSION_NODE_H__ - -#include -#include -#include -#include - -#include - -#include "BurstCommons.h" -#include "BurstErrorCodes.h" -#include "BurstErrorMessages.h" - -#include "BurstASTNode.h" - -struct burstArithmeticExpressionNode; -typedef struct burstArithmeticExpressionNode -{ - BurstASTNode *pLeftSide; - BurstASTNode *pRightSide; - - char *pOperator; - - int (*destroy) - ( - struct burstArithmeticExpressionNode *pNode - ); -} BurstArithmeticExpressionNode; - -int arithmetic_expression_node_create -( - BurstASTNode *pExpressionLeft, // IN - BurstASTNode *pExpressionRight, // IN - char *pExpressionOperator, // IN - BurstArithmeticExpressionNode **ppNode // OUT -); - -int arithmetic_expression_node_destroy -( - BurstArithmeticExpressionNode *pNode // IN -); - -#endif \ No newline at end of file diff --git a/Include/Frontend/Parser/AST/Nodes/BurstFunctionDeclarationNode.h b/Include/Frontend/Parser/AST/Nodes/BurstFunctionDeclarationNode.h deleted file mode 100644 index ac0b767..0000000 --- a/Include/Frontend/Parser/AST/Nodes/BurstFunctionDeclarationNode.h +++ /dev/null @@ -1,49 +0,0 @@ -// -// Burst -// Include/Frontend/Parser/AST/Nodes/BurstFunctionDeclarationNode.h -// -#ifndef __BURST_AST_FUNCTION_DECLARATION_NODE_H__ -#define __BURST_AST_FUNCTION_DECLARATION_NODE_H__ - -#include -#include -#include -#include - -#include - -#include "BurstCommons.h" -#include "BurstErrorCodes.h" -#include "BurstErrorMessages.h" - -#include "Frontend/Parser/AST/BurstAST.h" -#include "BurstASTNode.h" - -struct burstFunctionDeclarationNode; -typedef struct burstFunctionDeclarationNode -{ - char *pReturnType; - char *pIdentifier; - - BurstAST *pArgs; - BurstAST *pBody; - - int (*destroy) - ( - struct burstFunctionDeclarationNode *pNode - ); -} BurstFunctionDeclarationNode; - -int function_declaration_node_create -( - char *pFunctionReturnType, // IN - char *pFunctionIdentifier, // IN - BurstFunctionDeclarationNode **ppNode // OUT -); - -int function_declaration_node_destroy -( - BurstFunctionDeclarationNode *pNode // IN -); - -#endif \ No newline at end of file diff --git a/Include/Frontend/Parser/AST/Nodes/BurstLiteralExpressionNode.h b/Include/Frontend/Parser/AST/Nodes/BurstLiteralExpressionNode.h index 7cdfb40..91cdc5c 100644 --- a/Include/Frontend/Parser/AST/Nodes/BurstLiteralExpressionNode.h +++ b/Include/Frontend/Parser/AST/Nodes/BurstLiteralExpressionNode.h @@ -10,8 +10,6 @@ #include #include -#include - #include "BurstCommons.h" #include "BurstErrorCodes.h" #include "BurstErrorMessages.h" @@ -21,14 +19,9 @@ struct burstLiteralExpressionNode; typedef struct burstLiteralExpressionNode { - // TODO: Value Type - + // TODO (Giga): Figure out how to accurately represent different datatypes + // within literal expressions. char *pValueString; - - int (*destroy) - ( - struct burstLiteralExpressionNode *pNode - ); } BurstLiteralExpressionNode; int literal_expression_node_create diff --git a/Include/Frontend/Parser/AST/Nodes/BurstReferenceExpressionNode.h b/Include/Frontend/Parser/AST/Nodes/BurstReferenceExpressionNode.h deleted file mode 100644 index 1e24017..0000000 --- a/Include/Frontend/Parser/AST/Nodes/BurstReferenceExpressionNode.h +++ /dev/null @@ -1,43 +0,0 @@ -// -// Burst -// Include/Frontend/Parser/AST/Nodes/BurstReferenceExpressionNode.h -// -#ifndef __BURST_AST_REFERENCE_EXPRESSION_NODE_H__ -#define __BURST_AST_REFERENCE_EXPRESSION_NODE_H__ - -#include -#include -#include -#include - -#include - -#include "BurstCommons.h" -#include "BurstErrorCodes.h" -#include "BurstErrorMessages.h" - -#include "BurstASTNode.h" - -struct burstReferenceExpressionNode; -typedef struct burstReferenceExpressionNode -{ - char *pIdentifier; - - int (*destroy) - ( - struct burstReferenceExpressionNode *pNode - ); -} BurstReferenceExpressionNode; - -int reference_expression_node_create -( - char *pIdentifier, // IN - BurstReferenceExpressionNode **ppNode // OUT -); - -int reference_expression_node_destroy -( - BurstReferenceExpressionNode *pNode // IN -); - -#endif \ No newline at end of file diff --git a/Include/Frontend/Parser/AST/Nodes/BurstValueExpressionNode.h b/Include/Frontend/Parser/AST/Nodes/BurstValueExpressionNode.h deleted file mode 100644 index f74242e..0000000 --- a/Include/Frontend/Parser/AST/Nodes/BurstValueExpressionNode.h +++ /dev/null @@ -1,45 +0,0 @@ -// -// Burst -// Include/Frontend/Parser/AST/Nodes/BurstValueExpressionNode.h -// -#ifndef __BURST_AST_VALUE_EXPRESSION_NODE_H__ -#define __BURST_AST_VALUE_EXPRESSION_NODE_H__ - -#include -#include -#include -#include - -#include - -#include "BurstCommons.h" -#include "BurstErrorCodes.h" -#include "BurstErrorMessages.h" - -#include "BurstASTNode.h" - -struct burstValueExpressionNode; -typedef struct burstValueExpressionNode -{ - int valueType; - BurstASTNode *pValueNode; - - int (*destroy) - ( - struct burstValueExpressionNode *pNode - ); -} BurstValueExpressionNode; - -int value_expression_node_create -( - int valueType, // IN - BurstASTNode *pValueNode, // IN - BurstValueExpressionNode **ppNode // OUT -); - -int value_expression_node_destroy -( - BurstValueExpressionNode *pNode // IN -); - -#endif \ No newline at end of file diff --git a/Include/Frontend/Parser/AST/Nodes/BurstVariableDeclarationNode.h b/Include/Frontend/Parser/AST/Nodes/BurstVariableDeclarationNode.h deleted file mode 100644 index 75bc5a1..0000000 --- a/Include/Frontend/Parser/AST/Nodes/BurstVariableDeclarationNode.h +++ /dev/null @@ -1,46 +0,0 @@ -// -// Burst -// Include/Frontend/Parser/AST/Nodes/BurstVariableDeclarationNode.h -// -#ifndef __BURST_AST_VARIABLE_DECLARATION_NODE_H__ -#define __BURST_AST_VARIABLE_DECLARATION_NODE_H__ - -#include -#include -#include -#include - -#include - -#include "BurstCommons.h" -#include "BurstErrorCodes.h" -#include "BurstErrorMessages.h" - -#include "BurstASTNode.h" - -struct burstVariableDeclarationNode; -typedef struct burstVariableDeclarationNode -{ - char *pTypeString; // Variable Type - char *pNameString; // Variable Name - BurstASTNode *pValueExpressionNode; // Variable Value Expression - - int (*destroy) - ( - struct burstVariableDeclarationNode *pNode - ); -} BurstVariableDeclarationNode; - -int variable_declaration_node_create -( - char *pVariableType, // IN - char *pVariableName, // IN - BurstVariableDeclarationNode **ppNode // OUT -); - -int variable_declaration_node_destroy -( - BurstVariableDeclarationNode *pNode // IN -); - -#endif \ No newline at end of file diff --git a/Source/Frontend/Parser/AST/Nodes/BurstASTNode.c b/Source/Frontend/Parser/AST/Nodes/BurstASTNode.c index 68cc360..e6fd34d 100644 --- a/Source/Frontend/Parser/AST/Nodes/BurstASTNode.c +++ b/Source/Frontend/Parser/AST/Nodes/BurstASTNode.c @@ -6,7 +6,7 @@ int ast_node_create ( - int astNodeType, + int nodeType, void *pNode, BurstASTNode **ppASTNode ) @@ -20,7 +20,7 @@ int ast_node_create if (NULL == ((*ppASTNode) = (BurstASTNode *) malloc(sizeof(BurstASTNode)))) return BURST_FAIL; - (*ppASTNode)->nodeType = astNodeType; + (*ppASTNode)->nodeType = nodeType; (*ppASTNode)->pNode = pNode; return BURST_SUCCESS; @@ -38,44 +38,41 @@ int ast_node_destroy { switch (pASTNode->nodeType) { - case BURST_VARIABLE_DECLARATION_NODE: - ((BurstVariableDeclarationNode *) pASTNode->pNode)->destroy( - ((BurstVariableDeclarationNode *) pASTNode->pNode) + case BURST_AST_GENERIC_NODE: + { + // If, for some odd reason, the "instance" of the 'BurstASTNode' + // struct that was passed to us, was used to store another + // "instance" of the 'BurstASTNode' struct, we'll call ourself + // again. + ast_node_destroy( + (BurstASTNode *) pASTNode->pNode ); + break; + } - case BURST_VALUE_EXPRESSION_NODE: - ((BurstValueExpressionNode *) pASTNode->pNode)->destroy( - ((BurstValueExpressionNode *) pASTNode->pNode) - ); - break; - - case BURST_LITERAL_EXPRESSION_NODE: - ((BurstLiteralExpressionNode *) pASTNode->pNode)->destroy( - ((BurstLiteralExpressionNode *) pASTNode->pNode) - ); - break; - - case BURST_ARITHMETIC_EXPRESSION_NODE: - ((BurstArithmeticExpressionNode *) pASTNode->pNode)->destroy( - ((BurstArithmeticExpressionNode *) pASTNode->pNode) - ); - break; - - case BURST_REFERENCE_EXPRESSION_NODE: - ((BurstReferenceExpressionNode *) pASTNode->pNode)->destroy( - ((BurstReferenceExpressionNode *) pASTNode->pNode) - ); - break; - - case BURST_FUNCTION_DECLARATION_NODE: - ((BurstFunctionDeclarationNode *) pASTNode->pNode)->destroy( - ((BurstFunctionDeclarationNode *) pASTNode->pNode) + case BURST_AST_LITERAL_EXPRESSION_NODE: + { + literal_expression_node_destroy( + (BurstLiteralExpressionNode *) pASTNode->pNode ); + break; + } default: + { + // If we make it to this point, we apparently don't have any + // idea what type of AST node we're currently trying to + // destroy. + // + // As a result of this, we're going to perform a basic + // 'free'. This may or may not (probably the latter) free all + // of the memory used for this node. + free(pASTNode->pNode); + break; + } } } diff --git a/Source/Frontend/Parser/AST/Nodes/BurstArithmeticExpressionNode.c b/Source/Frontend/Parser/AST/Nodes/BurstArithmeticExpressionNode.c deleted file mode 100644 index e979339..0000000 --- a/Source/Frontend/Parser/AST/Nodes/BurstArithmeticExpressionNode.c +++ /dev/null @@ -1,56 +0,0 @@ -// -// Burst -// Source/Frontend/Parser/AST/Nodes/BurstArithmeticExpressionNode.c -// -#include "Frontend/Parser/AST/Nodes/BurstArithmeticExpressionNode.h" - -int arithmetic_expression_node_create -( - BurstASTNode *pExpressionLeft, - BurstASTNode *pExpressionRight, - char *pExpressionOperator, - BurstArithmeticExpressionNode **ppNode -) -{ - if (NULL != (*ppNode)) - return BURST_FAIL; - - if (NULL == pExpressionLeft || NULL == pExpressionRight) - return BURST_FAIL; - - if (NULL == pExpressionOperator) - return BURST_FAIL; - - (*ppNode) = (BurstArithmeticExpressionNode *) malloc(sizeof( - BurstArithmeticExpressionNode)); - - if (NULL == (*ppNode)) - return BURST_FAIL; - - (*ppNode)->pLeftSide = pExpressionLeft; - (*ppNode)->pRightSide = pExpressionRight; - (*ppNode)->pOperator = pExpressionOperator; - - (*ppNode)->destroy = arithmetic_expression_node_destroy; - - return BURST_SUCCESS; -} - -int arithmetic_expression_node_destroy -( - BurstArithmeticExpressionNode *pNode -) -{ - if (NULL == pNode) - return BURST_FAIL; - - if (NULL != pNode->pLeftSide) - ast_node_destroy(pNode->pLeftSide); - - if (NULL != pNode->pRightSide) - ast_node_destroy(pNode->pRightSide); - - free(pNode); - - return BURST_SUCCESS; -} \ No newline at end of file diff --git a/Source/Frontend/Parser/AST/Nodes/BurstFunctionDeclarationNode.c b/Source/Frontend/Parser/AST/Nodes/BurstFunctionDeclarationNode.c deleted file mode 100644 index 0adf565..0000000 --- a/Source/Frontend/Parser/AST/Nodes/BurstFunctionDeclarationNode.c +++ /dev/null @@ -1,54 +0,0 @@ -// -// Burst -// Source/Frontend/Parser/AST/Nodes/BurstFunctionDeclarationNode.c -// -#include "Frontend/Parser/AST/Nodes/BurstFunctionDeclarationNode.h" - -int function_declaration_node_create -( - char *pFunctionReturnType, - char *pFunctionIdentifier, - BurstFunctionDeclarationNode **ppNode -) -{ - if (NULL == pFunctionReturnType || NULL == pFunctionIdentifier) - return BURST_FAIL; - - if (NULL != (*ppNode)) - return BURST_FAIL; - - (*ppNode) = (BurstFunctionDeclarationNode *) malloc(sizeof( - BurstFunctionDeclarationNode)); - - if (NULL == (*ppNode)) - return BURST_FAIL; - - (*ppNode)->pReturnType = pFunctionReturnType; - (*ppNode)->pIdentifier = pFunctionIdentifier; - - ast_create(&(*ppNode)->pArgs); - ast_create(&(*ppNode)->pBody); - - (*ppNode)->destroy = function_declaration_node_destroy; - - return BURST_SUCCESS; -} - -int function_declaration_node_destroy -( - BurstFunctionDeclarationNode *pNode -) -{ - if (NULL == pNode) - return BURST_FAIL; - - if (NULL != pNode->pArgs) - ast_destroy(pNode->pArgs); - - if (NULL != pNode->pBody) - ast_destroy(pNode->pBody); - - free(pNode); - - return BURST_SUCCESS; -} \ No newline at end of file diff --git a/Source/Frontend/Parser/AST/Nodes/BurstLiteralExpressionNode.c b/Source/Frontend/Parser/AST/Nodes/BurstLiteralExpressionNode.c index b2ca62d..936ab61 100644 --- a/Source/Frontend/Parser/AST/Nodes/BurstLiteralExpressionNode.c +++ b/Source/Frontend/Parser/AST/Nodes/BurstLiteralExpressionNode.c @@ -16,13 +16,13 @@ int literal_expression_node_create (*ppNode) = (BurstLiteralExpressionNode *) malloc(sizeof( BurstLiteralExpressionNode)); + // Error allocating memory for node + // TODO (Giga): Come up with a better way to handle this. if (NULL == (*ppNode)) return BURST_FAIL; (*ppNode)->pValueString = pExpressionValue; - (*ppNode)->destroy = literal_expression_node_destroy; - return BURST_SUCCESS; } diff --git a/Source/Frontend/Parser/AST/Nodes/BurstReferenceExpressionNode.c b/Source/Frontend/Parser/AST/Nodes/BurstReferenceExpressionNode.c deleted file mode 100644 index c0e117c..0000000 --- a/Source/Frontend/Parser/AST/Nodes/BurstReferenceExpressionNode.c +++ /dev/null @@ -1,43 +0,0 @@ -// -// Burst -// Source/Frontend/Parser/AST/Nodes/BurstReferenceExpressionNode.c -// -#include "Frontend/Parser/AST/Nodes/BurstReferenceExpressionNode.h" - -int reference_expression_node_create -( - char *pIdentifier, - BurstReferenceExpressionNode **ppNode -) -{ - if (NULL == pIdentifier) - return BURST_FAIL; - - if (NULL != (*ppNode)) - return BURST_FAIL; - - (*ppNode) = (BurstReferenceExpressionNode *) malloc(sizeof( - BurstReferenceExpressionNode)); - - if (NULL == (*ppNode)) - return BURST_SUCCESS; - - (*ppNode)->pIdentifier = pIdentifier; - - (*ppNode)->destroy = reference_expression_node_destroy; - - return BURST_SUCCESS; -} - -int reference_expression_node_destroy -( - BurstReferenceExpressionNode *pNode -) -{ - if (NULL == pNode) - return BURST_FAIL; - - free(pNode); - - return BURST_SUCCESS; -} \ No newline at end of file diff --git a/Source/Frontend/Parser/AST/Nodes/BurstValueExpressionNode.c b/Source/Frontend/Parser/AST/Nodes/BurstValueExpressionNode.c deleted file mode 100644 index 285f7a0..0000000 --- a/Source/Frontend/Parser/AST/Nodes/BurstValueExpressionNode.c +++ /dev/null @@ -1,48 +0,0 @@ -// -// Burst -// Source/Frontend/Parser/AST/Nodes/BurstValueExpressionNode.c -// -#include "Frontend/Parser/AST/Nodes/BurstValueExpressionNode.h" - -int value_expression_node_create -( - int valueType, - BurstASTNode *pValueNode, - BurstValueExpressionNode **ppNode -) -{ - if (NULL != (*ppNode)) - return BURST_FAIL; - - if (NULL == pValueNode) - return BURST_FAIL; - - (*ppNode) = (BurstValueExpressionNode *) malloc(sizeof( - BurstValueExpressionNode)); - - if (NULL == (*ppNode)) - return BURST_FAIL; - - (*ppNode)->valueType = valueType; - (*ppNode)->pValueNode = pValueNode; - - (*ppNode)->destroy = value_expression_node_destroy; - - return BURST_SUCCESS; -} - -int value_expression_node_destroy -( - BurstValueExpressionNode *pNode -) -{ - if (NULL == pNode) - return BURST_FAIL; - - if (NULL != pNode->pValueNode) - ast_node_destroy(pNode->pValueNode); - - free(pNode); - - return BURST_SUCCESS; -} \ No newline at end of file diff --git a/Source/Frontend/Parser/AST/Nodes/BurstVariableDeclarationNode.c b/Source/Frontend/Parser/AST/Nodes/BurstVariableDeclarationNode.c deleted file mode 100644 index 8e18f48..0000000 --- a/Source/Frontend/Parser/AST/Nodes/BurstVariableDeclarationNode.c +++ /dev/null @@ -1,55 +0,0 @@ -// -// Burst -// Source/Frontend/Parser/AST/Nodes/BurstVariableDeclarationNode.c -// -#include "Frontend/Parser/AST/Nodes/BurstVariableDeclarationNode.h" - -int variable_declaration_node_create -( - char *pVariableType, - char *pVariableName, - BurstVariableDeclarationNode **ppNode -) -{ - if (NULL != (*ppNode)) - return BURST_FAIL; - - if (NULL == pVariableType || NULL == pVariableName) - return BURST_FAIL; - - (*ppNode) = (BurstVariableDeclarationNode *) malloc(sizeof( - BurstVariableDeclarationNode)); - - if (NULL == (*ppNode)) - return BURST_FAIL; - - (*ppNode)->pTypeString = pVariableType; - (*ppNode)->pNameString = pVariableName; - (*ppNode)->pValueExpressionNode = NULL; - - (*ppNode)->destroy = variable_declaration_node_destroy; - - return BURST_SUCCESS; -} - -int variable_declaration_node_destroy -( - BurstVariableDeclarationNode *pNode -) -{ - if (NULL == pNode) - return BURST_FAIL; - - // if (NULL != pNode->pTypeString) - // free(pNode->pTypeString); - - // if (NULL != pNode->pNameString) - // free(pNode->pNameString); - - if (NULL != pNode->pValueExpressionNode) - ast_node_destroy(pNode->pValueExpressionNode); - - free(pNode); - - return BURST_SUCCESS; -} \ No newline at end of file