Commit Graph

105 Commits

Author SHA1 Message Date
Joakim Hove
bdb1313f41 RawKeyword getRecord( int ) -> getFirstRecord()
The general loop through all raw records should be based on the iterator
interface of the RawKeyword, but to resolve INCLUDE statements we have
implemented a special case method to get the first record.
2016-04-04 16:21:52 +02:00
Joakim Hove
e57d61468d Added non const record iterators to RawKeyword. 2016-04-03 22:00:30 +02:00
Jørgen Kvalsvik
8e4e9b15d8 ReadValueToken correctly parses numbers
Changes the implementation of numbers parsing from std::atoi/f to
std::strtod/l. These support setting the optional end-of-string pointer
which are used to determine if a parsing was successful or not. This has
the nice side effect of *greatly* simplifying the logic, at the expense
of some C-style details.

Tests added to verify that the different edge cases are handled
properly.
2016-04-01 10:13:37 +02:00
Jørgen Kvalsvik
046afdd3be RawKeyword iterator support
Since RawRecords now has automatic storage, managed by std::list,
offering iterators is feasible. The random access
RawKeyword::getRecord's real use was accessing the records in order,
which now is handled via iterators.
2016-03-30 12:47:33 +02:00
Jørgen Kvalsvik
83ae276d67 Fix string_view iterator invalidation bug
By changing the underlying storage of RawKeyword to std::list, we ensure
that the RawRecords aren't reallocated and moved, preserving the
validity of string_view's. This changes the access complexity of
RawRecord from O(1) to O(n).
2016-03-30 12:31:00 +02:00
Jørgen Kvalsvik
9e76ec5f78 Inline hot-but-trivial functions
These functions are called a lot and are trivial accessors to the
underlying containers. By opening them for inlining we get a decent
performance benefit "for free" via optimisation opportunities.
2016-03-22 14:45:17 +01:00
Jørgen Kvalsvik
0da5cadc75 RawRecords auto store, strings moved to RawRecord
The accumulated strings are moved into RawRecords, which reduces
execution time (rough measurements indicates 4-8%). To facilitate this,
RawRecords are stored directly in the vector in favour of via
shared_ptrs.
2016-03-22 08:58:48 +01:00
Jørgen Kvalsvik
aa064a9050 Fix buffer overflow vulnerability
An attacker using very long decimal integers as input could trigger a
buffer overflow write during int/double parsing.

