]> granicus.if.org Git - re2c/log
re2c
9 years agoFixed bug #115 "flex-style named definitions cause ambiguity in re2c grammar".
Ulya Trofimovich [Thu, 30 Jul 2015 14:11:03 +0000 (15:11 +0100)]
Fixed bug #115 "flex-style named definitions cause ambiguity in re2c grammar".

This commit removes 10 shift/reduce conflicts in bison grammar for re2c.
These conflicts are caused by allowing flex-style named definitions
    name regular-expression
to contain newlines and to be mixed with rules. It's not just some
conflicts in LALR(1) grammar, it is genuine ambiguity as can be observed
from the following example:
    /*!re2c
        name "a"
        "b" "c" {}
    */
which can be parsed in two ways:
    definition -> name "a"
    rule -> "b" "c" {}
and
    definition -> name "a" "b"
    rule -> "c" {}
, both ways being perfectly valid.

This commit resolves ambiguity by forbidding newlines in flex-style
named definitions (conforming to flex syntax). Newline in these
definitions is treated in a special way: lexer emits token 'FID_END',
which marks the end of flex-style named definition in parser.

9 years agoFixed segfault on options that expect an argument but are passed none.
Ulya Trofimovich [Wed, 29 Jul 2015 13:46:19 +0000 (14:46 +0100)]
Fixed segfault on options that expect an argument but are passed none.

Example of commands that triggered segfault:
    $ re2c -o
    $ re2c --type-header
    $ re2c --input

9 years agoForce custom input API with "--skeleton" option.
Ulya Trofimovich [Wed, 29 Jul 2015 11:54:50 +0000 (12:54 +0100)]
Force custom input API with "--skeleton" option.

Dropped this line while rewriting options parser.

9 years agoRemoved extra newline at the end of some error messages.
Ulya Trofimovich [Wed, 29 Jul 2015 11:37:51 +0000 (12:37 +0100)]
Removed extra newline at the end of some error messages.

9 years agoOutput error message when passed multiple arguments after "--" option.
Ulya Trofimovich [Wed, 29 Jul 2015 11:32:20 +0000 (12:32 +0100)]
Output error message when passed multiple arguments after "--" option.

All arguments after "--" are treated as input files, but re2c expects
exactly one input file.

9 years agoCommented parser conflict.
Ulya Trofimovich [Wed, 29 Jul 2015 11:19:40 +0000 (12:19 +0100)]
Commented parser conflict.

See https://github.com/skvadrik/re2c/issues/115

orts the commit.

9 years agoImproved warning messages with '-Werror'.
Ulya Trofimovich [Mon, 27 Jul 2015 20:29:03 +0000 (21:29 +0100)]
Improved warning messages with '-Werror'.

Report an error rather than a warning (at least GCC does so).

9 years agoOutput condition name with '-Wnaked-default' in '-c' mode.
Ulya Trofimovich [Mon, 27 Jul 2015 14:54:57 +0000 (15:54 +0100)]
Output condition name with '-Wnaked-default' in '-c' mode.

9 years agoUpdated tests.
Ulya Trofimovich [Mon, 27 Jul 2015 14:33:29 +0000 (15:33 +0100)]
Updated tests.

Line info changed in warning messages since commit
929c87fdf3a3de5f08206a258dfabbc0a068c561:
"Unified location output in warning messages.

9 years agoUnified location output in warning messages.
Ulya Trofimovich [Mon, 27 Jul 2015 14:12:49 +0000 (15:12 +0100)]
Unified location output in warning messages.

9 years agoRenames '-Wempty-rule' -> '-Wmatch-empty-string' and improved message.
Ulya Trofimovich [Mon, 27 Jul 2015 11:57:46 +0000 (12:57 +0100)]
Renames '-Wempty-rule' -> '-Wmatch-empty-string' and improved message.

9 years agoEnable warnings globally for tests.
Ulya Trofimovich [Mon, 27 Jul 2015 11:45:36 +0000 (12:45 +0100)]
Enable warnings globally for tests.

Fixed reference results for tests that trigger warnings.

9 years agoDon't lose stdout and stderr when testing with -o.
Ulya Trofimovich [Mon, 27 Jul 2015 10:45:30 +0000 (11:45 +0100)]
Don't lose stdout and stderr when testing with -o.

9 years agoDon't output generated code when failed with -Werror.
Ulya Trofimovich [Mon, 27 Jul 2015 10:41:23 +0000 (11:41 +0100)]
Don't output generated code when failed with -Werror.

9 years agoAdded warinigs: -W, -Werror.
Ulya Trofimovich [Mon, 27 Jul 2015 08:00:33 +0000 (09:00 +0100)]
Added warinigs: -W, -Werror.

    -W: enable all warnings
    -Werror: turn all enabled (hereafter) warnings into errors

Specific warnings added by this commit:
    -Wempty-character-class
    -Wempty-rule
    -Wnaked-default

For each warning there are -Wno-, -Werror-, -Wno-error- options.

9 years agoFixed typos in release script, updated release guidelines.
Ulya Trofimovich [Fri, 24 Jul 2015 19:28:20 +0000 (20:28 +0100)]
Fixed typos in release script, updated release guidelines.

