[cfe-commits] r39234 - in /cfe/cfe/trunk: Parse/ParseDecl.cpp include/clang/Parse/DeclSpec.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:41:40 PDT 2007
Author: sabre
Date: Wed Jul 11 11:41:40 2007
New Revision: 39234
URL: http://llvm.org/viewvc/llvm-project?rev=39234&view=rev
Log:
finesse the interface to Declarator for function declarators so that the
declarator interface handles all alloc/dealloc issues related to the argument
list. Before the client had to alloc and Declarator did the dealloc.
Modified:
cfe/cfe/trunk/Parse/ParseDecl.cpp
cfe/cfe/trunk/include/clang/Parse/DeclSpec.h
Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=39234&r1=39233&r2=39234&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:41:40 2007
@@ -1048,18 +1048,11 @@
ExitScope();
}
- DeclaratorChunk::ParamInfo *ParamArray = 0;
- if (!ParamInfo.empty()) {
- ParamArray = new DeclaratorChunk::ParamInfo[ParamInfo.size()];
- memcpy(ParamArray, &ParamInfo[0], sizeof(ParamInfo[0])*ParamInfo.size());
- }
-
// Remember that we parsed a function type, and remember the attributes.
D.AddTypeInfo(DeclaratorChunk::getFunction(HasPrototype, IsVariadic,
- ParamInfo.size(), ParamArray,
+ &ParamInfo[0], ParamInfo.size(),
StartLoc));
-
// If we have the closing ')', eat it and we're done.
if (Tok.getKind() == tok::r_paren) {
ConsumeParen();
Modified: cfe/cfe/trunk/include/clang/Parse/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/DeclSpec.h?rev=39234&r1=39233&r2=39234&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/DeclSpec.h Wed Jul 11 11:41:40 2007
@@ -308,8 +308,8 @@
/// getArray - Return a DeclaratorChunk for an array.
///
static DeclaratorChunk getArray(unsigned TypeQuals, bool isStatic,
- bool isStar, void *NumElts,
- SourceLocation Loc) {
+ bool isStar, void *NumElts,
+ SourceLocation Loc) {
DeclaratorChunk I;
I.Kind = Array;
I.Loc = Loc;
@@ -320,18 +320,23 @@
return I;
}
- /// getFunction - Return a DeclaratorChunk for a function. ArgInfo should
- /// be a new[]'d array with NumArgs elements in it, or null if NumArgs is 0.
+ /// getFunction - Return a DeclaratorChunk for a function.
static DeclaratorChunk getFunction(bool hasProto, bool isVariadic,
- unsigned NumArgs, ParamInfo *ArgInfo,
- SourceLocation Loc) {
+ ParamInfo *ArgInfo, unsigned NumArgs,
+ SourceLocation Loc) {
DeclaratorChunk I;
I.Kind = Function;
I.Loc = Loc;
I.Fun.hasPrototype = hasProto;
I.Fun.isVariadic = isVariadic;
I.Fun.NumArgs = NumArgs;
- I.Fun.ArgInfo = ArgInfo;
+ I.Fun.ArgInfo = 0;
+
+ // new[] an argument array if needed.
+ if (NumArgs) {
+ I.Fun.ArgInfo = new DeclaratorChunk::ParamInfo[NumArgs];
+ memcpy(I.Fun.ArgInfo, ArgInfo, sizeof(ArgInfo[0])*NumArgs);
+ }
return I;
}
};
More information about the cfe-commits
mailing list