The vulnerability has been fixed and raw buffer boundaries are checked.
Additionally, integer buffer size is determined by platform 'int' width.
'double' uses a heuristic to support both pure decimal formats (up to 64
characters long) and float formats.
2016-03-15 16:42:02 +01:00
Atgeirr Flø Rasmussen
78e0870bad Use std::list instead of std::vector to fix push_front().
The push_front() method can cause reallocation of expanded_items,
thereby invalidating iterators already stored in m_recordItems.
Switching to std::list fixes this.
2016-03-14 14:54:29 +01:00
Atgeirr Flø Rasmussen
f23af386cf Add missing include, remove unused function. 2016-03-14 13:22:22 +01:00
Jørgen Kvalsvik
55b46da658 Moved RawRecord::isTerminator out of interface
This feature is internal to the raw records and is removed from its
public interface.
2016-03-14 08:29:54 +01:00
Jørgen Kvalsvik
2a650d5972 RawRecord refactoring
Some simple refactoring to remove a redundant check and clean up some
initialisation routines.
2016-03-14 08:29:54 +01:00
Jørgen Kvalsvik
dc094cbb16 More efficient findTerminatingSlash
Uses some heuristics and quick exists to avoid always paying worst case
cost for finding terminating slash.
2016-03-14 08:29:54 +01:00
Jørgen Kvalsvik
28eb195ac3 readValueToken< double > split into fast/slow path.
readValueToken spent almost half its time dealing with weirdly formed or
broken floats. Now has a shorter path that can early return a
successfully parsed float and only do slow handling of cases that need
it (notably zero, fortran style exponent and errors).
2016-03-14 08:29:54 +01:00
Jørgen Kvalsvik
38f88b4e14 RawKeyword::isTerminator uses is_separator 2016-03-14 08:29:54 +01:00
Jørgen Kvalsvik
1d1715b421 RawConsts::is_separator function
This replaces the inefficient RawConsts::separators.find( char ) with an
availble, efficient and inlinable is_separator.
2016-03-14 08:29:53 +01:00
Jørgen Kvalsvik
93b7c0739b Replace boost::lexical_cast<> with std functions
The boost provided lexical cast are inefficient and is shown to be a
slowdown in the inner loop. Replaces them with std::atoi/std::atof and
some simple correctness checking.
2016-03-14 08:29:53 +01:00
Jørgen Kvalsvik
e4ddf884f1 Using operator+ and stream operators 2016-03-14 08:29:53 +01:00
Jørgen Kvalsvik
798084676a RawRecord uses string_view internally
Modifies RawRecord to internally use string_view instead of copies of
the substrings. This *vastly* reduces copying in the processing of each
record and subsequently improves performance. Reduces total memory usage
in Deck construction.
2016-03-14 08:29:53 +01:00
Jørgen Kvalsvik
d0d4a74d31 Moves readValueToken implementation to source file
The templated readValueToken has been moved to source file, and uses
explicit instantiation and linking. The deprecated float specialisation
has been removed.
2016-03-04 18:27:44 +01:00
Jørgen Kvalsvik
4b98943665 Replaces unecessary header includes with fwd decls
Every header is self-contained and includes only what it must to
function, relying on users include what they need in source files,
adopting a pay-what-you-use model (in particular for internal
dependencies).
2016-01-26 13:23:22 +01:00
Tor Harald Sandve
4ae5049639 Add <algorithm> to make it compile for gcc 4-6 2015-08-05 08:48:03 +02:00
Andreas Lauser
e32f8b5742 make the 'd' exponent specifier the slow path
i.e. first try to convert it normally and only if this fails, replace
'd' by 'e' and try again.

this is because the slowdown when always taking the second path was
about 7 to 9% for the Norne deck on my machine. (I think this is quite
surprising.)

thanks to [at]joakim-hove for the hint.
2015-07-24 11:36:36 +02:00
Andreas Lauser
1d388b3b78 implement support for fortran-style 'd' exponent indicators
also, extend the corresponding unit test.
2015-07-23 16:18:07 +02:00
Arne Morten Kvarving
2acd2db5d0 changed: rename Parser to opmparser for consistency 2015-05-26 13:53:54 +02:00
Arne Morten Kvarving
9e96127705 change how tests are added in the build system
- use a opm-macro to reduce code duplication
- add a 'test-suite' target which builds tests. for use if BUILD_TESTING
  is 0.
- add a 'check' target which builds tests, then executes them
2015-05-26 13:07:44 +02:00
Andreas Lauser
e12a0aab1b parser main loop: handle unknown sized keywords in a better way 2014-12-19 10:59:12 +01:00
Andreas Lauser
017e582e5a handle comments and empty lines directly in the parser's main loop
note that comment handling is currently a bit too simplistic as stuff
like

FOO
'-- hello' /

won't work. as far as I can see, this is not different from the state
before this patch, though.
2014-12-09 11:54:55 +01:00
Andreas Lauser
ea38a25af4 remove all trailing white space
this is just the result of

```
find -iname "*.[ch]pp" | xargs sed -i "s/ *$//"
find opm/parser/share/keywords -type f |  xargs sed -i "s/ *$//"
```

so if it causes conflicts with other patches, the others should get
priority. The rationale behind this patch is that some people tell
their editor to remove white space which leads to larger than
necessary patches...
2014-12-08 16:34:28 +01:00
Andreas Lauser
ead7e0a8c9 make the parser case-insensitive
i.e., make keywords ALL_UPPERCASE before using them because Eclipse
seems to be case-insensitive (although this is one of its undocumented
features...)
2014-11-07 14:24:12 +01:00
Andreas Lauser
fff0c9cdf0 Revert "also eat keywords containing lowercase letters"
this was inadvertedly merged. the real fix is to make the parser
case-insensitive...
2014-11-07 14:23:08 +01:00
Andreas Lauser
382d449ebb also eat keywords containing lowercase letters
The Norne deck actually exhibits this atrocity in form of the
'fluxnum' keyword in the file 'INCLUDE/PETRO/FLUXNUM_0704.prop'.

