/[svn]/linuxsampler/trunk/src/scriptvm/parser_shared.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/scriptvm/parser_shared.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3746 - (show annotations) (download) (as text)
Sat Feb 15 20:00:55 2020 UTC (4 years, 2 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 4468 byte(s)
NKSP Parser: Fixed compiler warnings about memcpy() on dynamic objects.

1 /*
2 * Copyright (c) 2014-2020 Christian Schoenebeck
3 *
4 * http://www.linuxsampler.org
5 *
6 * This file is part of LinuxSampler and released under the same terms.
7 * See README file for details.
8 */
9
10 // types shared between auto generated lexer and parser ...
11
12 #ifndef LS_INSTRSCRIPTSPARSER_SHARED_H
13 #define LS_INSTRSCRIPTSPARSER_SHARED_H
14
15 #include <stdio.h>
16 #include "tree.h"
17
18 #if AC_APPLE_UNIVERSAL_BUILD
19 # include "parser.tab.h"
20 #else
21 # include "parser.h"
22 #endif
23
24 #include "../common/global_private.h"
25
26 struct _YYSTYPE {
27 union {
28 LinuxSampler::vmint iValue;
29 LinuxSampler::vmfloat fValue;
30 char* sValue;
31 struct {
32 LinuxSampler::vmint iValue;
33 LinuxSampler::MetricPrefix_t prefix[2];
34 LinuxSampler::StdUnit_t unit;
35 } iUnitValue;
36 struct {
37 LinuxSampler::vmfloat fValue;
38 LinuxSampler::MetricPrefix_t prefix[2];
39 LinuxSampler::StdUnit_t unit;
40 } fUnitValue;
41 };
42 LinuxSampler::EventHandlersRef nEventHandlers;
43 LinuxSampler::EventHandlerRef nEventHandler;
44 LinuxSampler::StatementsRef nStatements;
45 LinuxSampler::StatementRef nStatement;
46 LinuxSampler::FunctionCallRef nFunctionCall;
47 LinuxSampler::ArgsRef nArgs;
48 LinuxSampler::ExpressionRef nExpression;
49 LinuxSampler::CaseBranch nCaseBranch;
50 LinuxSampler::CaseBranches nCaseBranches;
51 LinuxSampler::Qualifier_t varQualifier;
52 };
53 #define YYSTYPE _YYSTYPE
54 #define yystype YYSTYPE ///< For backward compatibility.
55 #ifndef YYSTYPE_IS_DECLARED
56 # define YYSTYPE_IS_DECLARED ///< We tell the lexer / parser that we use our own data structure as defined above.
57 #endif
58
59 // custom Bison location type to support raw byte positions
60 struct _YYLTYPE {
61 int first_line;
62 int first_column;
63 int last_line;
64 int last_column;
65 int first_byte;
66 int length_bytes;
67 };
68 #define YYLTYPE _YYLTYPE
69 #define YYLTYPE_IS_DECLARED 1
70
71 // override Bison's default location passing to support raw byte positions
72 #define YYLLOC_DEFAULT(Cur, Rhs, N) \
73 do \
74 if (N) \
75 { \
76 (Cur).first_line = YYRHSLOC(Rhs, 1).first_line; \
77 (Cur).first_column = YYRHSLOC(Rhs, 1).first_column; \
78 (Cur).last_line = YYRHSLOC(Rhs, N).last_line; \
79 (Cur).last_column = YYRHSLOC(Rhs, N).last_column; \
80 (Cur).first_byte = YYRHSLOC(Rhs, 1).first_byte; \
81 (Cur).length_bytes = (YYRHSLOC(Rhs, N).first_byte - \
82 YYRHSLOC(Rhs, 1).first_byte) + \
83 YYRHSLOC(Rhs, N).length_bytes; \
84 } \
85 else \
86 { \
87 (Cur).first_line = (Cur).last_line = \
88 YYRHSLOC(Rhs, 0).last_line; \
89 (Cur).first_column = (Cur).last_column = \
90 YYRHSLOC(Rhs, 0).last_column; \
91 (Cur).first_byte = YYRHSLOC(Rhs, 0).first_byte; \
92 (Cur).length_bytes = YYRHSLOC(Rhs, 0).length_bytes; \
93 } \
94 while (0)
95
96 // Force YYCOPY() to use copy by value.
97 //
98 // By default YYCOPY() is using __builtin_memcpy, which is slightly problematic
99 // with our YYSTYPE (see above) since it has dynamic objects as member variables
100 // and hence __builtin_memcpy would overwrite their vpointer. In practice though
101 // this is more of a theoretical fix and probably just silences compiler
102 // warnings. So in practice __builtin_memcpy would probably not cause any
103 // misbehaviours, because it is expected that Bison generated parsers only use
104 // YYCOPY() to relocate the parser's stack (that is moving objects in memory),
105 // but not for really creating duplicates of any objects.
106 //
107 // In my benchmarks I did not encounter any measurable performance difference by
108 // this change, so shutting up the compiler wins for now.
109 #define YYCOPY(To, From, Count) \
110 do { \
111 for (YYSIZE_T i = 0; i < (Count); ++i) \
112 (To)[i] = (From)[i]; \
113 } while (YYID (0)); \
114
115 #endif // LS_INSTRSCRIPTSPARSER_SHARED_H

  ViewVC Help
Powered by ViewVC