9 years agoSplit release script into tw parts: distcheck and everything else.
Ulya Trofimovich [Tue, 21 Jul 2015 18:06:07 +0000 (19:06 +0100)]
Split release script into tw parts: distcheck and everything else.

9 years agoMakefile.am: remved nonexistent file 'doc/index.html'.
Ulya Trofimovich [Tue, 21 Jul 2015 17:17:54 +0000 (18:17 +0100)]
Makefile.am: remved nonexistent file 'doc/index.html'.

9 years agoSite front page 'doc/index.html' gone to branch 'gh-pages'.
Ulya Trofimovich [Tue, 21 Jul 2015 16:46:09 +0000 (17:46 +0100)]
Site front page 'doc/index.html' gone to branch 'gh-pages'.

Note that anther site page, manual.html, is autogenerated from
'doc/re2c.ad.in' which is also used to generate documentation.

9 years agoMakefile.am: added forgotten header.
Ulya Trofimovich [Tue, 21 Jul 2015 16:22:11 +0000 (17:22 +0100)]
Makefile.am: added forgotten header.

9 years agoFixed re2c behaviour with "--" command line option.
Ulya Trofimovich [Tue, 21 Jul 2015 12:47:31 +0000 (13:47 +0100)]
Fixed re2c behaviour with "--" command line option.

All arguments after "--" are treated as non-options. This can be
used to handle option-like filenames (those starting with "-" and "--").

9 years agoAllow to specify exacly one input file and at most one output and header file.
Ulya Trofimovich [Tue, 21 Jul 2015 11:15:01 +0000 (12:15 +0100)]
Allow to specify exacly one input file and at most one output and header file.

9 years agoFixed GXX warning '-Wsuggest-attribute=format'.
Ulya Trofimovich [Mon, 20 Jul 2015 21:14:12 +0000 (22:14 +0100)]
Fixed GXX warning '-Wsuggest-attribute=format'.

g++ warns if function with '__attribute__((format (printf, ...)))'
has wrong number of arguments or argument type is wrong.

9 years agoUse 'vfprintf' instead of 'fprintf' to print variadic arguments.
Ulya Trofimovich [Mon, 20 Jul 2015 18:45:54 +0000 (19:45 +0100)]
Use 'vfprintf' instead of 'fprintf' to print variadic arguments.

Added GCC warninigs -Wformat=2 (reveals this error) and
-Wsuggest-attribute=format.

9 years agoModified release script to try build with bmake as well as make.
Ulya Trofimovich [Mon, 20 Jul 2015 14:37:05 +0000 (15:37 +0100)]
Modified release script to try build with bmake as well as make.

9 years agoMakefile.am: drop non-POSIX make feature: '$<' in target rules.
Ulya Trofimovich [Mon, 20 Jul 2015 14:24:46 +0000 (15:24 +0100)]
Makefile.am: drop non-POSIX make feature: '$<' in target rules.

POSIX make allows '$<' only in inferencee rule.
Found while trying to build with bmake.

9 years agoMakefile.am: respect various 'make' alternatives: use '$(MAKE)'.
Ulya Trofimovich [Mon, 20 Jul 2015 13:42:32 +0000 (14:42 +0100)]
Makefile.am: respect various 'make' alternatives: use '$(MAKE)'.

9 years agoMakefile.am: use inference rule '.re.cc' to avoid rule duplication.
Ulya Trofimovich [Mon, 20 Jul 2015 13:39:54 +0000 (14:39 +0100)]
Makefile.am: use inference rule '.re.cc' to avoid rule duplication.

Inference rules is a standard POSIX make feature.

9 years agoNew re2c-based parser for command line options.
Ulya Trofimovich [Sun, 19 Jul 2015 14:22:47 +0000 (15:22 +0100)]
New re2c-based parser for command line options.

9 years agoRemoved unused class variable.
Ulya Trofimovich [Mon, 29 Jun 2015 20:51:02 +0000 (21:51 +0100)]
Removed unused class variable.

9 years agoDon't check range bounds in pretty-printing function.
Ulya Trofimovich [Fri, 26 Jun 2015 13:09:51 +0000 (14:09 +0100)]
Don't check range bounds in pretty-printing function.

9 years agoRemoved unused function.
Ulya Trofimovich [Fri, 26 Jun 2015 13:01:56 +0000 (14:01 +0100)]
Removed unused function.

9 years agoComment on test for character class operations.
Ulya Trofimovich [Tue, 23 Jun 2015 21:02:27 +0000 (22:02 +0100)]
Comment on test for character class operations.

9 years agoAdded test for operations on character classes (addition and subtraction).
Ulya Trofimovich [Tue, 23 Jun 2015 20:44:13 +0000 (21:44 +0100)]
Added test for operations on character classes (addition and subtraction).

Test is built into a separate binary. Both test building and running
is triggered by `make check`.

9 years agoOperations on character classes: fixed subtraction, simplified addition.
Ulya Trofimovich [Mon, 22 Jun 2015 12:50:17 +0000 (13:50 +0100)]
Operations on character classes: fixed subtraction, simplified addition.

Subtraction was broken by commit f56196d29f6c29b37e3e95a6777714c237e1c71c:
"Simplified implementation of range union and difference."

