forked from galaxy-lang/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modularization): modules for freeTokens and getTokenTypeName
- Loading branch information
Showing
5 changed files
with
34 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef FREE_TOKENS_H | ||
#define FREE_TOKENS_H | ||
|
||
#include "frontend/lexer/core.h" | ||
|
||
void freeTokens(Token *tokens, int tokenCount); | ||
|
||
#endif // FREE_TOKENS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <stdlib.h> | ||
#include "frontend/lexer/core.h" | ||
|
||
/** | ||
* @brief Frees the memory allocated for an array of tokens. | ||
* | ||
* This function frees both the `lexeme` and `message` strings of each token, as well as the | ||
* memory allocated for the array of tokens itself. It helps prevent memory leaks after token | ||
* processing is complete. | ||
* | ||
* @param tokens The array of tokens to be freed. | ||
* @param tokenCount The number of tokens in the array. | ||
*/ | ||
void freeTokens(Token *tokens, int tokenCount) { | ||
if (tokens != NULL) { | ||
for (int i = 0; i < tokenCount; i++) { | ||
free(tokens[i].lexeme); | ||
free(tokens[i].message); | ||
} | ||
free(tokens); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters