blob: 56fa0a0e3483ba795acdea526e2343a6233b2d74 [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
Logan Chien9207a2e2011-10-21 15:39:28 +080032// The diagnostics consumer instance (for reading the processed diagnostics)
33class DiagnosticBuffer : public clang::DiagnosticConsumer {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070034 private:
35 std::string mDiags;
Stephen Hines7ac9d0d2014-07-15 16:50:03 -070036 std::unique_ptr<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
Stephen Hinese67239d2012-02-24 15:08:36 -080041 explicit DiagnosticBuffer(DiagnosticBuffer const &src);
Logan Chien9207a2e2011-10-21 15:39:28 +080042
43 virtual ~DiagnosticBuffer();
44
45 virtual void HandleDiagnostic(clang::DiagnosticsEngine::Level DiagLevel,
46 const clang::Diagnostic& Info);
47
48 virtual clang::DiagnosticConsumer *
49 clone(clang::DiagnosticsEngine &Diags) const;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070050
zonr6315f762010-10-05 15:35:14 +080051 inline const std::string &str() const {
52 mSOS->flush();
53 return mDiags;
54 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -070055
zonr6315f762010-10-05 15:35:14 +080056 inline void reset() {
57 this->mSOS->str().clear();
zonr6315f762010-10-05 15:35:14 +080058 }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070059};
Logan Chien9207a2e2011-10-21 15:39:28 +080060
Stephen Hinese67239d2012-02-24 15:08:36 -080061} // namespace slang
Shih-wei Liao462aefd2010-06-04 15:32:04 -070062
Stephen Hinese639eb52010-11-08 19:27:20 -080063#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_DIAGNOSTIC_BUFFER_H_ NOLINT