9 years agoMore tests for "--empty-class" option.
Ulya Trofimovich [Tue, 16 Jun 2015 15:09:32 +0000 (16:09 +0100)]
More tests for "--empty-class" option.

This time I found all tests that are affected by this option
(that is, contain empty ranges) and added explicit option variants
for most of them (excluding 'test/empty_range.*' group, as we already
have 'test/bug61_positive.*' group that checks the same thing).

9 years agoUpdated docs (added new options an long variants for all options).
Ulya Trofimovich [Tue, 16 Jun 2015 14:48:55 +0000 (15:48 +0100)]
Updated docs (added new options an long variants for all options).

9 years agoMakefile.am: added forgotten header.
Ulya Trofimovich [Tue, 16 Jun 2015 14:20:02 +0000 (15:20 +0100)]
Makefile.am: added forgotten header.

9 years agoAdded cmd option "--empty-class <match-empty|match-none|error>".
Ulya Trofimovich [Tue, 16 Jun 2015 13:17:17 +0000 (14:17 +0100)]
Added cmd option "--empty-class <match-empty|match-none|error>".

This option controls re2c actions when it encounters empty character
class (e.g. [], [^\0x00-\xFF] or [\0x00-\xFF]\[\0x00-\xFF]):
    match-empty (default) - match on empty input
    match-none - fail to match on any input
    error - compilation error

This is a final fix for bug #61 "empty character class [] matches empty string".

9 years agoPartial fix for bug #61 "empty character class [] matches empty string".
Ulya Trofimovich [Tue, 16 Jun 2015 11:19:03 +0000 (12:19 +0100)]
Partial fix for bug #61 "empty character class [] matches empty string".

Given the following code:
    /*!re2c
        [] {}
    */

    /*!re2c
        [^\x00-\xFF] {}
    */

    /*!re2c
        [\x00-\xFF]\[\x00-\xFF] {}
    */
re2c versions <=0.13.6 and >=0.13.7 behaved differently.
0.13.6 consistently considered that empty range should match empty string.
Since 0.13.7 empty positive range [] and empty difference (e.g. [a-z][a-z])
still match empty string, but empty negative range (e.g. [^\x00-\xFF])
matches nothing (always fails). The faulty commit is
28ee7c95bca46ad3cdb965741c5c29e21c50df14
"Added UTF-8 encoding support and tests for it."

This commit brings back consistent behaviour of 0.13.6: empty range,
however it was constructed, always matches empty string. Whether this
behaviour is sane or not is another question.

9 years agoConstruct non-NULL regexps from NULL ranges (for variable-length encodings).
Ulya Trofimovich [Mon, 15 Jun 2015 14:39:29 +0000 (15:39 +0100)]
Construct non-NULL regexps from NULL ranges (for variable-length encodings).

NULL range represents empty range: range union and difference functions
return NULL for empty ranges. Thus NULL can be passed to functions
that construct regexp from range ('MatchOp', 'UTF8Range' and 'UTF16Range').
All these functions must behave return non-NULL for NULL ranges, since
further code relies on this.

9 years agoCrash on attempt to create range with lower bound greater or equal to lower bound.
Ulya Trofimovich [Mon, 15 Jun 2015 14:09:02 +0000 (15:09 +0100)]
Crash on attempt to create range with lower bound greater or equal to lower bound.

Better have an assert than nothing until we handle such cases properly.
As for now, if the user inputs range like [9-0], it will be tranformed
to [0-9]. Later re2c should at least warn about such cases.

9 years agoNow range internals are only visible to union/difference functions.
Ulya Trofimovich [Mon, 15 Jun 2015 13:31:26 +0000 (14:31 +0100)]
Now range internals are only visible to union/difference functions.

Ranges must be constructed so that linked ranges don't overlap and
are monotonous. This is always true for one-link ranges created by
range constructor, and we construct larger ranges from them using
union and difference functions (that maintain the invariant).

9 years agoSimplified implementation of range union and difference.
Ulya Trofimovich [Mon, 15 Jun 2015 13:09:08 +0000 (14:09 +0100)]
Simplified implementation of range union and difference.

9 years agoExplicitly shallow-copy ranges instead of using obscure copy constructor.
Ulya Trofimovich [Sat, 13 Jun 2015 10:51:19 +0000 (11:51 +0100)]
Explicitly shallow-copy ranges instead of using obscure copy constructor.

9 years agoRestructured sources layout, improved formatting.
Ulya Trofimovich [Wed, 10 Jun 2015 16:30:15 +0000 (17:30 +0100)]
Restructured sources layout, improved formatting.

9 years agoUnified macro names in header guards.
Ulya Trofimovich [Tue, 9 Jun 2015 16:36:36 +0000 (17:36 +0100)]
Unified macro names in header guards.

Inspired by sudden collision with '__COUNTER__' I occasionally got
while guarding 'src/util/counter.h'.

Now all headers use guards of the form '_RE2C_PATH_TO_HEADER_BASENAME_'.
Some compilers (e.g. clang++) would warn about [-Wreserved-id-macro],
but their reasonong about reserved macro names is quite crude and re2c
is not able to confirm their standards anyway (e.g. autoconf-generated
macro name 'SIZEOF___INT64').

