blob: 3c4e1c76a11a645666d737c78690726d4aa161be [file] [log] [blame]
Zonr Changc383a502010-10-12 01:52:08 +08001/*
2 * Copyright 2010, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Stephen Hinese639eb52010-11-08 19:27:20 -080017#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_DIAGNOSTIC_BUFFER_H_ // NOLINT
18#define _FRAMEWORKS_COMPILE_SLANG_SLANG_DIAGNOSTIC_BUFFER_H_
Shih-wei Liao462aefd2010-06-04 15:32:04 -070019
Stephen Hinese639eb52010-11-08 19:27:20 -080020#include <string>
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070021
22#include "clang/Basic/Diagnostic.h"
23
Stephen Hinese639eb52010-11-08 19:27:20 -080024#include "llvm/Support/raw_ostream.h"
Shih-wei Liao462aefd2010-06-04 15:32:04 -070025
Shih-wei Liao462aefd2010-06-04 15:32:04 -070026namespace llvm {
zonr6315f762010-10-05 15:35:14 +080027 class raw_string_ostream;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070028}
Shih-wei Liao462aefd2010-06-04 15:32:04 -070029
30namespace slang {
31
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070032// The diagnostics client instance (for reading the processed diagnostics)
33class DiagnosticBuffer : public clang::DiagnosticClient {
34 private:
35 std::string mDiags;
zonr6315f762010-10-05 15:35:14 +080036 llvm::raw_string_ostream *mSOS;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070037
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070038 public:
39 DiagnosticBuffer();
Shih-wei Liao462aefd2010-06-04 15:32:04 -070040
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070041 virtual void HandleDiagnostic(clang::Diagnostic::Level DiagLevel,
42 const clang::DiagnosticInfo& Info);
Shih-wei Liao462aefd2010-06-04 15:32:04 -070043
zonr6315f762010-10-05 15:35:14 +080044 inline const std::string &str() const {
45 mSOS->flush();
46 return mDiags;
47 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -070048
zonr6315f762010-10-05 15:35:14 +080049 inline void reset() {
50 this->mSOS->str().clear();
51 return;
52 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -070053
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070054 virtual ~DiagnosticBuffer();
55};
56}
Shih-wei Liao462aefd2010-06-04 15:32:04 -070057
Stephen Hinese639eb52010-11-08 19:27:20 -080058#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_DIAGNOSTIC_BUFFER_H_ NOLINT