[PATCH] D53969: [ELF] Use SaveAndRestore to simplify code
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 31 23:39:33 PDT 2018
MaskRay created this revision.
MaskRay added reviewers: ruiu, grimar.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D53969
Files:
ELF/ScriptParser.cpp
Index: ELF/ScriptParser.cpp
===================================================================
--- ELF/ScriptParser.cpp
+++ ELF/ScriptParser.cpp
@@ -31,6 +31,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/SaveAndRestore.h"
#include <cassert>
#include <limits>
#include <vector>
@@ -310,11 +311,9 @@
void ScriptParser::readAsNeeded() {
expect("(");
- bool Orig = Config->AsNeeded;
- Config->AsNeeded = true;
+ SaveAndRestore<bool> Restore(Config->AsNeeded, true);
while (!errorCount() && !consume(")"))
addFile(unquote(next()));
- Config->AsNeeded = Orig;
}
void ScriptParser::readEntry() {
@@ -333,11 +332,9 @@
}
void ScriptParser::readGroup() {
- bool Orig = InputFile::IsInGroup;
- InputFile::IsInGroup = true;
+ SaveAndRestore<bool> Restore(InputFile::IsInGroup, true);
readInput();
- InputFile::IsInGroup = Orig;
- if (!Orig)
+ if (!Restore.get())
++InputFile::NextGroupId;
}
@@ -939,10 +936,8 @@
Expr ScriptParser::readExpr() {
// Our lexer is context-aware. Set the in-expression bit so that
// they apply different tokenization rules.
- bool Orig = InExpr;
- InExpr = true;
+ SaveAndRestore<bool> Restore(InExpr, true);
Expr E = readExpr1(readPrimary(), 0);
- InExpr = Orig;
return E;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53969.172092.patch
Type: text/x-patch
Size: 1354 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181101/03052105/attachment.bin>
More information about the llvm-commits
mailing list