9 years agoDistinct restricted type for rule priority.
Ulya Trofimovich [Tue, 9 Jun 2015 14:28:58 +0000 (15:28 +0100)]
Distinct restricted type for rule priority.

As with labels, try to control how rule priorities are created:
make a special counter that creates new priorities and disallow
everyone but this counter do it.

9 years agoSimplified creation of rule states and backup states.
Ulya Trofimovich [Mon, 8 Jun 2015 21:25:32 +0000 (22:25 +0100)]
Simplified creation of rule states and backup states.

New simpler implementation uses STL containers instaed of sparse
array. It's less efficient, but the place is not a bottleneck and
simplicity is more important than efficiency.

9 years agoA better data structure for mapping 'yyaccept' values to DFA rule states.
Ulya Trofimovich [Mon, 8 Jun 2015 14:06:56 +0000 (15:06 +0100)]
A better data structure for mapping 'yyaccept' values to DFA rule states.

'yyaccept' values must be continuous natural numbers starting from 0,
so array indices represent them ideally.

9 years agoTried to improve code readability.
Ulya Trofimovich [Mon, 8 Jun 2015 13:41:55 +0000 (14:41 +0100)]
Tried to improve code readability.

Now rule states and default state are added to DFA in separate
independent passes.

Removed 'bSaveOnHead' DFA property as it can be calculated right
before setting initial state action.

9 years agoTrack backup states only if DFA has default state.
Ulya Trofimovich [Mon, 8 Jun 2015 10:27:14 +0000 (11:27 +0100)]
Track backup states only if DFA has default state.

9 years agoReduced redundant variable.
Ulya Trofimovich [Sun, 7 Jun 2015 12:59:48 +0000 (13:59 +0100)]
Reduced redundant variable.

Variables 'accept' and 'accfixup' were assigned both only once and
in the same place and used to do the same thing.

9 years agoFixed bug #60 "redundant use of YYMARKER".
Ulya Trofimovich [Sat, 6 Jun 2015 17:51:27 +0000 (18:51 +0100)]
Fixed bug #60 "redundant use of YYMARKER".

Bug description: sometimes re2c would generate code that backups
current input position (e.g. 'YYMARKER = YYCURSOR'), but wouldn't
generate code that restores backuped position (e.g. 'YYCURSOR =
YYMARKER').

Analyses: DFA may have overlapping rules (e.g. "a" and "aaa").
In such cases, if the shorter rule matched, lexer must attempt to
match the longer one. If the longer rule also mathed, then lexer
prefers it to the shorter rule. If the longer rule didn't match,
lexer must backtrack input position to the point when the shorter
rule matched. In order to be able to backtrack, re2c must generate
backup code (e.g. 'YYMARKER = YYCURSOR') and restore code (e.g.
'YYCURSOR = YYMARKER').
In some rare cases DFA has overlapping rules, but if the shorter rule
matched, then the longer rule will always match (perhaps on an
arbitrary long input string), e.g.:
    /*!re2c
        [^]+ "a" { 1st }
        "b"      { 2nd }
    */
In this cases there's no need to generate backup code for 2nd rule:
lexer will either encounter final "a" and the 1st rule will match
or YYFILL will not return; anyway, restore code will never be run.
re2c used to output backup code but not restore code in such cases.
This is the bug: backup code is useless without restore code and
should be omitted.

In future re2c should warn about such cases (when the shorter of
two overlapping rules is shadowed by the longer one).

The fix: postpone insertion of save actions (those with backup code)
untill it is known if restore code will be generated.
I also removed obsolete global variable 'bUsedYYMarker', which was
always set to 'true' (it should be per-DFA, not per-block configuration
anyway).

9 years agoFixed bug #59 "bogus 'yyaccept' in '-c' mode".
Ulya Trofimovich [Thu, 4 Jun 2015 21:25:03 +0000 (22:25 +0100)]
Fixed bug #59 "bogus 'yyaccept' in '-c' mode".

We have one 'yyaccept' initialization per re2c block. Each block
consists of one or more DFA (multiple DFA in '-c' mode in case of
multiple conditions). Each DFA may or may not use 'yyaccept'
(that is, save 'yyaccept' in some states and have a dispatch state
based on saved 'yyaccept' value).

Description of the bug: in '-c' mode, sometimes a DFA would have
states that save 'yyaccept', but no dispatch state that uses that
saved values. DFA didn't actually need 'yyaccept' (all the
assignments vanished if other conditions that need 'yyaccept' were
removed).

The essence of the bug: re2c decided whether to output 'yyaccept'
related stuff on a per-block basis: for multiple conditions in the
same block, the same decision was made (if any condition needed
'yyaccept', all of them would to output it).

The fix: 'yyaccept' initialization should be done on a per-block
basis, while assignments to 'yyaccept' should be done on a per-DFA
basis. Also, 'yyaccept' initialization must be delayed, while
assignments to 'yyaccept' must not.

Note: we may consider per-DFA 'yyaccept' initialization (have a
local 'yyaccept' variable per DFA). This wouldn't conflict with '-f'
switch (as it might seem) as long as we name all the variables
'yyaccept' and don't generate any 'yyaccept' initializations with '-f'.