I don't know if Eclipse cares about the case of the keywords, but
opm-parser currently does for sure. (If Eclipse turns out to be
case-insensitive, the easiest fix for us is to just make all keywords
ALL_UPPERCASE...)
2014-11-07 12:58:04 +01:00
Andreas Lauser
f8946b9e7e RawKeyword: rename tryParseKeyword() to isKeywordPrefix()
because the method never tried to *parse* the data as a keyword but always
returned whether the *calling* code should try to parse it...
2014-11-05 13:11:52 +01:00
Andreas Lauser
6eb3421f38 Handle quotes better
This allows to arbitrary characters like stars into strings. e.g.

MYKEYWORD
'123*456' 2*'Hello, World! (*)' /

is now a valid record with three strings while it threw an exception
before.

This patch works by transferring the removal of the quotes from the
RawDeck class to the readValueToken<T>() function which now has a
specialization for strings that deals with quotes. One small
complication is that the RawDeck needs to be adapted in order not to
split tokens in the middle of strings.

Finally, the StarToken class does not deal with the conversion from
string to the value type of the item anymore which allows it to become
a normal class instead of a template...
2014-11-05 13:05:22 +01:00
Andreas Lauser
435e6aa6c5 extend "StarToken" class
that's because not every token which contains a star represents an
repetion, e.g.

'PROD*'

and

'123*456'

(with the quotes) are strings...
2014-09-15 12:27:28 +02:00
Andreas Lauser
c2329b72ba add a few missing includes
these includes are required by the headers. If the affected files
would have been included without the headers included before, a
compiler error would have been produced.
2014-08-25 14:07:28 +02:00
Andreas Lauser
523d5d049f fix ugly bug which prevented deck keyword names from having a minus in them
i.e. MULT[XYZ]- was trimmed to MULT[XYZ]. Also, the RawKeyword now
uses ParserKeyword::isValidDeckName() instead of a regular expression
which makes it automatically consistent and also should make it
slightly faster...
2014-07-15 16:47:31 +02:00
Kristian Flikka
697c273c19 OPM-94: Removed specialized int,double,string implementations, one generic covers the same 2014-07-10 13:24:49 +02:00
Arne Morten Kvarving
d85782d9f5 fixed: keep a copy instead of a reference
storing string references are not a good idea, since temporaries are
often used. fixes RawRecordTest on my box
2014-06-05 11:48:17 +02:00
Kristian Flikka
82a38c1cc8 Merge pull request #208 from AtleH/wellnamewithwildcard
Added wildcard support in WCONINJE and WCONPROD
2014-05-16 12:28:39 +02:00
Arne Morten Kvarving
8cb2646995 fixed: initialize members 2014-05-15 14:46:16 +02:00
Atle Haugan
344d02ad1c Add support for wildcard in WCONPROD and WCONINJE keywords. 2014-05-06 09:54:37 +02:00
Atgeirr Flø Rasmussen
e3d167048f Commented out unused function arguments. 2014-04-15 09:48:19 +02:00
Joakim Hove
5becf79dd1 The ParserKeyword->parse() method will throw if the raw input argument is not finished.
Requires several changes to assure that the rawkeyword instances are
marked as finished before reacing the ParserKeyword->parse method.
2014-04-11 13:42:22 +02:00
Atgeirr Flø Rasmussen
2df1761922 Deleted unneeded default constructor.
Its implementation was buggy, initialising references to temporary objects.
2014-04-04 10:05:04 +02:00
Atle Haugan
9ac0401af5 Support for PATHS keyword - first take 2014-02-21 12:56:20 +01:00
Kristian Flikka
15682a71df Merge pull request #114 from joakim-hove/valgrind
Valgrind
2014-02-06 16:39:30 +01:00
Arne Morten Kvarving
4a9c18ac9f run tests through valgrind 2014-01-27 15:16:34 +01:00
Atle Haugan
ef11a2331f OPM-17: First attempt to handle END and ENDINC keywords 2014-01-24 10:01:17 +01:00
Kristian Flikka
c74a86b3f5 Merge pull request #68 from joakim-hove/units
Units
2013-12-09 01:12:33 -08:00