freeSolsToken()

This commit is contained in:
2026-02-05 20:22:25 +11:00
parent 6cd9e6764c
commit d5692369d4
2 changed files with 18 additions and 0 deletions

View File

@@ -46,3 +46,18 @@ ResultType(SolsToken, charptr) createSolsToken(SolsTokenType type, ...) {
va_end(args);
return Success(SolsToken, charptr, token);
}
void freeSolsToken(SolsToken* token) {
if (token->type == STT_IDENTIFIER && token->as.idName != NULL) {
free(token->as.idName);
}
if (token->type == STT_KW_GROUND && token->as.inlineGround != NULL) {
free(token->as.inlineGround);
}
if (token->type == STT_LITERAL) {
freeSolsLiteral(&token->as.literal);
}
if (token->type == STT_TYPE) {
freeSolsType(&token->as.type);
}
}

View File

@@ -37,6 +37,9 @@ Result(SolsToken, charptr);
// the token holds. See the SolsToken struct for more information.
ResultType(SolsToken, charptr) createSolsToken(SolsTokenType type, ...);
// Frees a SolsToken, specifically the .as field elements.
void freeSolsToken(SolsToken* token);
// Represents a Solstice program, seperated into tokens.
// .at is a pointer to the tokens
// .count is how many tokens are currently being stored