detemplatify setArgumentList and some other cleanups.
llvm-svn: 65187
This commit is contained in:
parent
5e5503f5da
commit
f87c510cc9
|
@ -72,16 +72,26 @@ private:
|
|||
/// been used, or if it is not defined in the main file. This is used to
|
||||
/// emit -Wunused-macros diagnostics.
|
||||
bool IsUsed : 1;
|
||||
public:
|
||||
MacroInfo(SourceLocation DefLoc);
|
||||
|
||||
~MacroInfo() {
|
||||
assert(ArgumentList == 0 && "Didn't call destroy before dtor!");
|
||||
}
|
||||
|
||||
void Destroy() {
|
||||
public:
|
||||
MacroInfo(SourceLocation DefLoc);
|
||||
|
||||
/// FreeArgumentList - Free the argument list of the macro, restoring it to a
|
||||
/// state where it can be reused for other devious purposes.
|
||||
void FreeArgumentList() {
|
||||
delete[] ArgumentList;
|
||||
ArgumentList = 0;
|
||||
NumArguments = 0;
|
||||
}
|
||||
|
||||
/// Destroy - destroy this MacroInfo object.
|
||||
void Destroy() {
|
||||
FreeArgumentList();
|
||||
this->~MacroInfo();
|
||||
}
|
||||
|
||||
/// getDefinitionLoc - Return the location that the macro was defined at.
|
||||
|
@ -107,15 +117,15 @@ public:
|
|||
|
||||
/// setArgumentList - Set the specified list of identifiers as the argument
|
||||
/// list for this macro.
|
||||
template<typename ItTy>
|
||||
void setArgumentList(ItTy ArgBegin, ItTy ArgEnd) {
|
||||
assert(ArgumentList == 0 && "Argument list already set!");
|
||||
unsigned NumArgs = ArgEnd-ArgBegin;
|
||||
void setArgumentList(IdentifierInfo* const *List, unsigned NumArgs) {
|
||||
assert(ArgumentList == 0 && NumArguments == 0 &&
|
||||
"Argument list already set!");
|
||||
if (NumArgs == 0) return;
|
||||
|
||||
NumArguments = NumArgs;
|
||||
ArgumentList = new IdentifierInfo*[NumArgs];
|
||||
for (unsigned i = 0; ArgBegin != ArgEnd; ++i, ++ArgBegin)
|
||||
ArgumentList[i] = *ArgBegin;
|
||||
for (unsigned i = 0; i != NumArgs; ++i)
|
||||
ArgumentList[i] = List[i];
|
||||
}
|
||||
|
||||
/// Arguments - The list of arguments for a function-like macro. This can be
|
||||
|
|
|
@ -40,7 +40,7 @@ MacroInfo *Preprocessor::AllocateMacroInfo(SourceLocation L) {
|
|||
/// be reused for allocating new MacroInfo objects.
|
||||
void Preprocessor::ReleaseMacroInfo(MacroInfo* MI) {
|
||||
MICache.push_back(MI);
|
||||
MI->Destroy();
|
||||
MI->FreeArgumentList();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1097,10 +1097,8 @@ bool Preprocessor::ReadMacroDefinitionArgList(MacroInfo *MI) {
|
|||
switch (Tok.getKind()) {
|
||||
case tok::r_paren:
|
||||
// Found the end of the argument list.
|
||||
if (Arguments.empty()) { // #define FOO()
|
||||
MI->setArgumentList(Arguments.begin(), Arguments.end());
|
||||
if (Arguments.empty()) // #define FOO()
|
||||
return false;
|
||||
}
|
||||
// Otherwise we have #define FOO(A,)
|
||||
Diag(Tok, diag::err_pp_expected_ident_in_arg_list);
|
||||
return true;
|
||||
|
@ -1117,7 +1115,7 @@ bool Preprocessor::ReadMacroDefinitionArgList(MacroInfo *MI) {
|
|||
// Add the __VA_ARGS__ identifier as an argument.
|
||||
Arguments.push_back(Ident__VA_ARGS__);
|
||||
MI->setIsC99Varargs();
|
||||
MI->setArgumentList(Arguments.begin(), Arguments.end());
|
||||
MI->setArgumentList(&Arguments[0], Arguments.size());
|
||||
return false;
|
||||
case tok::eom: // #define X(
|
||||
Diag(Tok, diag::err_pp_missing_rparen_in_macro_def);
|
||||
|
@ -1151,7 +1149,7 @@ bool Preprocessor::ReadMacroDefinitionArgList(MacroInfo *MI) {
|
|||
Diag(Tok, diag::err_pp_expected_comma_in_arg_list);
|
||||
return true;
|
||||
case tok::r_paren: // #define X(A)
|
||||
MI->setArgumentList(Arguments.begin(), Arguments.end());
|
||||
MI->setArgumentList(&Arguments[0], Arguments.size());
|
||||
return false;
|
||||
case tok::comma: // #define X(A,
|
||||
break;
|
||||
|
@ -1167,7 +1165,7 @@ bool Preprocessor::ReadMacroDefinitionArgList(MacroInfo *MI) {
|
|||
}
|
||||
|
||||
MI->setIsGNUVarargs();
|
||||
MI->setArgumentList(Arguments.begin(), Arguments.end());
|
||||
MI->setArgumentList(&Arguments[0], Arguments.size());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,6 @@ Preprocessor::~Preprocessor() {
|
|||
// destroyed. We still need to run the dstor, however, to free
|
||||
// memory alocated by MacroInfo.
|
||||
I->second->Destroy();
|
||||
I->second->~MacroInfo();
|
||||
I->first->setHasMacroDefinition(false);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue