Skip to content

Conversation

@rerobika
Copy link
Member

These flags makes the code more readable also makes the process of introducing a new statement type easier.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]

@rerobika rerobika added enhancement An improvement parser Related to the JavaScript parser labels Nov 14, 2019
Comment on lines +88 to +93
/**
* Parser statement attributes.
* Note: the order of the attributes must be keep in sync with parser_statement_type_t
*/
static const uint8_t parser_statement_flags[] =
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea to remove redundancies and simplify the code base. But it would be great if we could make sure that the enum and this array are in synch.

If we can change the order of enum values, we can do it with macros, for example:

#define PARSER_STATEMENT_TYPE(F) \
  F(PARSER_STATEMENT_START, PARSER_STATM_NO_OPTS), \
  F(PARSER_STATEMENT_BLOCK, PARSER_STATM_NO_OPTS), \
...

#define PARSER_STATEMENT_TYPE_ES2015(F) ...

#define EXPAND1(A, B)  A
#define EXPAND2(A, B)  B

typedef enum
{
  PARSER_STATEMENT_TYPE(EXPAND1)
#if ENABLED (JERRY_ES2015)
  PARSER_STATEMENT_TYPE_ES2015(EXPAND1)
#endif /* ENABLED (JERRY_ES2015) */
} parser_statement_type_t;

static const uint8_t parser_statement_flags[] =
{
  PARSER_STATEMENT_TYPE(EXPAND2)
#if ENABLED (JERRY_ES2015)
  PARSER_STATEMENT_TYPE_ES2015(EXPAND2)
#endif /* ENABLED (JERRY_ES2015) */
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, probably it can be combined with statement_lengths[] as well.
@zherczeg What do you think about it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate patch. I want to se how it looks like.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(lines in the length are quite long, and we have 120 char limit)

These flags makes the code more readable also makes the process of introducing a new statement type easier.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
Copy link
Member

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@dbatyai dbatyai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dbatyai dbatyai merged commit 8cf5f96 into jerryscript-project:master Nov 15, 2019
@rerobika rerobika deleted the statm_flags branch June 16, 2020 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An improvement parser Related to the JavaScript parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants