@@ -289,7 +289,7 @@ void ScriptParser::readLinkerScript() {
289289void ScriptParser::readDefsym () {
290290 if (errCount (ctx))
291291 return ;
292- inExpr = true ;
292+ SaveAndRestore saved (lexState, State::Expr) ;
293293 StringRef name = readName ();
294294 expect (" =" );
295295 Expr e = readExpr ();
@@ -954,8 +954,8 @@ bool ScriptParser::readSectionDirective(OutputSection *cmd, StringRef tok) {
954954// https://sourceware.org/binutils/docs/ld/Output-Section-Type.html
955955void ScriptParser::readSectionAddressType (OutputSection *cmd) {
956956 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 );
959959 if (readSectionDirective (cmd, peek ()))
960960 return ;
961961 cmd->addrExpr = readExpr ();
@@ -965,7 +965,7 @@ void ScriptParser::readSectionAddressType(OutputSection *cmd) {
965965 }
966966
967967 if (consume (" (" )) {
968- SaveAndRestore saved (inExpr, true );
968+ SaveAndRestore saved (lexState, State::Expr );
969969 StringRef tok = peek ();
970970 if (!readSectionDirective (cmd, tok))
971971 setError (" unknown section directive: " + tok);
@@ -1087,10 +1087,10 @@ OutputDesc *ScriptParser::readOutputSectionDescription(StringRef outSec) {
10871087 osec->phdrs = readOutputSectionPhdrs ();
10881088
10891089 if (peek () == " =" || peek ().starts_with (" =" )) {
1090- inExpr = true ;
1090+ lexState = State::Expr ;
10911091 consume (" =" );
10921092 osec->filler = readFill ();
1093- inExpr = false ;
1093+ lexState = State::Script ;
10941094 }
10951095
10961096 // Consume optional comma following output section command.
@@ -1162,7 +1162,7 @@ SymbolAssignment *ScriptParser::readAssignment(StringRef tok) {
11621162 bool savedSeenRelroEnd = ctx.script ->seenRelroEnd ;
11631163 const StringRef op = peek ();
11641164 {
1165- SaveAndRestore saved (inExpr, true );
1165+ SaveAndRestore saved (lexState, State::Expr );
11661166 if (op.starts_with (" =" )) {
11671167 // Support = followed by an expression without whitespace.
11681168 cmd = readSymbolAssignment (unquote (tok));
@@ -1235,7 +1235,7 @@ SymbolAssignment *ScriptParser::readSymbolAssignment(StringRef name) {
12351235Expr ScriptParser::readExpr () {
12361236 // Our lexer is context-aware. Set the in-expression bit so that
12371237 // they apply different tokenization rules.
1238- SaveAndRestore saved (inExpr, true );
1238+ SaveAndRestore saved (lexState, State::Expr );
12391239 Expr e = readExpr1 (readPrimary (), 0 );
12401240 return e;
12411241}
@@ -1452,12 +1452,11 @@ std::pair<uint64_t, uint64_t> ScriptParser::readInputSectionFlags() {
14521452
14531453StringRef ScriptParser::readParenName () {
14541454 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;
14591458 expect (" )" );
1460- return tok ;
1459+ return name ;
14611460}
14621461
14631462static void checkIfExists (LinkerScript &script, const OutputSection &osec,
0 commit comments