9 years agoUse autoconf to locate bison.
Ulya Trofimovich [Tue, 2 Jun 2015 21:54:01 +0000 (22:54 +0100)]
Use autoconf to locate bison.

9 years agoRespect user CXXFLAGS.
Ulya Trofimovich [Tue, 2 Jun 2015 21:29:19 +0000 (22:29 +0100)]
Respect user CXXFLAGS.

As automake manual (chapter 27.6 "Flag Variables Ordering") states,
CXXFLAGS is a user variable and should be left for users to override
C++ compiler flags. Thus we should leave CXXFLAGS as is and modify
AM_CXXFLAGS insted.

9 years agoAdded missing header (revealed by mingw build).
Ulya Trofimovich [Tue, 2 Jun 2015 16:16:27 +0000 (17:16 +0100)]
Added missing header (revealed by mingw build).

9 years agoCheck CXXFLAGS in configure.
Ulya Trofimovich [Tue, 2 Jun 2015 15:58:53 +0000 (16:58 +0100)]
Check CXXFLAGS in configure.

Instead of unconditionally setting CXXFLAGS in Makefile.am,
check the presence of a flag in configure.ac. If the flag is
present (that is, an attempt to compile an empty C++ program with
this flag is successful), then it is added to CXXFLAGS.

Now one can add *any* compiler flag in configure.ac without
worrying about portability.

9 years agoSupport 'make distcheck'.
Ulya Trofimovich [Tue, 2 Jun 2015 12:19:50 +0000 (13:19 +0100)]
Support 'make distcheck'.

The only problem with 'make distcheck' was that we needed write
access to top source directory ('make' wanted to overwrite bootstrap
parser if it was built with bison and 'make check' wanted to create
temporary files in 'test/' directory).

This commit fixes it:
    - 'make' doesn't try to overwrite bootstrap if it is identical
      to the existing one (must always be true for 'make distcheck')
    - testing script makes a temporary directory and keeps all
      temporary files there. If some tests failed, temporary files
      for them are left and test sources and reference results are
      copied into temporary directory to make debug more convenient.

This commit makes use of 'make distcheck' in release script.

9 years agoFixed build system to support automake's 'subdir-objects' feature.
Ulya Trofimovich [Tue, 2 Jun 2015 11:34:09 +0000 (12:34 +0100)]
Fixed build system to support automake's 'subdir-objects' feature.

As I updated automake to version 1.15 it began to produce lots of
warnings about 'subdir-objects' not used when it should have been.
Turns out that 'subdir-objects' will be on by default in 2.0.

So I tried to turn on 'subdir-objects' and builds began to fail:
automake didn't expand '$(sourcedir)' and '$(builddir)' prefixes.
I erroneously prepended these prefixes in commit
38f526d04415adb7b5e6bca228fc26409833f5c3 "Updated build system.",
as commit message says:
...
    Makefile.am:
        - explicitly prefixed all file names with $(srcdir) or $(builddir)
...

But automake prepends these prefixes already where necessary, except
for custom rules with side effects: if a custom rule touches some
files that are not explicit targets or dependencies of this rule,
then automake won't find these files unless they are in build directory.
We have such side-effectful custom rules:
    - parser rule produces multiple files and touches bootstrap files
    - scanner rule touches bootstrap file
    - doc rules touch bootstrap files
Multiple files is a common problem of make. Bootstrap introduces
circular dependency, since bootstrap files need to be updated after
they've been used. So it's hard to get rid of side effects in these
rules.

This commit enabels 'subdir-objects' feature and removes all prefixes
in variables and adds them in side-effectful custom rules (for files
from source directory, not for files from build directory). It also
makes use of '$@' and '$<' special variables in custom rules (which
makes side effects more explicit).

Still I don't yet fully understand how automake uses things like
'$(sourcedir)' and '$(builddir)' and their relation with 'subdir-objects'
(it's probably related with non-recursive makefiles).

9 years agoEnable silent builds by default.
Ulya Trofimovich [Mon, 1 Jun 2015 21:59:08 +0000 (22:59 +0100)]
Enable silent builds by default.

9 years agoIgnore one more autoconf-generated script.
Ulya Trofimovich [Mon, 1 Jun 2015 10:43:26 +0000 (11:43 +0100)]
Ignore one more autoconf-generated script.

9 years agoRemoved remnants of CVS ("# $Id$" in the beginning of some files)
Ulya Trofimovich [Mon, 1 Jun 2015 10:42:23 +0000 (11:42 +0100)]
Removed remnants of CVS ("# $Id$" in the beginning of some files)

9 years agoUse autoreconf.
Ulya Trofimovich [Mon, 1 Jun 2015 10:23:38 +0000 (11:23 +0100)]
Use autoreconf.

As stated by autoconf manual, autoreconf is more portable than
self-written scripts because aclocal may be removed in future.

9 years agoSplit header and appropriate source file into smaller parts.
Ulya Trofimovich [Thu, 28 May 2015 20:10:45 +0000 (21:10 +0100)]
Split header and appropriate source file into smaller parts.

9 years agoMoved another utility class to a separate file in 'src/util/'.
Ulya Trofimovich [Thu, 28 May 2015 17:40:41 +0000 (18:40 +0100)]
Moved another utility class to a separate file in 'src/util/'.

9 years agoMoved utility class to a separate file in 'src/util/'.
Ulya Trofimovich [Thu, 28 May 2015 17:26:10 +0000 (18:26 +0100)]
Moved utility class to a separate file in 'src/util/'.

9 years agoDon't output newline instead if label in initial DFA state.
Ulya Trofimovich [Thu, 28 May 2015 11:16:06 +0000 (12:16 +0100)]
Don't output newline instead if label in initial DFA state.

Rationale: the equivalence of initial label to
're2c::label_counter_t::FIRST' is NOT a proper criterion
and pretty-printing shouldn't rely on it. The real criterion
is something like "(first re2c block OR any use block in '-r'
mode) AND first condition in'-c' mode", but it's spurious and
introduces unnecessary complications.

