Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Side by Side Diff: unittests/Bitcode/NaClMungeTest.cpp

Issue 1310883003: Install notion of diagnostic handler into PNaCl bitcode readers. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix issues in patch set 2. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « unittests/Bitcode/NaClMungeTest.h ('k') | unittests/Bitcode/NaClMungeWriteErrorTests.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 //===- llvm/unittests/Bitcode/NaClMungeTest.cpp - Test munging utils ------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Implements stringify methods for munging tests.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "NaClMungeTest.h"
15 #include <regex>
16
17 using namespace llvm;
18
19 namespace naclmungetest {
20
21 static bool matchErrorPrefixForLine(const std::string &Line, std::regex &Exp,
22 std::string &Suffix) {
23 std::smatch Match;
24 if (std::regex_search(Line, Match, Exp)) {
25 // Note: Element 0 is the original string.
26 Suffix = Match[2];
27 return true;
28 }
29 Suffix.clear();
30 return false;
31 }
32
33 static std::string stripErrorPrefixForLine(const std::string &Line) {
34 std::string Suffix;
35 std::regex ErrorExp("[Ee]rror: (\\(.*\\) )?(.*)");
36 if (matchErrorPrefixForLine(Line, ErrorExp, Suffix))
37 return Suffix;
38 std::regex WarningExp("[Ww]arning: (\\(.*\\) )?(.*)");
39 if (matchErrorPrefixForLine(Line, WarningExp, Suffix))
40 return Suffix;
41 return Line;
42 }
43
44 std::string stripErrorPrefix(const std::string &Message) {
45 std::string Result;
46 size_t StartPos = 0;
47 size_t NextEoln = Message.find('\n', StartPos);
48 while (NextEoln != std::string::npos) {
49 std::string Line(Message.c_str() + StartPos, NextEoln - StartPos);
50 Result.append(stripErrorPrefixForLine(Line)).push_back('\n');
51 StartPos = NextEoln + 1;
52 NextEoln = Message.find_first_of("\n", StartPos);
53 }
54 if (StartPos < Message.size()) {
55 std::string Remainder(Message.c_str() + StartPos,
56 Message.size() - StartPos);
57 Result.append(stripErrorPrefixForLine(Remainder));
58 }
59 return Result;
60 }
61
62 } // end of naclmungetest namespace
OLDNEW
« no previous file with comments | « unittests/Bitcode/NaClMungeTest.h ('k') | unittests/Bitcode/NaClMungeWriteErrorTests.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698