C-sparse
view release on metacpan or search on metacpan
src/sparse-0.4.4/parse.c view on Meta::CPAN
#include "expand.c"
#include "inline.c"
#include "linearize.c"
#include "allocate.c"
#include "ptrlist.c"
#include "flow.c"
#include "cse.c"
#include "simplify.c"
#include "memops.c"
#include "liveness.c"
#include "storage.c"
#include "unssa.c"
#include "dissect.c"
#include "target.c"
#include "show-parse.c"
#include "char.c"
#include "sort.c"
#include "compat-linux.c"
#endif
#ifndef DO_CTX
static struct symbol_list **function_symbol_list;
struct symbol_list *function_computed_target_list;
struct statement_list *function_computed_goto_list;
#endif
static struct token *statement(SCTX_ struct token *token, struct statement **tree);
static struct token *handle_attributes(SCTX_ struct token *token, struct decl_state *ctx, unsigned int keywords);
typedef struct token *declarator_t(SCTX_ struct token *, struct decl_state *);
static declarator_t
struct_specifier, union_specifier, enum_specifier,
attribute_specifier, typeof_specifier, parse_asm_declarator,
typedef_specifier, inline_specifier, auto_specifier,
register_specifier, static_specifier, extern_specifier,
thread_specifier, const_qualifier, volatile_qualifier;
static struct token *parse_if_statement(SCTX_ struct token *token, struct statement *stmt);
static struct token *parse_return_statement(SCTX_ struct token *token, struct statement *stmt);
static struct token *parse_loop_iterator(SCTX_ struct token *token, struct statement *stmt);
static struct token *parse_default_statement(SCTX_ struct token *token, struct statement *stmt);
static struct token *parse_case_statement(SCTX_ struct token *token, struct statement *stmt);
static struct token *parse_switch_statement(SCTX_ struct token *token, struct statement *stmt);
static struct token *parse_for_statement(SCTX_ struct token *token, struct statement *stmt);
static struct token *parse_while_statement(SCTX_ struct token *token, struct statement *stmt);
static struct token *parse_do_statement(SCTX_ struct token *token, struct statement *stmt);
static struct token *parse_goto_statement(SCTX_ struct token *token, struct statement *stmt);
static struct token *parse_context_statement(SCTX_ struct token *token, struct statement *stmt);
static struct token *parse_range_statement(SCTX_ struct token *token, struct statement *stmt);
static struct token *parse_asm_statement(SCTX_ struct token *token, struct statement *stmt);
static struct token *toplevel_asm_declaration(SCTX_ struct token *token, struct symbol_list **list);
typedef struct token *attr_t(SCTX_
struct token *, struct symbol *,
struct decl_state *);
static attr_t
attribute_packed, attribute_aligned, attribute_modifier,
attribute_address_space, attribute_context,
attribute_designated_init,
attribute_transparent_union, ignore_attribute,
attribute_mode, attribute_force;
typedef struct symbol *to_mode_t(SCTX_ struct symbol *);
static to_mode_t
to_QI_mode, to_HI_mode, to_SI_mode, to_DI_mode, to_TI_mode, to_word_mode;
enum {
Set_T = 1,
Set_S = 2,
Set_Char = 4,
Set_Int = 8,
Set_Double = 16,
Set_Float = 32,
Set_Signed = 64,
Set_Unsigned = 128,
Set_Short = 256,
Set_Long = 512,
Set_Vlong = 1024,
Set_Any = Set_T | Set_Short | Set_Long | Set_Signed | Set_Unsigned
};
enum {
CInt = 0, CSInt, CUInt, CReal, CChar, CSChar, CUChar
};
enum {
SNone = 0, STypedef, SAuto, SRegister, SExtern, SStatic, SForced
};
static struct symbol_op typedef_op = {
.type = KW_MODIFIER,
.declarator = typedef_specifier,
};
static struct symbol_op inline_op = {
.type = KW_MODIFIER,
.declarator = inline_specifier,
};
static struct symbol_op auto_op = {
.type = KW_MODIFIER,
.declarator = auto_specifier,
};
static struct symbol_op register_op = {
.type = KW_MODIFIER,
.declarator = register_specifier,
};
static struct symbol_op static_op = {
.type = KW_MODIFIER,
.declarator = static_specifier,
};
static struct symbol_op extern_op = {
.type = KW_MODIFIER,
.declarator = extern_specifier,
};
src/sparse-0.4.4/parse.c view on Meta::CPAN
static struct symbol_op while_op = {
.statement = parse_while_statement,
};
static struct symbol_op do_op = {
.statement = parse_do_statement,
};
static struct symbol_op goto_op = {
.statement = parse_goto_statement,
};
static struct symbol_op __context___op = {
.statement = parse_context_statement,
};
static struct symbol_op range_op = {
.statement = parse_range_statement,
};
static struct symbol_op asm_op = {
.type = KW_ASM,
.declarator = parse_asm_declarator,
.statement = parse_asm_statement,
.toplevel = toplevel_asm_declaration,
};
static struct symbol_op packed_op = {
.attribute = attribute_packed,
};
static struct symbol_op aligned_op = {
.attribute = attribute_aligned,
};
static struct symbol_op attr_mod_op = {
.attribute = attribute_modifier,
};
static struct symbol_op attr_force_op = {
.attribute = attribute_force,
};
static struct symbol_op address_space_op = {
.attribute = attribute_address_space,
};
static struct symbol_op mode_op = {
.attribute = attribute_mode,
};
static struct symbol_op context_op = {
.attribute = attribute_context,
};
static struct symbol_op designated_init_op = {
.attribute = attribute_designated_init,
};
static struct symbol_op transparent_union_op = {
.attribute = attribute_transparent_union,
};
static struct symbol_op ignore_attr_op = {
.attribute = ignore_attribute,
};
static struct symbol_op mode_QI_op = {
.type = KW_MODE,
.to_mode = to_QI_mode
};
static struct symbol_op mode_HI_op = {
.type = KW_MODE,
.to_mode = to_HI_mode
};
static struct symbol_op mode_SI_op = {
.type = KW_MODE,
.to_mode = to_SI_mode
};
static struct symbol_op mode_DI_op = {
.type = KW_MODE,
.to_mode = to_DI_mode
};
static struct symbol_op mode_TI_op = {
.type = KW_MODE,
.to_mode = to_TI_mode
};
static struct symbol_op mode_word_op = {
.type = KW_MODE,
.to_mode = to_word_mode
};
#ifndef DO_CTX
static
#else
void sparse_ctx_init_parse1(SCTX) {
#endif
struct init_keyword keyword_table[] = {
/* Type qualifiers */
{ "const", NS_TYPEDEF, .op = &const_op },
{ "__const", NS_TYPEDEF, .op = &const_op },
{ "__const__", NS_TYPEDEF, .op = &const_op },
{ "volatile", NS_TYPEDEF, .op = &volatile_op },
{ "__volatile", NS_TYPEDEF, .op = &volatile_op },
{ "__volatile__", NS_TYPEDEF, .op = &volatile_op },
/* Typedef.. */
{ "typedef", NS_TYPEDEF, .op = &typedef_op },
/* Type specifiers */
{ "void", NS_TYPEDEF, .type = &sctxp void_ctype, .op = &spec_op},
{ "char", NS_TYPEDEF, .op = &char_op },
{ "short", NS_TYPEDEF, .op = &short_op },
{ "int", NS_TYPEDEF, .op = &int_op },
{ "long", NS_TYPEDEF, .op = &long_op },
{ "float", NS_TYPEDEF, .op = &float_op },
src/sparse-0.4.4/parse.c view on Meta::CPAN
/* Extended types */
{ "typeof", NS_TYPEDEF, .op = &typeof_op },
{ "__typeof", NS_TYPEDEF, .op = &typeof_op },
{ "__typeof__", NS_TYPEDEF, .op = &typeof_op },
{ "__attribute", NS_TYPEDEF, .op = &attribute_op },
{ "__attribute__", NS_TYPEDEF, .op = &attribute_op },
{ "struct", NS_TYPEDEF, .op = &struct_op },
{ "union", NS_TYPEDEF, .op = &union_op },
{ "enum", NS_TYPEDEF, .op = &enum_op },
{ "inline", NS_TYPEDEF, .op = &inline_op },
{ "__inline", NS_TYPEDEF, .op = &inline_op },
{ "__inline__", NS_TYPEDEF, .op = &inline_op },
/* Ignored for now.. */
{ "restrict", NS_TYPEDEF, .op = &restrict_op},
{ "__restrict", NS_TYPEDEF, .op = &restrict_op},
/* Storage class */
{ "auto", NS_TYPEDEF, .op = &auto_op },
{ "register", NS_TYPEDEF, .op = ®ister_op },
{ "static", NS_TYPEDEF, .op = &static_op },
{ "extern", NS_TYPEDEF, .op = &extern_op },
{ "__thread", NS_TYPEDEF, .op = &thread_op },
/* Statement */
{ "if", NS_KEYWORD, .op = &if_op },
{ "return", NS_KEYWORD, .op = &return_op },
{ "break", NS_KEYWORD, .op = &loop_iter_op },
{ "continue", NS_KEYWORD, .op = &loop_iter_op },
{ "default", NS_KEYWORD, .op = &default_op },
{ "case", NS_KEYWORD, .op = &case_op },
{ "switch", NS_KEYWORD, .op = &switch_op },
{ "for", NS_KEYWORD, .op = &for_op },
{ "while", NS_KEYWORD, .op = &while_op },
{ "do", NS_KEYWORD, .op = &do_op },
{ "goto", NS_KEYWORD, .op = &goto_op },
{ "__context__",NS_KEYWORD, .op = &__context___op },
{ "__range__", NS_KEYWORD, .op = &range_op },
{ "asm", NS_KEYWORD, .op = &asm_op },
{ "__asm", NS_KEYWORD, .op = &asm_op },
{ "__asm__", NS_KEYWORD, .op = &asm_op },
/* Attribute */
{ "packed", NS_KEYWORD, .op = &packed_op },
{ "__packed__", NS_KEYWORD, .op = &packed_op },
{ "aligned", NS_KEYWORD, .op = &aligned_op },
{ "__aligned__",NS_KEYWORD, .op = &aligned_op },
{ "nocast", NS_KEYWORD, MOD_NOCAST, .op = &attr_mod_op },
{ "noderef", NS_KEYWORD, MOD_NODEREF, .op = &attr_mod_op },
{ "safe", NS_KEYWORD, MOD_SAFE, .op = &attr_mod_op },
{ "force", NS_KEYWORD, .op = &attr_force_op },
{ "bitwise", NS_KEYWORD, MOD_BITWISE, .op = &attr_mod_op },
{ "__bitwise__",NS_KEYWORD, MOD_BITWISE, .op = &attr_mod_op },
{ "address_space",NS_KEYWORD, .op = &address_space_op },
{ "mode", NS_KEYWORD, .op = &mode_op },
{ "context", NS_KEYWORD, .op = &context_op },
{ "designated_init", NS_KEYWORD, .op = &designated_init_op },
{ "__transparent_union__", NS_KEYWORD, .op = &transparent_union_op },
{ "noreturn", NS_KEYWORD, MOD_NORETURN, .op = &attr_mod_op },
{ "__noreturn__", NS_KEYWORD, MOD_NORETURN, .op = &attr_mod_op },
{ "pure", NS_KEYWORD, MOD_PURE, .op = &attr_mod_op },
{"__pure__", NS_KEYWORD, MOD_PURE, .op = &attr_mod_op },
{"const", NS_KEYWORD, MOD_PURE, .op = &attr_mod_op },
{"__const", NS_KEYWORD, MOD_PURE, .op = &attr_mod_op },
{"__const__", NS_KEYWORD, MOD_PURE, .op = &attr_mod_op },
{ "__mode__", NS_KEYWORD, .op = &mode_op },
{ "QI", NS_KEYWORD, MOD_CHAR, .op = &mode_QI_op },
{ "__QI__", NS_KEYWORD, MOD_CHAR, .op = &mode_QI_op },
{ "HI", NS_KEYWORD, MOD_SHORT, .op = &mode_HI_op },
{ "__HI__", NS_KEYWORD, MOD_SHORT, .op = &mode_HI_op },
{ "SI", NS_KEYWORD, .op = &mode_SI_op },
{ "__SI__", NS_KEYWORD, .op = &mode_SI_op },
{ "DI", NS_KEYWORD, MOD_LONGLONG, .op = &mode_DI_op },
{ "__DI__", NS_KEYWORD, MOD_LONGLONG, .op = &mode_DI_op },
{ "TI", NS_KEYWORD, MOD_LONGLONGLONG, .op = &mode_TI_op },
{ "__TI__", NS_KEYWORD, MOD_LONGLONGLONG, .op = &mode_TI_op },
{ "word", NS_KEYWORD, MOD_LONG, .op = &mode_word_op },
{ "__word__", NS_KEYWORD, MOD_LONG, .op = &mode_word_op },
};
#ifndef DO_CTX
static int keyword_table_cnt = ARRAY_SIZE(keyword_table);
#else
sctxp keyword_table_cnt = ARRAY_SIZE(keyword_table);
sctxp keyword_table = malloc(sizeof(keyword_table)); /* todo: release */
memcpy(sctxp keyword_table, keyword_table, sizeof(keyword_table));
}
#endif
const char *ignored_attributes[] = {
"alias",
"__alias__",
"alloc_size",
"__alloc_size__",
"always_inline",
"__always_inline__",
"artificial",
"__artificial__",
"bounded",
"__bounded__",
"cdecl",
"__cdecl__",
"cold",
"__cold__",
"constructor",
"__constructor__",
"deprecated",
"__deprecated__",
"destructor",
"__destructor__",
"dllexport",
"__dllexport__",
"dllimport",
"__dllimport__",
"error",
"__error__",
"externally_visible",
src/sparse-0.4.4/parse.c view on Meta::CPAN
token = token->next;
} else
sparse_error(sctx_ token->pos, "expect attribute mode symbol\n");
token = expect(sctx_ token, ')', "after mode attribute");
return token;
}
static struct token *attribute_context(SCTX_ struct token *token, struct symbol *attr, struct decl_state *ctx)
{
struct sym_context *context = alloc_context(sctx );
struct expression *args[3];
int argc = 0;
token = expect(sctx_ token, '(', "after context attribute");
while (!match_op(token, ')')) {
struct expression *expr = NULL;
token = conditional_expression(sctx_ token, &expr);
if (!expr)
break;
if (argc < 3)
args[argc++] = expr;
if (!match_op(token, ','))
break;
token = token->next;
}
switch(argc) {
case 0:
sparse_error(sctx_ token->pos, "expected context input/output values");
break;
case 1:
context->in = get_expression_value(sctx_ args[0]);
break;
case 2:
context->in = get_expression_value(sctx_ args[0]);
context->out = get_expression_value(sctx_ args[1]);
break;
case 3:
context->context = args[0];
context->in = get_expression_value(sctx_ args[1]);
context->out = get_expression_value(sctx_ args[2]);
break;
}
if (argc)
add_ptr_list(&ctx->ctype.contexts, context);
token = expect(sctx_ token, ')', "after context attribute");
return token;
}
static struct token *attribute_designated_init(SCTX_ struct token *token, struct symbol *attr, struct decl_state *ctx)
{
if (ctx->ctype.base_type && ctx->ctype.base_type->type == SYM_STRUCT)
ctx->ctype.base_type->designated_init = 1;
else
warning(sctx_ token->pos, "attribute designated_init applied to non-structure type");
return token;
}
static struct token *attribute_transparent_union(SCTX_ struct token *token, struct symbol *attr, struct decl_state *ctx)
{
if (sctxp Wtransparent_union)
warning(sctx_ token->pos, "ignoring attribute __transparent_union__");
return token;
}
static struct token *recover_unknown_attribute(SCTX_ struct token *token)
{
struct expression *expr = NULL;
sparse_error(sctx_ token->pos, "attribute '%s': unknown attribute", show_ident(sctx_ token->ident));
token = token->next;
if (match_op(token, '('))
token = parens_expression(sctx_ token, &expr, "in attribute");
return token;
}
static struct token *attribute_specifier(SCTX_ struct token *token, struct decl_state *ctx)
{
token = expect(sctx_ token, '(', "after attribute");
token = expect(sctx_ token, '(', "after attribute");
for (;;) {
struct ident *attribute_name;
struct symbol *attr;
if (eof_token(token))
break;
if (match_op(token, ';'))
break;
if (token_type(token) != TOKEN_IDENT)
break;
attribute_name = token->ident;
attr = lookup_keyword(sctx_ attribute_name, NS_KEYWORD);
if (attr && attr->op->attribute)
token = attr->op->attribute(sctx_ token->next, attr, ctx);
else
token = recover_unknown_attribute(sctx_ token);
if (!match_op(token, ','))
break;
token = token->next;
}
token = expect(sctx_ token, ')', "after attribute");
token = expect(sctx_ token, ')', "after attribute");
return token;
}
static const char *storage_class[] =
{
[STypedef] = "typedef",
[SAuto] = "auto",
[SExtern] = "extern",
[SStatic] = "static",
[SRegister] = "register",
[SForced] = "[force]"
};
static unsigned long storage_modifiers(SCTX_ struct decl_state *ctx)
{
static unsigned long mod[] =
{
( run in 0.506 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )