@@ -289,7 +289,7 @@ void ScriptParser::readLinkerScript() {
289
289
void ScriptParser::readDefsym () {
290
290
if (errCount (ctx))
291
291
return ;
292
- inExpr = true ;
292
+ SaveAndRestore saved (lexState, State::Expr) ;
293
293
StringRef name = readName ();
294
294
expect (" =" );
295
295
Expr e = readExpr ();
@@ -954,8 +954,8 @@ bool ScriptParser::readSectionDirective(OutputSection *cmd, StringRef tok) {
954
954
// https://sourceware.org/binutils/docs/ld/Output-Section-Type.html
955
955
void ScriptParser::readSectionAddressType (OutputSection *cmd) {
956
956
if (consume (" (" )) {
957
- // Temporarily set inExpr to support TYPE=<value> without spaces.
958
- SaveAndRestore saved (inExpr, true );
957
+ // Temporarily set lexState to support TYPE=<value> without spaces.
958
+ SaveAndRestore saved (lexState, State::Expr );
959
959
if (readSectionDirective (cmd, peek ()))
960
960
return ;
961
961
cmd->addrExpr = readExpr ();
@@ -965,7 +965,7 @@ void ScriptParser::readSectionAddressType(OutputSection *cmd) {
965
965
}
966
966
967
967
if (consume (" (" )) {
968
- SaveAndRestore saved (inExpr, true );
968
+ SaveAndRestore saved (lexState, State::Expr );
969
969
StringRef tok = peek ();
970
970
if (!readSectionDirective (cmd, tok))
971
971
setError (" unknown section directive: " + tok);
@@ -1087,10 +1087,10 @@ OutputDesc *ScriptParser::readOutputSectionDescription(StringRef outSec) {
1087
1087
osec->phdrs = readOutputSectionPhdrs ();
1088
1088
1089
1089
if (peek () == " =" || peek ().starts_with (" =" )) {
1090
- inExpr = true ;
1090
+ lexState = State::Expr ;
1091
1091
consume (" =" );
1092
1092
osec->filler = readFill ();
1093
- inExpr = false ;
1093
+ lexState = State::Script ;
1094
1094
}
1095
1095
1096
1096
// Consume optional comma following output section command.
@@ -1162,7 +1162,7 @@ SymbolAssignment *ScriptParser::readAssignment(StringRef tok) {
1162
1162
bool savedSeenRelroEnd = ctx.script ->seenRelroEnd ;
1163
1163
const StringRef op = peek ();
1164
1164
{
1165
- SaveAndRestore saved (inExpr, true );
1165
+ SaveAndRestore saved (lexState, State::Expr );
1166
1166
if (op.starts_with (" =" )) {
1167
1167
// Support = followed by an expression without whitespace.
1168
1168
cmd = readSymbolAssignment (unquote (tok));
@@ -1235,7 +1235,7 @@ SymbolAssignment *ScriptParser::readSymbolAssignment(StringRef name) {
1235
1235
Expr ScriptParser::readExpr () {
1236
1236
// Our lexer is context-aware. Set the in-expression bit so that
1237
1237
// they apply different tokenization rules.
1238
- SaveAndRestore saved (inExpr, true );
1238
+ SaveAndRestore saved (lexState, State::Expr );
1239
1239
Expr e = readExpr1 (readPrimary (), 0 );
1240
1240
return e;
1241
1241
}
@@ -1452,12 +1452,11 @@ std::pair<uint64_t, uint64_t> ScriptParser::readInputSectionFlags() {
1452
1452
1453
1453
StringRef ScriptParser::readParenName () {
1454
1454
expect (" (" );
1455
- bool orig = inExpr;
1456
- inExpr = false ;
1457
- StringRef tok = readName ();
1458
- inExpr = orig;
1455
+ auto saved = std::exchange (lexState, State::Script);
1456
+ StringRef name = readName ();
1457
+ lexState = saved;
1459
1458
expect (" )" );
1460
- return tok ;
1459
+ return name ;
1461
1460
}
1462
1461
1463
1462
static void checkIfExists (LinkerScript &script, const OutputSection &osec,
0 commit comments