Droping this newline allows us drop equivalence operator for
labels.

Used the following bash script to ensure that all the changes
in tests are caused by missing newline(s):

    #!/bin/bash

    for f2 in *.temp
    do
        f1=${f2%.temp}

        diff1=`diff $f1 $f2 | grep '^< ' | wc -l`
        diff1_line=`diff $f1 $f2 | grep '^< #line' | wc -l`
        diff1_newline=`diff $f1 $f2 | grep '^< $' | wc -l`
        diff2=`diff $f1 $f2 | grep '^> ' | wc -l`
        diff2_line=`diff $f1 $f2 | grep '^> #line' | wc -l`

        # missing: only newlines and line directives
        if [[ $diff1 -ne $((diff1_line + diff1_newline)) ]]
        then
            echo "FAIL1: $f1"
            exit 1
        fi

        # added: only line directives
        if [[ $diff2 -ne $diff2_line ]]
        then
            echo "FAIL2: $f1"
            exit 1
        fi

        # the number of missing line directives
        # equals to the number of added line directives
        if [[ $diff1_line -ne $diff2_line ]]
        then
            echo "FAIL4: $f1"
            exit 1
        fi
    done

    echo "OK"

9 years agoIntroduced a distinct type for labels.
Ulya Trofimovich [Thu, 28 May 2015 10:45:11 +0000 (11:45 +0100)]
Introduced a distinct type for labels.

9 years agoMoved label assignment out of global scope to 're2c::OutputFile'.
Ulya Trofimovich [Wed, 27 May 2015 21:24:19 +0000 (22:24 +0100)]
Moved label assignment out of global scope to 're2c::OutputFile'.

Now label assignment is done with the help of a simple class
're2c::Label' that has very few operations.

9 years agoSome renaming and comment updating.
Ulya Trofimovich [Wed, 27 May 2015 16:26:22 +0000 (17:26 +0100)]
Some renaming and comment updating.

9 years agoAdded some more on 're2c:startlabel = <integer>;' configuration.
Ulya Trofimovich [Wed, 27 May 2015 15:48:32 +0000 (16:48 +0100)]
Added some more on 're2c:startlabel = <integer>;' configuration.

9 years agoClarified which label is used.
Ulya Trofimovich [Wed, 27 May 2015 15:33:22 +0000 (16:33 +0100)]
Clarified which label is used.

Label of the first state must be used rather than some obscure label
relative to start label (which is itself quite obscure).

9 years agoIsolated label counting.
Ulya Trofimovich [Wed, 27 May 2015 14:04:26 +0000 (15:04 +0100)]
Isolated label counting.

9 years agoSeparated code generation for DFA actions and DFA states.
Ulya Trofimovich [Wed, 27 May 2015 12:04:53 +0000 (13:04 +0100)]
Separated code generation for DFA actions and DFA states.

Removes debugging utilities for DFA states (we should either add
debug builds explicitely or throw away temporary debug stuff).

9 years agoGather all label counting in one place prior to code generation.
Ulya Trofimovich [Wed, 27 May 2015 11:52:02 +0000 (12:52 +0100)]
Gather all label counting in one place prior to code generation.

9 years agoMoved start label configuration out of global scope.
Ulya Trofimovich [Wed, 27 May 2015 10:50:55 +0000 (11:50 +0100)]
Moved start label configuration out of global scope.

There are two configurations:
1. re2c:startlabel = <integer>;
2. re2c:startlabel = <string>;
The scope of these configurations is the scope of current re2c block.

9 years agoOutput user-defines start label in the appropriate place.
Ulya Trofimovich [Tue, 26 May 2015 20:34:56 +0000 (21:34 +0100)]
Output user-defines start label in the appropriate place.

Before this commit, given the following example:
    /*!re2c
            re2c:startlabel = "start";
            [^]* {}
    */
re2c would generate the following code:
    {
            YYCTYPE yych;
            goto yy0;
    yy1:
    start:
            ++YYCURSOR;
    yy0:
            if (YYLIMIT <= YYCURSOR) YYFILL(1);
            yych = *YYCURSOR;
            goto yy1;
            {}
    }
where "start:" falsely corresponds to "yy1:" rather to "yy0:".
(The important property of this example is that DFA has arrows
to initial state.) This commit fixes this behavior:
    {
            YYCTYPE yych;
    start:
            goto yy0;
    yy1:
            ++YYCURSOR;
    yy0:
            if (YYLIMIT <= YYCURSOR) YYFILL(1);
            yych = *YYCURSOR;
            goto yy1;
            {}
    }

