summaryrefslogtreecommitdiff
path: root/tools/d2c/d2c_gram.y
diff options
context:
space:
mode:
Diffstat (limited to 'tools/d2c/d2c_gram.y')
-rw-r--r--tools/d2c/d2c_gram.y69
1 files changed, 36 insertions, 33 deletions
diff --git a/tools/d2c/d2c_gram.y b/tools/d2c/d2c_gram.y
index 12eff11..9e1e034 100644
--- a/tools/d2c/d2c_gram.y
+++ b/tools/d2c/d2c_gram.y
@@ -33,6 +33,7 @@ static void show_usage(const char *);
#include "coder.h"
#include "conv.h"
+#include "helpers.h"
struct action_tmp
{
@@ -95,13 +96,13 @@ struct action_tmp
register_hook_function(__hooks, t, f); \
})
-#define add_conditional_rule_to_coder(c, e, a, d) \
+#define add_conditional_rule_to_coder(c, e, a) \
({ \
encoding_spec *__spec; \
decoding_rules *__rules; \
__spec = get_current_encoding_spec(c); \
__rules = get_rules_in_encoding_spec(__spec); \
- register_conditional_rule(__rules, e, a, d); \
+ register_conditional_rule(__rules, e, a); \
})
}
@@ -115,15 +116,15 @@ struct action_tmp
int integer;
conv_func *subst; /* Fonction de conversion */
- conv_arg_list_t *conv_list; /* Liste d'arguments de conv. */
+ arg_list_t *args; /* Liste d'arguments */
- conv_expr_t *conv; /* Expression de conversion */
+ arg_expr_t *arg; /* Argument multi-usages */
ConvUnaryOperation un_op; /* Opération unaire */
ConvBinaryOperation bin_op; /* Opération bianire */
cond_expr *expr; /* Expression de déclenchement */
- struct action_tmp tmpa; /* Transfert temporaire */
+ rule_action raction; /* Action et éléments associés */
}
@@ -146,7 +147,7 @@ struct action_tmp
%token HOOKS
-%token RULES IF EXPR_START EQUAL BINVAL IMMVAL EXPR_END AND THEN SEE UNPREDICTABLE
+%token RULES IF EXPR_START EQUAL BINVAL IMMVAL EXPR_END AND THEN SEE CALL UNPREDICTABLE
%type <string> COPYRIGHT INS_NAME
@@ -160,17 +161,17 @@ struct action_tmp
%type <string> OPERAND_NAME OPERAND_INTERNAL OPERAND_VISIBLE
-
%type <subst> substitution
-%type <conv_list> conv_arg_list
-%type <conv> conv_expr conv_arg_composed
-%type <un_op> conv_expr_un_op
-%type <bin_op> conv_expr_bin_op
-%type <string> conv_arg_field
+
+%type <args> arg_list
+%type <arg> arg_expr arg_composed
+%type <un_op> arg_expr_un_op
+%type <bin_op> arg_expr_bin_op
+%type <string> arg_field
%type <expr> rule_cond
%type <string> BINVAL IMMVAL
-%type <tmpa> action
+%type <raction> action
%%
@@ -231,28 +232,29 @@ conversions : CONV substitutions
substitutions : /* empty */
| substitutions substitution { register_conversion_in_coder(coder, $2); }
-substitution : NAME EQ conv_expr { $$ = make_conv_from_expr($1, $3); }
- | NAME EQ NAME OP conv_arg_list CP { $$ = make_conv_from_func($1, $3, $5); }
+substitution : NAME EQ arg_expr { $$ = make_conv_from_expr($1, $3); }
+ | NAME EQ NAME OP arg_list CP { $$ = make_conv_from_func($1, $3, $5); }
+
-conv_arg_list : conv_expr { $$ = build_conv_arg_list($1); }
- | conv_arg_list COMMA conv_expr { $$ = extend_conv_arg_list($1, $3); printf("extend\n"); }
+arg_list : arg_expr { $$ = build_arg_list($1); }
+ | arg_list COMMA arg_expr { $$ = extend_arg_list($1, $3); }
-conv_expr : NAME { $$ = build_conv_expr_from_name($1); }
- | NUMBER { $$ = build_conv_expr_from_number($1); }
- | conv_arg_composed { $$ = $1; }
- | OP conv_expr CP { $$ = $2; }
- | conv_expr_un_op conv_expr { $$ = build_unary_conv_expr($2, $1); }
- | OP conv_expr conv_expr_bin_op conv_expr CP { $$ = build_binary_conv_expr($2, $4, $3); }
+arg_expr : NAME { $$ = build_arg_expr_from_name($1); }
+ | NUMBER { $$ = build_arg_expr_from_number($1); }
+ | arg_composed { $$ = $1; }
+ | OP arg_expr CP { $$ = $2; }
+ | arg_expr_un_op arg_expr { $$ = build_unary_arg_expr($2, $1); }
+ | OP arg_expr arg_expr_bin_op arg_expr CP { $$ = build_binary_arg_expr($2, $4, $3); }
-conv_expr_un_op : NOT { $$ = CUO_NOT; }
+arg_expr_un_op : NOT { $$ = CUO_NOT; }
-conv_expr_bin_op : EOR { $$ = CBO_EOR; }
+arg_expr_bin_op : EOR { $$ = CBO_EOR; }
-conv_arg_composed : conv_arg_field COLON conv_arg_field { $$ = build_composed_conv_expr($1, $3); }
- | conv_arg_composed COLON conv_arg_field { $$ = extend_composed_conv_expr($1, $3); }
+arg_composed : arg_field COLON arg_field { $$ = build_composed_arg_expr($1, $3); }
+ | arg_composed COLON arg_field { $$ = extend_composed_arg_expr($1, $3); }
-conv_arg_field : NAME { $$ = $1; printf(" composed::name '%s'\n", $1); }
- | BINVAL { $$ = $1; printf(" composed::bin '%s'\n", $1); }
+arg_field : NAME { $$ = $1; }
+ | BINVAL { $$ = $1; }
hooks : HOOKS hookings
@@ -268,16 +270,17 @@ rules : RULES rules_list
rules_list : /* empty */
| rules_list rule
-rule : IF EXPR_START rule_cond EXPR_END THEN action
- { add_conditional_rule_to_coder(coder, $3, $6.action, $6.details); }
+rule : IF EXPR_START rule_cond EXPR_END THEN action { add_conditional_rule_to_coder(coder, $3, &$6); }
+ | action { add_conditional_rule_to_coder(coder, NULL, &$1); }
rule_cond : NAME EQUAL BINVAL { $$ = build_simple_cond_expression($1, CCT_EQUAL, $3); }
| NAME EQUAL IMMVAL { $$ = build_simple_cond_expression($1, CCT_EQUAL, $3); }
| EXPR_START rule_cond EXPR_END AND EXPR_START rule_cond EXPR_END
{ $$ = build_composed_cond_expression($2, COT_AND, $6); }
-action : SEE INS_DETAILS { $$.action = CAT_SEE; $$.details = $2; }
- | UNPREDICTABLE { $$.action = CAT_UNPREDICTABLE; $$.details = NULL; }
+action : SEE INS_DETAILS { $$.type = CAT_SEE; $$.details = make_callable($2, false); }
+ | UNPREDICTABLE { $$.type = CAT_UNPREDICTABLE; }
+ | CALL NAME OP arg_list CP { $$.type = CAT_CALL; $$.callee = $2; $$.args = $4; }
%%