blob: 500f345644e41d773eacf9b2f98c4606cc86d5c0 [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
Jean-Luc Brouillet666b0a72015-05-01 16:13:11 -070020#include <set>
Stephen Hinese639eb52010-11-08 19:27:20 -080021#include <string>
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070022
23#include "clang/Basic/Diagnostic.h"
24
Stephen Hinese639eb52010-11-08 19:27:20 -080025#include "llvm/Support/raw_ostream.h"
Shih-wei Liao462aefd2010-06-04 15:32:04 -070026
Shih-wei Liao462aefd2010-06-04 15:32:04 -070027namespace llvm {
zonr6315f762010-10-05 15:35:14 +080028 class raw_string_ostream;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070029}
Shih-wei Liao462aefd2010-06-04 15:32:04 -070030
31namespace slang {
32
Logan Chien9207a2e2011-10-21 15:39:28 +080033// The diagnostics consumer instance (for reading the processed diagnostics)
34class DiagnosticBuffer : public clang::DiagnosticConsumer {
Jean-Luc Brouillet666b0a72015-05-01 16:13:11 -070035private:
36 // We keed track of the messages that have been already added to this
37 // diagnostic buffer, to avoid duplicates. This can happen because for a
38 // given script we'll usually compile for both 32 and 64 bit targets.
39 std::set<std::string> mIncludedMessages;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070040 std::string mDiags;
Stephen Hines2eb9a3f2014-07-15 16:50:03 -070041 std::unique_ptr<llvm::raw_string_ostream> mSOS;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070042
Jean-Luc Brouillet666b0a72015-05-01 16:13:11 -070043public:
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070044 DiagnosticBuffer();
Logan Chien9207a2e2011-10-21 15:39:28 +080045 virtual ~DiagnosticBuffer();
46
47 virtual void HandleDiagnostic(clang::DiagnosticsEngine::Level DiagLevel,
Jean-Luc Brouillet666b0a72015-05-01 16:13:11 -070048 const clang::Diagnostic &Info) override;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070049
zonr6315f762010-10-05 15:35:14 +080050 inline const std::string &str() const {
51 mSOS->flush();
52 return mDiags;
53 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -070054
zonr6315f762010-10-05 15:35:14 +080055 inline void reset() {
Jean-Luc Brouillet666b0a72015-05-01 16:13:11 -070056 mIncludedMessages.clear();
57 mSOS.reset();
58 mDiags.clear();
zonr6315f762010-10-05 15:35:14 +080059 }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070060};
Logan Chien9207a2e2011-10-21 15:39:28 +080061
Stephen Hinese67239d2012-02-24 15:08:36 -080062} // namespace slang
Shih-wei Liao462aefd2010-06-04 15:32:04 -070063
Stephen Hinese639eb52010-11-08 19:27:20 -080064#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_DIAGNOSTIC_BUFFER_H_ NOLINT