9 years agoDon't hide the ugly fact that default state in '-f' mode is always state 0.
Ulya Trofimovich [Tue, 26 May 2015 13:00:01 +0000 (14:00 +0100)]
Don't hide the ugly fact that default state in '-f' mode is always state 0.

In '-f' mode, state dispatch generation can be triggered in two ways.
Both ways use 're2c::OutputFile::insert_state_goto', which generates
state dispatch only if it hasn't been already generated. The two ways
are:
1. Explicitly, using '/*!getstate:re2c*/'. In this case default state
   must be state 0 because it's hardcoded in the invocation of
   're2c::OutputFile::insert_state_goto' in 'src/parse/scanner_lex.re'.
2. Implicitly, in 're2c::DFA::emit'. In this case default state must
   be state 0 because if 'prolog_label' is not 0, it means that it's
   not the first time 're2c::DFA::emit' is called and state dispatch
   has already been generated.

This commit makes it explicit that re2c always uses state 0.

Note:
    Currently in '-f' mode re2c generates one global dispatch for
    the whole file (the enumeration of yyFillLabel's is also global).
    All re2c blocks share the same state dispatch, so in '-f' mode all
    re2c blocks must reside in the same function and must be parts of
    the same lexer (exception: in '-r' mode re2c generates one state
    dispatch per use block).

    This is clearly an ugly limitation: one is forced put disconnected
    lexers in different files in '-f' mode.

    Now re2c provides conditions as a way to express related blocks,
    so if users used multiple blocks only for unrelated lexers, we
    could safely limit the scope of state dispatch to a single block.
    But conditions can conflict with other re2c features, they are
    a bit broken and I'm pretty sure some users use multiple blocks
    (e.g. I used to do it).

    Thus we cannot just make '-f' generate state dispatch on per-block
    basis (there're some other obstacles: it's not quite clear which
    block '/*!getstate:re2c*/ directive is related to, etc.).

    I leave the situation 'as is' until better times (when lexer-
    parser loop is fixed and the whole code generation model is more
    robust).

9 years agoClarify which label is relevant to initial state.
Ulya Trofimovich [Tue, 26 May 2015 11:34:57 +0000 (12:34 +0100)]
Clarify which label is relevant to initial state.

(see commit 4ab969deca341820d03ffb979f023256b10c2f92)

9 years agoCompare DFA states rather than labels.
Ulya Trofimovich [Tue, 26 May 2015 11:24:48 +0000 (12:24 +0100)]
Compare DFA states rather than labels.

(see commit 923f4c5559b1f8b43e63d1013d91698e7496e28c)

9 years agoClarify which label is relevant to initial state.
Ulya Trofimovich [Sun, 24 May 2015 20:38:55 +0000 (21:38 +0100)]
Clarify which label is relevant to initial state.

Initial state is different from all other states in that should
not advance YYCURSOR when it's entered first time (when DFA is
entered). But it should advance YYCURSOR like any normal state if
it's entered from any other part of DFA (other DFA states may well
lead to the inital state, e.g. '[^]*')

That's why inital state is split into two parts, each marked by a
separate label: normal state label points to the code that advances
YYCURSOR, and special label points right after that code (skips it).

It happens so that normal state label is equal to special initial
label plus one, but we shouldn't rely on that.

9 years agoClarify that initial state stores 'start_label', not some random label.
Ulya Trofimovich [Sun, 24 May 2015 20:33:18 +0000 (21:33 +0100)]
Clarify that initial state stores 'start_label', not some random label.

9 years agoCompare DFA states rather than labels.
Ulya Trofimovich [Thu, 21 May 2015 13:38:13 +0000 (14:38 +0100)]
Compare DFA states rather than labels.

This is first step to postpone labelling states until all the
code is actually generated (in the form of some structure in
memory) and it's time to pretty-print it to file.

Labels shouldn't be mixed up with states (in particular, they
shouldn't be used as a state identifier).

9 years agoRegenerated documentation (changed by previous commit).
Ulya Trofimovich [Wed, 20 May 2015 09:45:31 +0000 (10:45 +0100)]
Regenerated documentation (changed by previous commit).

9 years agoFinally removed auxiliary code generation pass to 'null device'.
Ulya Trofimovich [Wed, 20 May 2015 08:34:26 +0000 (09:34 +0100)]
Finally removed auxiliary code generation pass to 'null device'.

This pass was used to gather statistics:
    - which labels are used (to avoid 'unused label' warnings from
      C/C++ compiler)
    - in '-f' mode, how many times YYFILL is called (to generate
      dispatch to the arrpopriate YYFILL call and resume lexing from
      there)

This commit deals with second case: it makes counting YYFILL calls
independent of auxiliary pass. Counting relies on variable
're2c::last_fill_index', which is updated in 're2c::need' function
(note that it is crucial that 're2c::need' is always called prior
to generation of state dispatch).

Also fixed documentation for '-f'.

9 years agoPass only that part of output needed by 're2c::State::emit'.
Ulya Trofimovich [Tue, 19 May 2015 17:53:35 +0000 (18:53 +0100)]
Pass only that part of output needed by 're2c::State::emit'.

