[cfe-commits] r72085 - in /cfe/trunk/tools/clang-cc: CacheTokens.cpp PrintParserCallbacks.cpp PrintPreprocessedOutput.cpp RewriteMacros.cpp RewriteTest.cpp clang-cc.cpp clang-cc.h
Eli Friedman
eli.friedman at gmail.com
Mon May 18 18:02:07 PDT 2009
Author: efriedma
Date: Mon May 18 20:02:07 2009
New Revision: 72085
URL: http://llvm.org/viewvc/llvm-project?rev=72085&view=rev
Log:
Switch some utilities in clang-cc to take a stream instead of a
filename (or unconditionally using stdout).
Modified:
cfe/trunk/tools/clang-cc/CacheTokens.cpp
cfe/trunk/tools/clang-cc/PrintParserCallbacks.cpp
cfe/trunk/tools/clang-cc/PrintPreprocessedOutput.cpp
cfe/trunk/tools/clang-cc/RewriteMacros.cpp
cfe/trunk/tools/clang-cc/RewriteTest.cpp
cfe/trunk/tools/clang-cc/clang-cc.cpp
cfe/trunk/tools/clang-cc/clang-cc.h
Modified: cfe/trunk/tools/clang-cc/CacheTokens.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/CacheTokens.cpp?rev=72085&r1=72084&r2=72085&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/CacheTokens.cpp (original)
+++ cfe/trunk/tools/clang-cc/CacheTokens.cpp Mon May 18 20:02:07 2009
@@ -535,16 +535,7 @@
} // end anonymous namespace
-void clang::CacheTokens(Preprocessor &PP, const std::string &OutFile) {
- // Open up the PTH file.
- std::string ErrMsg;
- llvm::raw_fd_ostream Out(OutFile.c_str(), true, ErrMsg);
-
- if (!ErrMsg.empty()) {
- llvm::errs() << "PTH error: " << ErrMsg << "\n";
- return;
- }
-
+void clang::CacheTokens(Preprocessor &PP, llvm::raw_fd_ostream* OS) {
// Get the name of the main file.
const SourceManager &SrcMgr = PP.getSourceManager();
const FileEntry *MainFile = SrcMgr.getFileEntryForID(SrcMgr.getMainFileID());
@@ -560,7 +551,7 @@
}
// Create the PTHWriter.
- PTHWriter PW(Out, PP);
+ PTHWriter PW(*OS, PP);
// Install the 'stat' system call listener in the FileManager.
PP.getFileManager().setStatCache(new StatListener(PW.getPM()));
Modified: cfe/trunk/tools/clang-cc/PrintParserCallbacks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/PrintParserCallbacks.cpp?rev=72085&r1=72084&r2=72085&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/PrintParserCallbacks.cpp (original)
+++ cfe/trunk/tools/clang-cc/PrintParserCallbacks.cpp Mon May 18 20:02:07 2009
@@ -15,14 +15,16 @@
#include "clang-cc.h"
#include "clang/Parse/Action.h"
#include "clang/Parse/DeclSpec.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
using namespace clang;
namespace {
class ParserPrintActions : public MinimalAction {
-
+ llvm::raw_ostream& Out;
+
public:
- ParserPrintActions(Preprocessor &PP) : MinimalAction(PP) {}
+ ParserPrintActions(Preprocessor &PP, llvm::raw_ostream& OS)
+ : MinimalAction(PP), Out(OS) {}
// Printing Functions which also must call MinimalAction
@@ -30,13 +32,13 @@
/// and 'Init' specifies the initializer if any. This is for things like:
/// "int X = 4" or "typedef int foo".
virtual DeclPtrTy ActOnDeclarator(Scope *S, Declarator &D) {
- llvm::cout << __FUNCTION__ << " ";
+ Out << __FUNCTION__ << " ";
if (IdentifierInfo *II = D.getIdentifier()) {
- llvm::cout << "'" << II->getName() << "'";
+ Out << "'" << II->getName() << "'";
} else {
- llvm::cout << "<anon>";
+ Out << "<anon>";
}
- llvm::cout << "\n";
+ Out << "\n";
// Pass up to EmptyActions so that the symbol table is maintained right.
return MinimalAction::ActOnDeclarator(S, D);
@@ -44,14 +46,14 @@
/// ActOnPopScope - This callback is called immediately before the specified
/// scope is popped and deleted.
virtual void ActOnPopScope(SourceLocation Loc, Scope *S) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return MinimalAction::ActOnPopScope(Loc, S);
}
/// ActOnTranslationUnitScope - This callback is called once, immediately
/// after creating the translation unit scope (in Parser::Initialize).
virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
MinimalAction::ActOnTranslationUnitScope(Loc, S);
}
@@ -65,7 +67,7 @@
unsigned NumProtocols,
SourceLocation EndProtoLoc,
AttributeList *AttrList) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return MinimalAction::ActOnStartClassInterface(AtInterfaceLoc,
ClassName, ClassLoc,
SuperName, SuperLoc,
@@ -78,7 +80,7 @@
Action::DeclPtrTy ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
IdentifierInfo **IdentList,
unsigned NumElts) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return MinimalAction::ActOnForwardClassDeclaration(AtClassLoc, IdentList,
NumElts);
}
@@ -90,13 +92,13 @@
/// with prototypes. S is the function prototype scope for the
/// parameters (C++ [basic.scope.proto]).
virtual DeclPtrTy ActOnParamDeclarator(Scope *S, Declarator &D) {
- llvm::cout << __FUNCTION__ << " ";
+ Out << __FUNCTION__ << " ";
if (IdentifierInfo *II = D.getIdentifier()) {
- llvm::cout << "'" << II->getName() << "'";
+ Out << "'" << II->getName() << "'";
} else {
- llvm::cout << "<anon>";
+ Out << "<anon>";
}
- llvm::cout << "\n";
+ Out << "\n";
return DeclPtrTy();
}
@@ -108,7 +110,7 @@
/// initializer. The declaration above should still result in a warning,
/// since the reference to "xx" is uninitialized.
virtual void AddInitializerToDecl(DeclPtrTy Dcl, ExprArg Init) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
}
/// FinalizeDeclaratorGroup - After a sequence of declarators are parsed,
@@ -116,7 +118,7 @@
/// a whole.
virtual DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, DeclPtrTy *Group,
unsigned NumDecls) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return DeclGroupPtrTy();
}
@@ -125,38 +127,38 @@
/// information about formal arguments that are part of this function.
virtual DeclPtrTy ActOnStartOfFunctionDef(Scope *FnBodyScope,
Declarator &D){
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return DeclPtrTy();
}
/// ActOnStartOfFunctionDef - This is called at the start of a function
/// definition, after the FunctionDecl has already been created.
virtual DeclPtrTy ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return DeclPtrTy();
}
virtual void ActOnStartOfObjCMethodDef(Scope *FnBodyScope, DeclPtrTy D) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
}
/// ActOnFunctionDefBody - This is called when a function body has completed
/// parsing. Decl is the DeclTy returned by ParseStartOfFunctionDef.
virtual DeclPtrTy ActOnFinishFunctionBody(DeclPtrTy Decl, StmtArg Body) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return DeclPtrTy();
}
virtual DeclPtrTy ActOnFileScopeAsmDecl(SourceLocation Loc,
ExprArg AsmString) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return DeclPtrTy();
}
/// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
/// no declarator (e.g. "struct foo;") is parsed.
virtual DeclPtrTy ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return DeclPtrTy();
}
@@ -169,7 +171,7 @@
SourceLocation RBrace, const char *Lang,
unsigned StrSize,
DeclPtrTy *Decls, unsigned NumDecls) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return DeclPtrTy();
}
@@ -186,7 +188,7 @@
//===------------------------------------------------------------------===//
virtual TypeResult ActOnTypeName(Scope *S, Declarator &D) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return TypeResult();
}
@@ -196,7 +198,7 @@
AttributeList *Attr, AccessSpecifier AS) {
// TagType is an instance of DeclSpec::TST, indicating what kind of tag this
// is (struct/union/enum/class).
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return DeclPtrTy();
}
@@ -205,20 +207,20 @@
virtual void ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart,
IdentifierInfo *ClassName,
llvm::SmallVectorImpl<DeclPtrTy> &Decls) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
}
virtual DeclPtrTy ActOnField(Scope *S, DeclPtrTy TagD,
SourceLocation DeclStart,
Declarator &D, ExprTy *BitfieldWidth) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return DeclPtrTy();
}
virtual DeclPtrTy ActOnIvar(Scope *S, SourceLocation DeclStart,
Declarator &D, ExprTy *BitfieldWidth,
tok::ObjCKeywordKind visibility) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return DeclPtrTy();
}
@@ -226,21 +228,21 @@
DeclPtrTy *Fields, unsigned NumFields,
SourceLocation LBrac, SourceLocation RBrac,
AttributeList *AttrList) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
}
virtual DeclPtrTy ActOnEnumConstant(Scope *S, DeclPtrTy EnumDecl,
DeclPtrTy LastEnumConstant,
SourceLocation IdLoc,IdentifierInfo *Id,
SourceLocation EqualLoc, ExprTy *Val) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return DeclPtrTy();
}
virtual void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
SourceLocation RBraceLoc, DeclPtrTy EnumDecl,
DeclPtrTy *Elements, unsigned NumElements) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
}
//===------------------------------------------------------------------===//
@@ -248,7 +250,7 @@
//===------------------------------------------------------------------===//
virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
@@ -256,18 +258,18 @@
SourceLocation R,
MultiStmtArg Elts,
bool isStmtExpr) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnDeclStmt(DeclGroupPtrTy Decl,
SourceLocation StartLoc,
SourceLocation EndLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnExprStmt(FullExprArg Expr) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return OwningStmtResult(*this, Expr->release());
}
@@ -278,13 +280,13 @@
SourceLocation DotDotDotLoc,
ExprArg RHSVal,
SourceLocation ColonLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
SourceLocation ColonLoc,
StmtArg SubStmt, Scope *CurScope){
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
@@ -292,7 +294,7 @@
IdentifierInfo *II,
SourceLocation ColonLoc,
StmtArg SubStmt) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
@@ -300,30 +302,30 @@
FullExprArg CondVal, StmtArg ThenVal,
SourceLocation ElseLoc,
StmtArg ElseVal) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
StmtArg Switch,
StmtArg Body) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc,
FullExprArg Cond, StmtArg Body) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
SourceLocation WhileLoc, ExprArg Cond){
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc,
@@ -331,7 +333,7 @@
StmtArg First, ExprArg Second,
ExprArg Third, SourceLocation RParenLoc,
StmtArg Body) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnObjCForCollectionStmt(
@@ -339,34 +341,34 @@
SourceLocation LParenLoc,
StmtArg First, ExprArg Second,
SourceLocation RParenLoc, StmtArg Body) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnGotoStmt(SourceLocation GotoLoc,
SourceLocation LabelLoc,
IdentifierInfo *LabelII) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
SourceLocation StarLoc,
ExprArg DestExp) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
Scope *CurScope) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnBreakStmt(SourceLocation GotoLoc,
Scope *CurScope) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
ExprArg RetValExp) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc,
@@ -380,7 +382,7 @@
ExprArg AsmString,
MultiExprArg Clobbers,
SourceLocation RParenLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
@@ -389,54 +391,54 @@
SourceLocation RParen,
DeclPtrTy Parm, StmtArg Body,
StmtArg CatchList) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc,
StmtArg Body) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc,
StmtArg Try, StmtArg Catch,
StmtArg Finally) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
ExprArg Throw,
Scope *CurScope) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
ExprArg SynchExpr,
StmtArg SynchBody) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
// C++ Statements
virtual DeclPtrTy ActOnExceptionDeclarator(Scope *S, Declarator &D) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return DeclPtrTy();
}
virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
DeclPtrTy ExceptionDecl,
StmtArg HandlerBlock) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc,
StmtArg TryBlock,
MultiStmtArg Handlers) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return StmtEmpty();
}
@@ -454,7 +456,7 @@
bool HasTrailingLParen,
const CXXScopeSpec *SS,
bool isAddressOfOperand) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
@@ -463,7 +465,7 @@
OverloadedOperatorKind Op,
bool HasTrailingLParen, const CXXScopeSpec &SS,
bool isAddressOfOperand) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
@@ -471,23 +473,23 @@
Scope *S, SourceLocation OperatorLoc,
TypeTy *Type, bool HasTrailingLParen,
const CXXScopeSpec &SS,bool isAddressOfOperand) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnPredefinedExpr(SourceLocation Loc,
tok::TokenKind Kind) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnCharacterConstant(const Token &) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnNumericConstant(const Token &) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
@@ -495,13 +497,13 @@
/// fragments (e.g. "foo" "bar" L"baz").
virtual OwningExprResult ActOnStringLiteral(const Token *Toks,
unsigned NumToks) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
ExprArg Val) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return move(Val); // Default impl returns operand.
}
@@ -509,14 +511,14 @@
virtual OwningExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
tok::TokenKind Kind,
ExprArg Input) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnArraySubscriptExpr(Scope *S, ExprArg Base,
SourceLocation LLoc,
ExprArg Idx,
SourceLocation RLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnMemberReferenceExpr(Scope *S, ExprArg Base,
@@ -525,7 +527,7 @@
SourceLocation MemberLoc,
IdentifierInfo &Member,
DeclPtrTy ImplDecl) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
@@ -534,20 +536,20 @@
MultiExprArg Args,
SourceLocation *CommaLocs,
SourceLocation RParenLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
// Unary Operators. 'Tok' is the token for the operator.
virtual OwningExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
tok::TokenKind Op, ExprArg Input) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult
ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType,
void *TyOrEx, const SourceRange &ArgRange) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
@@ -555,25 +557,25 @@
TypeTy *Ty,
SourceLocation RParen,
ExprArg Op) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
MultiExprArg InitList,
SourceLocation RParenLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
SourceLocation RParenLoc,ExprArg Op){
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
tok::TokenKind Kind,
ExprArg LHS, ExprArg RHS) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
@@ -583,7 +585,7 @@
SourceLocation ColonLoc,
ExprArg Cond, ExprArg LHS,
ExprArg RHS) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
@@ -592,14 +594,14 @@
virtual OwningExprResult ActOnAddrLabel(SourceLocation OpLoc,
SourceLocation LabLoc,
IdentifierInfo *LabelII) {// "&&foo"
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnStmtExpr(SourceLocation LPLoc,
StmtArg SubStmt,
SourceLocation RPLoc) { // "({..})"
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
@@ -610,7 +612,7 @@
OffsetOfComponent *CompPtr,
unsigned NumComponents,
SourceLocation RParenLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
@@ -618,7 +620,7 @@
virtual OwningExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
TypeTy *arg1,TypeTy *arg2,
SourceLocation RPLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
// __builtin_choose_expr(constExpr, expr1, expr2)
@@ -626,7 +628,7 @@
ExprArg cond, ExprArg expr1,
ExprArg expr2,
SourceLocation RPLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
@@ -634,43 +636,43 @@
virtual OwningExprResult ActOnVAArg(SourceLocation BuiltinLoc,
ExprArg expr, TypeTy *type,
SourceLocation RPLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnGNUNullExpr(SourceLocation TokenLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
}
virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
}
virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
}
virtual OwningExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc,
StmtArg Body,
Scope *CurScope) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual DeclPtrTy ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
IdentifierInfo *Ident,
SourceLocation LBrace) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return DeclPtrTy();
}
virtual void ActOnFinishNamespaceDef(DeclPtrTy Dcl, SourceLocation RBrace) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return;
}
@@ -684,7 +686,7 @@
SourceLocation IdentLoc,
IdentifierInfo *NamespcName,
AttributeList *AttrList) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return DeclPtrTy();
}
#endif
@@ -692,16 +694,16 @@
virtual void ActOnParamDefaultArgument(DeclPtrTy param,
SourceLocation EqualLoc,
ExprArg defarg) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
}
virtual void ActOnParamUnparsedDefaultArgument(DeclPtrTy param,
SourceLocation EqualLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
}
virtual void ActOnParamDefaultArgumentError(DeclPtrTy param) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
}
virtual void AddCXXDirectInitializerToDecl(DeclPtrTy Dcl,
@@ -709,29 +711,29 @@
MultiExprArg Exprs,
SourceLocation *CommaLocs,
SourceLocation RParenLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return;
}
virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S,
DeclPtrTy Method)
{
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
}
virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclPtrTy Param) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
}
virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S,
DeclPtrTy Method) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
}
virtual DeclPtrTy ActOnStaticAssertDeclaration(SourceLocation AssertLoc,
ExprArg AssertExpr,
ExprArg AssertMessageExpr) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return DeclPtrTy();
}
@@ -743,7 +745,7 @@
SourceLocation LParenLoc,
ExprArg Op,
SourceLocation RParenLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
@@ -751,23 +753,23 @@
SourceLocation LParenLoc,
bool isType, void *TyOrExpr,
SourceLocation RParenLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnCXXThis(SourceLocation ThisLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
tok::TokenKind Kind) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnCXXThrow(SourceLocation OpLoc, ExprArg Op) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
@@ -777,7 +779,7 @@
MultiExprArg Exprs,
SourceLocation *CommaLocs,
SourceLocation RParenLoc) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
@@ -786,7 +788,7 @@
Declarator &D,
SourceLocation EqualLoc,
ExprArg AssignExprVal) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
@@ -799,14 +801,14 @@
SourceLocation ConstructorLParen,
MultiExprArg ConstructorArgs,
SourceLocation ConstructorRParen) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
virtual OwningExprResult ActOnCXXDelete(SourceLocation StartLoc,
bool UseGlobal, bool ArrayForm,
ExprArg Operand) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
@@ -815,12 +817,13 @@
SourceLocation LParen,
TypeTy *Ty,
SourceLocation RParen) {
- llvm::cout << __FUNCTION__ << "\n";
+ Out << __FUNCTION__ << "\n";
return ExprEmpty();
}
};
}
-MinimalAction *clang::CreatePrintParserActionsAction(Preprocessor &PP) {
- return new ParserPrintActions(PP);
+MinimalAction *clang::CreatePrintParserActionsAction(Preprocessor &PP,
+ llvm::raw_ostream* OS) {
+ return new ParserPrintActions(PP, *OS);
}
Modified: cfe/trunk/tools/clang-cc/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/PrintPreprocessedOutput.cpp?rev=72085&r1=72084&r2=72085&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/tools/clang-cc/PrintPreprocessedOutput.cpp Mon May 18 20:02:07 2009
@@ -417,21 +417,12 @@
/// DoPrintPreprocessedInput - This implements -E mode.
///
void clang::DoPrintPreprocessedInput(Preprocessor &PP,
- const std::string &OutFile) {
+ llvm::raw_ostream *OS) {
// Inform the preprocessor whether we want it to retain comments or not, due
// to -C or -CC.
PP.SetCommentRetentionState(EnableCommentOutput, EnableMacroCommentOutput);
-
- // Open the output buffer using "Binary" mode. On Windows, this distinction
- // is important (to surpress automatic LF->CFLF conversion).
- std::string Err;
- llvm::raw_fd_ostream OS(OutFile.empty() ? "-" : OutFile.c_str(), true, Err);
- if (!Err.empty()) {
- fprintf(stderr, "%s\n", Err.c_str());
- exit(1);
- }
-
- OS.SetBufferSize(64*1024);
+
+ OS->SetBufferSize(64*1024);
if (DumpMacros) {
// -dM mode just scans and ignores all tokens in the files, then dumps out
@@ -453,12 +444,12 @@
// Ignore computed macros like __LINE__ and friends.
if (MI.isBuiltinMacro()) continue;
- PrintMacroDefinition(*MacrosByID[i].first, MI, PP, OS);
- OS << "\n";
+ PrintMacroDefinition(*MacrosByID[i].first, MI, PP, *OS);
+ *OS << "\n";
}
} else {
- PrintPPOutputPPCallbacks *Callbacks = new PrintPPOutputPPCallbacks(PP, OS);
+ PrintPPOutputPPCallbacks *Callbacks = new PrintPPOutputPPCallbacks(PP, *OS);
PP.AddPragmaHandler(0, new UnknownPragmaHandler("#pragma", Callbacks));
PP.AddPragmaHandler("GCC", new UnknownPragmaHandler("#pragma GCC",
Callbacks));
@@ -479,15 +470,11 @@
"<built-in>"));
// Read all the preprocessed tokens, printing them out to the stream.
- PrintPreprocessedTokens(PP, Tok, Callbacks, OS);
- OS << '\n';
+ PrintPreprocessedTokens(PP, Tok, Callbacks, *OS);
+ *OS << '\n';
}
-
+
// Flush the ostream.
- OS.flush();
-
- // If an error occurred, remove the output file.
- if (PP.getDiagnostics().hasErrorOccurred() && !OutFile.empty())
- llvm::sys::Path(OutFile).eraseFromDisk();
+ OS->flush();
}
Modified: cfe/trunk/tools/clang-cc/RewriteMacros.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/RewriteMacros.cpp?rev=72085&r1=72084&r2=72085&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/RewriteMacros.cpp (original)
+++ cfe/trunk/tools/clang-cc/RewriteMacros.cpp Mon May 18 20:02:07 2009
@@ -85,8 +85,7 @@
/// RewriteMacrosInInput - Implement -rewrite-macros mode.
-void clang::RewriteMacrosInInput(Preprocessor &PP,const std::string &InFileName,
- const std::string &OutFileName) {
+void clang::RewriteMacrosInInput(Preprocessor &PP, llvm::raw_ostream *OS) {
SourceManager &SM = PP.getSourceManager();
Rewriter Rewrite;
@@ -202,35 +201,15 @@
Expansion += ' ';
RB.InsertTextBefore(InsertPos, &Expansion[0], Expansion.size());
}
-
- // Create the output file.
- llvm::OwningPtr<llvm::raw_ostream> OwnedStream;
- llvm::raw_ostream *OutFile;
- if (OutFileName == "-") {
- OutFile = &llvm::outs();
- } else if (!OutFileName.empty()) {
- std::string Err;
- OutFile = new llvm::raw_fd_ostream(OutFileName.c_str(), false, Err);
- OwnedStream.reset(OutFile);
- } else if (InFileName == "-") {
- OutFile = &llvm::outs();
- } else {
- llvm::sys::Path Path(InFileName);
- Path.eraseSuffix();
- Path.appendSuffix("cpp");
- std::string Err;
- OutFile = new llvm::raw_fd_ostream(Path.toString().c_str(), false, Err);
- OwnedStream.reset(OutFile);
- }
// Get the buffer corresponding to MainFileID. If we haven't changed it, then
// we are done.
if (const RewriteBuffer *RewriteBuf =
Rewrite.getRewriteBufferFor(SM.getMainFileID())) {
//printf("Changed:\n");
- *OutFile << std::string(RewriteBuf->begin(), RewriteBuf->end());
+ *OS << std::string(RewriteBuf->begin(), RewriteBuf->end());
} else {
fprintf(stderr, "No changes\n");
}
- OutFile->flush();
+ OS->flush();
}
Modified: cfe/trunk/tools/clang-cc/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/RewriteTest.cpp?rev=72085&r1=72084&r2=72085&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/RewriteTest.cpp (original)
+++ cfe/trunk/tools/clang-cc/RewriteTest.cpp Mon May 18 20:02:07 2009
@@ -14,10 +14,9 @@
#include "clang-cc.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Rewrite/TokenRewriter.h"
-#include <iostream>
+#include "llvm/Support/raw_ostream.h"
-void clang::DoRewriteTest(Preprocessor &PP, const std::string &InFileName,
- const std::string &OutFileName) {
+void clang::DoRewriteTest(Preprocessor &PP, llvm::raw_ostream* OS) {
SourceManager &SM = PP.getSourceManager();
const LangOptions &LangOpts = PP.getLangOptions();
@@ -36,5 +35,5 @@
// Print out the output.
for (TokenRewriter::token_iterator I = Rewriter.token_begin(),
E = Rewriter.token_end(); I != E; ++I)
- std::cout << PP.getSpelling(*I);
+ *OS << PP.getSpelling(*I);
}
Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=72085&r1=72084&r2=72085&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Mon May 18 20:02:07 2009
@@ -1748,12 +1748,20 @@
case GeneratePTH: {
llvm::TimeRegion Timer(ClangFrontendTimer);
- CacheTokens(PP, OutputFile);
+ if (OutputFile.empty() || OutputFile == "-") {
+ // FIXME: Don't fail this way.
+ // FIXME: Verify that we can actually seek in the given file.
+ llvm::cerr << "ERROR: PTH requires an seekable file for output!\n";
+ ::exit(1);
+ }
+ OS.reset(ComputeOutFile(InFile, 0, true, OutPath));
+ CacheTokens(PP, static_cast<llvm::raw_fd_ostream*>(OS.get()));
ClearSourceMgr = true;
break;
}
case PrintPreprocessedInput:
+ OS.reset(ComputeOutFile(InFile, 0, true, OutPath));
break;
case ParseNoop:
@@ -1761,7 +1769,8 @@
case ParsePrintCallbacks: {
llvm::TimeRegion Timer(ClangFrontendTimer);
- ParseFile(PP, CreatePrintParserActionsAction(PP));
+ OS.reset(ComputeOutFile(InFile, 0, true, OutPath));
+ ParseFile(PP, CreatePrintParserActionsAction(PP, OS.get()));
ClearSourceMgr = true;
break;
}
@@ -1773,15 +1782,16 @@
}
case RewriteMacros:
- RewriteMacrosInInput(PP, InFile, OutputFile);
+ OS.reset(ComputeOutFile(InFile, 0, true, OutPath));
+ RewriteMacrosInInput(PP, OS.get());
ClearSourceMgr = true;
break;
- case RewriteTest: {
- DoRewriteTest(PP, InFile, OutputFile);
+ case RewriteTest:
+ OS.reset(ComputeOutFile(InFile, 0, true, OutPath));
+ DoRewriteTest(PP, OS.get());
ClearSourceMgr = true;
break;
- }
case FixIt:
llvm::TimeRegion Timer(ClangFrontendTimer);
@@ -1906,7 +1916,7 @@
ClearSourceMgr = true;
} else if (PA == PrintPreprocessedInput){ // -E mode.
llvm::TimeRegion Timer(ClangFrontendTimer);
- DoPrintPreprocessedInput(PP, OutputFile);
+ DoPrintPreprocessedInput(PP, OS.get());
ClearSourceMgr = true;
}
Modified: cfe/trunk/tools/clang-cc/clang-cc.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.h?rev=72085&r1=72084&r2=72085&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.h (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.h Mon May 18 20:02:07 2009
@@ -17,6 +17,11 @@
#include <vector>
#include <string>
+namespace llvm {
+class raw_ostream;
+class raw_fd_ostream;
+}
+
namespace clang {
class Preprocessor;
class MinimalAction;
@@ -33,19 +38,18 @@
bool ProcessWarningOptions(Diagnostic &Diags);
/// DoPrintPreprocessedInput - Implement -E mode.
-void DoPrintPreprocessedInput(Preprocessor &PP, const std::string& OutFile);
+void DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream* OS);
/// RewriteMacrosInInput - Implement -rewrite-macros mode.
-void RewriteMacrosInInput(Preprocessor &PP, const std::string &InFileName,
- const std::string& OutFile);
+void RewriteMacrosInInput(Preprocessor &PP, llvm::raw_ostream* OS);
-void DoRewriteTest(Preprocessor &PP, const std::string &InFileName,
- const std::string &OutFileName);
-
+/// RewriteMacrosInInput - A simple test for the TokenRewriter class.
+void DoRewriteTest(Preprocessor &PP, llvm::raw_ostream* OS);
/// CreatePrintParserActionsAction - Return the actions implementation that
/// implements the -parse-print-callbacks option.
-MinimalAction *CreatePrintParserActionsAction(Preprocessor &PP);
+MinimalAction *CreatePrintParserActionsAction(Preprocessor &PP,
+ llvm::raw_ostream* OS);
/// CheckDiagnostics - Gather the expected diagnostics and check them.
bool CheckDiagnostics(Preprocessor &PP);
@@ -54,8 +58,9 @@
/// This is only done if either -MD or -MMD has been specified.
bool CreateDependencyFileGen(Preprocessor *PP, std::string &ErrStr);
-/// CacheTokens - Cache tokens for use with PCH.
-void CacheTokens(Preprocessor& PP, const std::string& OutFile);
+/// CacheTokens - Cache tokens for use with PCH. Note that this requires
+/// a seekable stream.
+void CacheTokens(Preprocessor& PP, llvm::raw_fd_ostream* OS);
/// CreateAnalysisConsumer - Creates an ASTConsumer to run various code
/// analysis passes. (The set of analyses run is controlled by command-line
More information about the cfe-commits
mailing list