[llvm] r269286 - Refactor duplicated code. NFC.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu May 12 05:37:53 PDT 2016
Author: rafael
Date: Thu May 12 07:37:52 2016
New Revision: 269286
URL: http://llvm.org/viewvc/llvm-project?rev=269286&view=rev
Log:
Refactor duplicated code. NFC.
Linkage is always followed by visibility and dll storage.
Modified:
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/AsmParser/LLParser.h
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=269286&r1=269285&r2=269286&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu May 12 07:37:52 2016
@@ -454,11 +454,8 @@ bool LLParser::ParseUnnamedGlobal() {
unsigned Linkage, Visibility, DLLStorageClass;
GlobalVariable::ThreadLocalMode TLM;
bool UnnamedAddr;
- if (ParseOptionalLinkage(Linkage, HasLinkage) ||
- ParseOptionalVisibility(Visibility) ||
- ParseOptionalDLLStorageClass(DLLStorageClass) ||
- ParseOptionalThreadLocal(TLM) ||
- parseOptionalUnnamedAddr(UnnamedAddr))
+ if (ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass) ||
+ ParseOptionalThreadLocal(TLM) || parseOptionalUnnamedAddr(UnnamedAddr))
return true;
if (Lex.getKind() != lltok::kw_alias && Lex.getKind() != lltok::kw_ifunc)
@@ -484,11 +481,8 @@ bool LLParser::ParseNamedGlobal() {
GlobalVariable::ThreadLocalMode TLM;
bool UnnamedAddr;
if (ParseToken(lltok::equal, "expected '=' in global variable") ||
- ParseOptionalLinkage(Linkage, HasLinkage) ||
- ParseOptionalVisibility(Visibility) ||
- ParseOptionalDLLStorageClass(DLLStorageClass) ||
- ParseOptionalThreadLocal(TLM) ||
- parseOptionalUnnamedAddr(UnnamedAddr))
+ ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass) ||
+ ParseOptionalThreadLocal(TLM) || parseOptionalUnnamedAddr(UnnamedAddr))
return true;
if (Lex.getKind() != lltok::kw_alias && Lex.getKind() != lltok::kw_ifunc)
@@ -1535,10 +1529,14 @@ static unsigned parseOptionalLinkageAux(
/// ::= 'common'
/// ::= 'extern_weak'
/// ::= 'external'
-bool LLParser::ParseOptionalLinkage(unsigned &Res, bool &HasLinkage) {
+bool LLParser::ParseOptionalLinkage(unsigned &Res, bool &HasLinkage,
+ unsigned &Visibility,
+ unsigned &DLLStorageClass) {
Res = parseOptionalLinkageAux(Lex.getKind(), HasLinkage);
if (HasLinkage)
Lex.Lex();
+ ParseOptionalVisibility(Visibility);
+ ParseOptionalDLLStorageClass(DLLStorageClass);
return false;
}
@@ -1548,15 +1546,22 @@ bool LLParser::ParseOptionalLinkage(unsi
/// ::= 'hidden'
/// ::= 'protected'
///
-bool LLParser::ParseOptionalVisibility(unsigned &Res) {
+void LLParser::ParseOptionalVisibility(unsigned &Res) {
switch (Lex.getKind()) {
- default: Res = GlobalValue::DefaultVisibility; return false;
- case lltok::kw_default: Res = GlobalValue::DefaultVisibility; break;
- case lltok::kw_hidden: Res = GlobalValue::HiddenVisibility; break;
- case lltok::kw_protected: Res = GlobalValue::ProtectedVisibility; break;
+ default:
+ Res = GlobalValue::DefaultVisibility;
+ return;
+ case lltok::kw_default:
+ Res = GlobalValue::DefaultVisibility;
+ break;
+ case lltok::kw_hidden:
+ Res = GlobalValue::HiddenVisibility;
+ break;
+ case lltok::kw_protected:
+ Res = GlobalValue::ProtectedVisibility;
+ break;
}
Lex.Lex();
- return false;
}
/// ParseOptionalDLLStorageClass
@@ -1564,14 +1569,19 @@ bool LLParser::ParseOptionalVisibility(u
/// ::= 'dllimport'
/// ::= 'dllexport'
///
-bool LLParser::ParseOptionalDLLStorageClass(unsigned &Res) {
+void LLParser::ParseOptionalDLLStorageClass(unsigned &Res) {
switch (Lex.getKind()) {
- default: Res = GlobalValue::DefaultStorageClass; return false;
- case lltok::kw_dllimport: Res = GlobalValue::DLLImportStorageClass; break;
- case lltok::kw_dllexport: Res = GlobalValue::DLLExportStorageClass; break;
+ default:
+ Res = GlobalValue::DefaultStorageClass;
+ return;
+ case lltok::kw_dllimport:
+ Res = GlobalValue::DLLImportStorageClass;
+ break;
+ case lltok::kw_dllexport:
+ Res = GlobalValue::DLLExportStorageClass;
+ break;
}
Lex.Lex();
- return false;
}
/// ParseOptionalCallingConv
@@ -4469,13 +4479,11 @@ bool LLParser::ParseFunctionHeader(Funct
unsigned DLLStorageClass;
AttrBuilder RetAttrs;
unsigned CC;
+ bool HasLinkage;
Type *RetType = nullptr;
LocTy RetTypeLoc = Lex.getLoc();
- if (ParseOptionalLinkage(Linkage) ||
- ParseOptionalVisibility(Visibility) ||
- ParseOptionalDLLStorageClass(DLLStorageClass) ||
- ParseOptionalCallingConv(CC) ||
- ParseOptionalReturnAttrs(RetAttrs) ||
+ if (ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass) ||
+ ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) ||
ParseType(RetType, RetTypeLoc, true /*void allowed*/))
return true;
Modified: llvm/trunk/lib/AsmParser/LLParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.h?rev=269286&r1=269285&r2=269286&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.h (original)
+++ llvm/trunk/lib/AsmParser/LLParser.h Thu May 12 07:37:52 2016
@@ -232,12 +232,10 @@ namespace llvm {
bool ParseOptionalAddrSpace(unsigned &AddrSpace);
bool ParseOptionalParamAttrs(AttrBuilder &B);
bool ParseOptionalReturnAttrs(AttrBuilder &B);
- bool ParseOptionalLinkage(unsigned &Linkage, bool &HasLinkage);
- bool ParseOptionalLinkage(unsigned &Linkage) {
- bool HasLinkage; return ParseOptionalLinkage(Linkage, HasLinkage);
- }
- bool ParseOptionalVisibility(unsigned &Visibility);
- bool ParseOptionalDLLStorageClass(unsigned &DLLStorageClass);
+ bool ParseOptionalLinkage(unsigned &Linkage, bool &HasLinkage,
+ unsigned &Visibility, unsigned &DLLStorageClass);
+ void ParseOptionalVisibility(unsigned &Visibility);
+ void ParseOptionalDLLStorageClass(unsigned &DLLStorageClass);
bool ParseOptionalCallingConv(unsigned &CC);
bool ParseOptionalAlignment(unsigned &Alignment);
bool ParseOptionalDerefAttrBytes(lltok::Kind AttrKind, uint64_t &Bytes);
More information about the llvm-commits
mailing list