9 years agoFixed clang's "warning: declaration shadows a local variable [-Wshadow]"
Ulya Trofimovich [Tue, 19 May 2015 17:45:55 +0000 (18:45 +0100)]
Fixed clang's "warning: declaration shadows a local variable [-Wshadow]"

9 years ago're2c::emit_init' doesn't generate anything useful in .dot mode.
Ulya Trofimovich [Tue, 19 May 2015 17:39:04 +0000 (18:39 +0100)]
're2c::emit_init' doesn't generate anything useful in .dot mode.

9 years agoAnother part of tracking label usage moved out from codegen.
Ulya Trofimovich [Tue, 19 May 2015 17:19:24 +0000 (18:19 +0100)]
Another part of tracking label usage moved out from codegen.

This is part of effort to reduce code generation to 'null device'
(the same code is generated twice only to gather statistics on
label usage). In order to reduce this evil pass, we should be able
to track label usage before code generation.

9 years agoSimplified 're2c::Action' class and its usage.
Ulya Trofimovich [Tue, 19 May 2015 11:53:24 +0000 (12:53 +0100)]
Simplified 're2c::Action' class and its usage.

Replaced inheritance hierarchy with tagged union.

9 years agoFixed clang's "warning: declaration shadows a local variable [-Wshadow]"
Ulya Trofimovich [Mon, 18 May 2015 11:58:04 +0000 (12:58 +0100)]
Fixed clang's "warning: declaration shadows a local variable [-Wshadow]"

9 years agoDon't copy <*> regexps for each condition.
Ulya Trofimovich [Sat, 16 May 2015 11:01:58 +0000 (12:01 +0100)]
Don't copy <*> regexps for each condition.

There're two major things to care about in this situation:
1. <*> rules must have the lowest priority: in order to guarantee
   it, we re-iterate <*> regexps after all other rules have been
   parsed and fix <*> regexps priority.
2. <*> regexps must be compiled to instrictions separately for each
   condition: this is guaranteed by assigning them
   're2c::RegExp::PRIVATE' attribute.

Note that 're2c::RuleOp::accept' member stores rule priority.
These priorities don't have to be consecutive, only the right order
must be maintained. Later on in 're2c::DFA::prepare' they result in
consecutive 'yyaccept' values.

9 years agoForbid copying of 're2c::Substr'.
Ulya Trofimovich [Thu, 14 May 2015 17:20:13 +0000 (18:20 +0100)]
Forbid copying of 're2c::Substr'.

Removed useless methods (most of them became useless after
're2c::Str' removal) and obsolete autoconf check for 'strndup'.

Removed 'Scanner::token' methods. They used
'Scanner::check_token_length', which was pretty useless:
1. checking for the lower should have always succeed, because
   'Scanner::tok' is always set to buffer start in 'Scanner::fill'
   and if the token was too long, it's start will be lost anyway.
2. checking for the upper bound could fail if re2c dev passed some
   trash into it, but any normal function would do so and this is
   no particular reason to have special runtime checks here.
Now substrings are constructed in lexer, where all the lengths
and bounds are easier to verify from lexing context (for re2c dev).

9 years agoRemoved obsolete 're2c::Str' stuff.
Ulya Trofimovich [Thu, 14 May 2015 15:37:54 +0000 (16:37 +0100)]
Removed obsolete 're2c::Str' stuff.

9 years agoPass unquoted strings to parsing functions.
Ulya Trofimovich [Thu, 14 May 2015 12:58:29 +0000 (13:58 +0100)]
Pass unquoted strings to parsing functions.

In most cases re2c accepts single-quoted or double-quoted strings
in regexp specifications, but if flex-like syntax if enabled, then
re2c accepts unquoted strings.

Before this commit, functions that parse strings into regexps
expected quoted strings, and we had to add quotes in case of
flex-like syntax. That was very inconvenient and in fact
unnecessary, since the first thing parsing functions do is get rid
of quotes.

9 years agoNow 're2c::Token' uses 'std::string' instead of 're2c::Str'.
Ulya Trofimovich [Thu, 14 May 2015 12:16:24 +0000 (13:16 +0100)]
Now 're2c::Token' uses 'std::string' instead of 're2c::Str'.

9 years agoSimplified handling of named definitions in parser.
Ulya Trofimovich [Thu, 14 May 2015 11:25:24 +0000 (12:25 +0100)]
Simplified handling of named definitions in parser.

Don't bother with named definitions in lexer, just pass them as
strings to parser. Parser will recognize named definitions, insert
them into symbol table and handle conflicts.

Use simple 'std::map' instead 're2c::Symbol' class (that hides
symbol table in class static member).

Use 'std::string' instead of 're2c::Str'. Due to bison limitations
we have to pass pointers to strings allocated on the heap and
carefully destroy them. The whole thing is quite error prone, so
maybe I'll make a small slab allocator for parser later on.

9 years agoFixed mismatched new/delelte (found by valgrind).
Ulya Trofimovich [Thu, 14 May 2015 11:21:26 +0000 (12:21 +0100)]
Fixed mismatched new/delelte (found by valgrind).

What is allocated with 're2c::allocate<T>' (operator new), should
be freed with 'operator delete', not with 'delete' or 'delete []'.