1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <inttypes.h>

#include "comment.h"
#include <utils/str.h>

static struct Str comment;

void
commentClear(void)
{
    clearStr(&comment);
}

void
commentAddExpr(const struct Expr *expr)
{
    if (expr) {
        appendCStrToStr(&comment, strExpr(expr));
    }
}

void
commentAddCStr(const char *str)
{
    appendCStrToStr(&comment, str);
}

void
commentAddLiteral(uint64_t val)
{
    char s[30];
    snprintf(s, 30, "%" PRIu64, val);
    appendCStrToStr(&comment, s);
}

void
commentAddCurrentToken(void)
{
    if (token.kind == EOL) {
        return;
    }

    appendStrToStr(&comment, &token.val);

    if ((MNEMONIC_FIRST != MNEMONIC_END && token.kind >= MNEMONIC_FIRST &&
         token.kind < MNEMONIC_END) ||
        (token.kind >= DIRECTIVE_FIRST && token.kind < DIRECTIVE_END) ||
        token.kind == COMMA)
    {
        appendCharToStr(&comment, ' ');
    }
}

const char *
commentGetCStr(void)
{
    return comment.cstr;
}