summaryrefslogtreecommitdiffstats
path: root/lib/Support
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2012-05-03 16:50:55 +0000
committerdim <dim@FreeBSD.org>2012-05-03 16:50:55 +0000
commit2c5e9d71aba3b1a85f07c08d2c09d40b8547264b (patch)
tree8575c732129e272992ac5d7b4c2519238fff4735 /lib/Support
parent1fc08f5e9ef733ef1ce6f363fecedc2260e78974 (diff)
downloadFreeBSD-src-2c5e9d71aba3b1a85f07c08d2c09d40b8547264b.zip
FreeBSD-src-2c5e9d71aba3b1a85f07c08d2c09d40b8547264b.tar.gz
Vendor import of llvm release_31 branch r155985:
http://llvm.org/svn/llvm-project/llvm/branches/release_31@155985
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/CMakeLists.txt2
-rw-r--r--lib/Support/JSONParser.cpp302
-rw-r--r--lib/Support/Locale.cpp10
-rw-r--r--lib/Support/LocaleGeneric.inc17
-rw-r--r--lib/Support/LocaleWindows.inc15
-rw-r--r--lib/Support/LocaleXlocale.inc61
-rw-r--r--lib/Support/SmallPtrSet.cpp3
-rw-r--r--lib/Support/SourceMgr.cpp48
-rw-r--r--lib/Support/Unix/Process.inc4
-rw-r--r--lib/Support/Windows/Process.inc32
-rw-r--r--lib/Support/YAMLParser.cpp6
-rw-r--r--lib/Support/raw_ostream.cpp13
12 files changed, 199 insertions, 314 deletions
diff --git a/lib/Support/CMakeLists.txt b/lib/Support/CMakeLists.txt
index 9b3b6c8..9103327 100644
--- a/lib/Support/CMakeLists.txt
+++ b/lib/Support/CMakeLists.txt
@@ -32,7 +32,7 @@ add_llvm_library(LLVMSupport
IntrusiveRefCntPtr.cpp
IsInf.cpp
IsNAN.cpp
- JSONParser.cpp
+ Locale.cpp
LockFileManager.cpp
ManagedStatic.cpp
MemoryBuffer.cpp
diff --git a/lib/Support/JSONParser.cpp b/lib/Support/JSONParser.cpp
deleted file mode 100644
index 5dfcf29..0000000
--- a/lib/Support/JSONParser.cpp
+++ /dev/null
@@ -1,302 +0,0 @@
-//===--- JSONParser.cpp - Simple JSON parser ------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements a JSON parser.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Support/JSONParser.h"
-
-#include "llvm/ADT/Twine.h"
-#include "llvm/Support/Casting.h"
-#include "llvm/Support/MemoryBuffer.h"
-
-using namespace llvm;
-
-JSONParser::JSONParser(StringRef Input, SourceMgr *SM)
- : SM(SM), Failed(false) {
- InputBuffer = MemoryBuffer::getMemBuffer(Input, "JSON");
- SM->AddNewSourceBuffer(InputBuffer, SMLoc());
- End = InputBuffer->getBuffer().end();
- Position = InputBuffer->getBuffer().begin();
-}
-
-JSONValue *JSONParser::parseRoot() {
- if (Position != InputBuffer->getBuffer().begin())
- report_fatal_error("Cannot reuse JSONParser.");
- if (isWhitespace())
- nextNonWhitespace();
- if (errorIfAtEndOfFile("'[' or '{' at start of JSON text"))
- return 0;
- switch (*Position) {
- case '[':
- return new (ValueAllocator.Allocate<JSONArray>(1)) JSONArray(this);
- case '{':
- return new (ValueAllocator.Allocate<JSONObject>(1)) JSONObject(this);
- default:
- setExpectedError("'[' or '{' at start of JSON text", *Position);
- return 0;
- }
-}
-
-bool JSONParser::validate() {
- JSONValue *Root = parseRoot();
- if (Root == NULL) {
- return false;
- }
- return skip(*Root);
-}
-
-bool JSONParser::skip(const JSONAtom &Atom) {
- switch(Atom.getKind()) {
- case JSONAtom::JK_Array:
- case JSONAtom::JK_Object:
- return skipContainer(*cast<JSONContainer>(&Atom));
- case JSONAtom::JK_String:
- return true;
- case JSONAtom::JK_KeyValuePair:
- return skip(*cast<JSONKeyValuePair>(&Atom)->Value);
- }
- llvm_unreachable("Impossible enum value.");
-}
-
-// Sets the current error to:
-// "expected <Expected>, but found <Found>".
-void JSONParser::setExpectedError(StringRef Expected, StringRef Found) {
- SM->PrintMessage(SMLoc::getFromPointer(Position), SourceMgr::DK_Error,
- "expected " + Expected + ", but found " + Found + ".", ArrayRef<SMRange>());
- Failed = true;
-}
-
-// Sets the current error to:
-// "expected <Expected>, but found <Found>".
-void JSONParser::setExpectedError(StringRef Expected, char Found) {
- setExpectedError(Expected, ("'" + StringRef(&Found, 1) + "'").str());
-}
-
-// If there is no character available, returns true and sets the current error
-// to: "expected <Expected>, but found EOF.".
-bool JSONParser::errorIfAtEndOfFile(StringRef Expected) {
- if (Position == End) {
- setExpectedError(Expected, "EOF");
- return true;
- }
- return false;
-}
-
-// Sets the current error if the current character is not C to:
-// "expected 'C', but got <current character>".
-bool JSONParser::errorIfNotAt(char C, StringRef Message) {
- if (*Position != C) {
- std::string Expected =
- ("'" + StringRef(&C, 1) + "' " + Message).str();
- if (Position == End)
- setExpectedError(Expected, "EOF");
- else
- setExpectedError(Expected, *Position);
- return true;
- }
- return false;
-}
-
-// Forbidding inlining improves performance by roughly 20%.
-// FIXME: Remove once llvm optimizes this to the faster version without hints.
-LLVM_ATTRIBUTE_NOINLINE static bool
-wasEscaped(StringRef::iterator First, StringRef::iterator Position);
-
-// Returns whether a character at 'Position' was escaped with a leading '\'.
-// 'First' specifies the position of the first character in the string.
-static bool wasEscaped(StringRef::iterator First,
- StringRef::iterator Position) {
- assert(Position - 1 >= First);
- StringRef::iterator I = Position - 1;
- // We calulate the number of consecutive '\'s before the current position
- // by iterating backwards through our string.
- while (I >= First && *I == '\\') --I;
- // (Position - 1 - I) now contains the number of '\'s before the current
- // position. If it is odd, the character at 'Positon' was escaped.
- return (Position - 1 - I) % 2 == 1;
-}
-
-// Parses a JSONString, assuming that the current position is on a quote.
-JSONString *JSONParser::parseString() {
- assert(Position != End);
- assert(!isWhitespace());
- if (errorIfNotAt('"', "at start of string"))
- return 0;
- StringRef::iterator First = Position + 1;
-
- // Benchmarking shows that this loop is the hot path of the application with
- // about 2/3rd of the runtime cycles. Since escaped quotes are not the common
- // case, and multiple escaped backslashes before escaped quotes are very rare,
- // we pessimize this case to achieve a smaller inner loop in the common case.
- // We're doing that by having a quick inner loop that just scans for the next
- // quote. Once we find the quote we check the last character to see whether
- // the quote might have been escaped. If the last character is not a '\', we
- // know the quote was not escaped and have thus found the end of the string.
- // If the immediately preceding character was a '\', we have to scan backwards
- // to see whether the previous character was actually an escaped backslash, or
- // an escape character for the quote. If we find that the current quote was
- // escaped, we continue parsing for the next quote and repeat.
- // This optimization brings around 30% performance improvements.
- do {
- // Step over the current quote.
- ++Position;
- // Find the next quote.
- while (Position != End && *Position != '"')
- ++Position;
- if (errorIfAtEndOfFile("'\"' at end of string"))
- return 0;
- // Repeat until the previous character was not a '\' or was an escaped
- // backslash.
- } while (*(Position - 1) == '\\' && wasEscaped(First, Position));
-
- return new (ValueAllocator.Allocate<JSONString>())
- JSONString(StringRef(First, Position - First));
-}
-
-
-// Advances the position to the next non-whitespace position.
-void JSONParser::nextNonWhitespace() {
- do {
- ++Position;
- } while (isWhitespace());
-}
-
-// Checks if there is a whitespace character at the current position.
-bool JSONParser::isWhitespace() {
- return *Position == ' ' || *Position == '\t' ||
- *Position == '\n' || *Position == '\r';
-}
-
-bool JSONParser::failed() const {
- return Failed;
-}
-
-// Parses a JSONValue, assuming that the current position is at the first
-// character of the value.
-JSONValue *JSONParser::parseValue() {
- assert(Position != End);
- assert(!isWhitespace());
- switch (*Position) {
- case '[':
- return new (ValueAllocator.Allocate<JSONArray>(1)) JSONArray(this);
- case '{':
- return new (ValueAllocator.Allocate<JSONObject>(1)) JSONObject(this);
- case '"':
- return parseString();
- default:
- setExpectedError("'[', '{' or '\"' at start of value", *Position);
- return 0;
- }
-}
-
-// Parses a JSONKeyValuePair, assuming that the current position is at the first
-// character of the key, value pair.
-JSONKeyValuePair *JSONParser::parseKeyValuePair() {
- assert(Position != End);
- assert(!isWhitespace());
-
- JSONString *Key = parseString();
- if (Key == 0)
- return 0;
-
- nextNonWhitespace();
- if (errorIfNotAt(':', "between key and value"))
- return 0;
-
- nextNonWhitespace();
- const JSONValue *Value = parseValue();
- if (Value == 0)
- return 0;
-
- return new (ValueAllocator.Allocate<JSONKeyValuePair>(1))
- JSONKeyValuePair(Key, Value);
-}
-
-/// \brief Parses the first element of a JSON array or object, or closes the
-/// array.
-///
-/// The method assumes that the current position is before the first character
-/// of the element, with possible white space in between. When successful, it
-/// returns the new position after parsing the element. Otherwise, if there is
-/// no next value, it returns a default constructed StringRef::iterator.
-StringRef::iterator JSONParser::parseFirstElement(JSONAtom::Kind ContainerKind,
- char StartChar, char EndChar,
- const JSONAtom *&Element) {
- assert(*Position == StartChar);
- Element = 0;
- nextNonWhitespace();
- if (errorIfAtEndOfFile("value or end of container at start of container"))
- return StringRef::iterator();
-
- if (*Position == EndChar)
- return StringRef::iterator();
-
- Element = parseElement(ContainerKind);
- if (Element == 0)
- return StringRef::iterator();
-
- return Position;
-}
-
-/// \brief Parses the next element of a JSON array or object, or closes the
-/// array.
-///
-/// The method assumes that the current position is before the ',' which
-/// separates the next element from the current element. When successful, it
-/// returns the new position after parsing the element. Otherwise, if there is
-/// no next value, it returns a default constructed StringRef::iterator.
-StringRef::iterator JSONParser::parseNextElement(JSONAtom::Kind ContainerKind,
- char EndChar,
- const JSONAtom *&Element) {
- Element = 0;
- nextNonWhitespace();
- if (errorIfAtEndOfFile("',' or end of container for next element"))
- return 0;
-
- if (*Position == ',') {
- nextNonWhitespace();
- if (errorIfAtEndOfFile("element in container"))
- return StringRef::iterator();
-
- Element = parseElement(ContainerKind);
- if (Element == 0)
- return StringRef::iterator();
-
- return Position;
- } else if (*Position == EndChar) {
- return StringRef::iterator();
- } else {
- setExpectedError("',' or end of container for next element", *Position);
- return StringRef::iterator();
- }
-}
-
-const JSONAtom *JSONParser::parseElement(JSONAtom::Kind ContainerKind) {
- switch (ContainerKind) {
- case JSONAtom::JK_Array:
- return parseValue();
- case JSONAtom::JK_Object:
- return parseKeyValuePair();
- default:
- llvm_unreachable("Impossible code path");
- }
-}
-
-bool JSONParser::skipContainer(const JSONContainer &Container) {
- for (JSONContainer::AtomIterator I = Container.atom_current(),
- E = Container.atom_end();
- I != E; ++I) {
- assert(*I != 0);
- if (!skip(**I))
- return false;
- }
- return !failed();
-}
diff --git a/lib/Support/Locale.cpp b/lib/Support/Locale.cpp
new file mode 100644
index 0000000..17b9b6c
--- /dev/null
+++ b/lib/Support/Locale.cpp
@@ -0,0 +1,10 @@
+#include "llvm/Support/Locale.h"
+#include "llvm/Config/config.h"
+
+#ifdef __APPLE__
+#include "LocaleXlocale.inc"
+#elif LLVM_ON_WIN32
+#include "LocaleWindows.inc"
+#else
+#include "LocaleGeneric.inc"
+#endif
diff --git a/lib/Support/LocaleGeneric.inc b/lib/Support/LocaleGeneric.inc
new file mode 100644
index 0000000..278deee
--- /dev/null
+++ b/lib/Support/LocaleGeneric.inc
@@ -0,0 +1,17 @@
+#include <cwctype>
+
+namespace llvm {
+namespace sys {
+namespace locale {
+
+int columnWidth(StringRef s) {
+ return s.size();
+}
+
+bool isPrint(int c) {
+ return iswprint(c);
+}
+
+}
+}
+}
diff --git a/lib/Support/LocaleWindows.inc b/lib/Support/LocaleWindows.inc
new file mode 100644
index 0000000..6827ac1
--- /dev/null
+++ b/lib/Support/LocaleWindows.inc
@@ -0,0 +1,15 @@
+namespace llvm {
+namespace sys {
+namespace locale {
+
+int columnWidth(StringRef s) {
+ return s.size();
+}
+
+bool isPrint(int c) {
+ return ' ' <= c && c <= '~';
+}
+
+}
+}
+} \ No newline at end of file
diff --git a/lib/Support/LocaleXlocale.inc b/lib/Support/LocaleXlocale.inc
new file mode 100644
index 0000000..f595e7c
--- /dev/null
+++ b/lib/Support/LocaleXlocale.inc
@@ -0,0 +1,61 @@
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/ManagedStatic.h"
+#include <cassert>
+#include <xlocale.h>
+
+
+namespace {
+ struct locale_holder {
+ locale_holder()
+ : l(newlocale(LC_CTYPE_MASK,"en_US.UTF-8",LC_GLOBAL_LOCALE))
+ {
+ assert(NULL!=l);
+ }
+ ~locale_holder() {
+ freelocale(l);
+ }
+
+ int mbswidth(llvm::SmallString<16> s) const {
+ // this implementation assumes no '\0' in s
+ assert(s.size()==strlen(s.c_str()));
+
+ size_t size = mbstowcs_l(NULL,s.c_str(),0,l);
+ assert(size!=(size_t)-1);
+ if (size==0)
+ return 0;
+ llvm::SmallVector<wchar_t,200> ws(size);
+ size = mbstowcs_l(&ws[0],s.c_str(),ws.size(),l);
+ assert(ws.size()==size);
+ return wcswidth_l(&ws[0],ws.size(),l);
+ }
+
+ int isprint(int c) const {
+ return iswprint_l(c,l);
+ }
+
+ private:
+
+ locale_t l;
+ };
+
+ llvm::ManagedStatic<locale_holder> l;
+}
+
+namespace llvm {
+namespace sys {
+namespace locale {
+
+int columnWidth(StringRef s) {
+ int width = l->mbswidth(s);
+ assert(width>=0);
+ return width;
+}
+
+bool isPrint(int c) {
+ return l->isprint(c);
+}
+
+}
+}
+}
diff --git a/lib/Support/SmallPtrSet.cpp b/lib/Support/SmallPtrSet.cpp
index 68d9c29..3b53e9f 100644
--- a/lib/Support/SmallPtrSet.cpp
+++ b/lib/Support/SmallPtrSet.cpp
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/Support/MathExtras.h"
#include <algorithm>
#include <cstdlib>
@@ -102,7 +103,7 @@ bool SmallPtrSetImpl::erase_imp(const void * Ptr) {
}
const void * const *SmallPtrSetImpl::FindBucketFor(const void *Ptr) const {
- unsigned Bucket = Hash(Ptr);
+ unsigned Bucket = DenseMapInfo<void *>::getHashValue(Ptr) & (CurArraySize-1);
unsigned ArraySize = CurArraySize;
unsigned ProbeAmt = 1;
const void *const *Array = CurArray;
diff --git a/lib/Support/SourceMgr.cpp b/lib/Support/SourceMgr.cpp
index bbe36b2..15278c5 100644
--- a/lib/Support/SourceMgr.cpp
+++ b/lib/Support/SourceMgr.cpp
@@ -193,7 +193,8 @@ SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
}
void SourceMgr::PrintMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
- const Twine &Msg, ArrayRef<SMRange> Ranges) const {
+ const Twine &Msg, ArrayRef<SMRange> Ranges,
+ bool ShowColors) const {
SMDiagnostic Diagnostic = GetMessage(Loc, Kind, Msg, Ranges);
// Report the message with the diagnostic handler if present.
@@ -208,7 +209,7 @@ void SourceMgr::PrintMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
assert(CurBuf != -1 && "Invalid or unspecified location!");
PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
- Diagnostic.print(0, OS);
+ Diagnostic.print(0, OS, ShowColors);
}
//===----------------------------------------------------------------------===//
@@ -225,7 +226,14 @@ SMDiagnostic::SMDiagnostic(const SourceMgr &sm, SMLoc L, const std::string &FN,
}
-void SMDiagnostic::print(const char *ProgName, raw_ostream &S) const {
+void SMDiagnostic::print(const char *ProgName, raw_ostream &S,
+ bool ShowColors) const {
+ // Display colors only if OS goes to a tty.
+ ShowColors &= S.is_displayed();
+
+ if (ShowColors)
+ S.changeColor(raw_ostream::SAVEDCOLOR, true);
+
if (ProgName && ProgName[0])
S << ProgName << ": ";
@@ -244,13 +252,33 @@ void SMDiagnostic::print(const char *ProgName, raw_ostream &S) const {
}
switch (Kind) {
- case SourceMgr::DK_Error: S << "error: "; break;
- case SourceMgr::DK_Warning: S << "warning: "; break;
- case SourceMgr::DK_Note: S << "note: "; break;
+ case SourceMgr::DK_Error:
+ if (ShowColors)
+ S.changeColor(raw_ostream::RED, true);
+ S << "error: ";
+ break;
+ case SourceMgr::DK_Warning:
+ if (ShowColors)
+ S.changeColor(raw_ostream::MAGENTA, true);
+ S << "warning: ";
+ break;
+ case SourceMgr::DK_Note:
+ if (ShowColors)
+ S.changeColor(raw_ostream::BLACK, true);
+ S << "note: ";
+ break;
}
-
+
+ if (ShowColors) {
+ S.resetColor();
+ S.changeColor(raw_ostream::SAVEDCOLOR, true);
+ }
+
S << Message << '\n';
+ if (ShowColors)
+ S.resetColor();
+
if (LineNo == -1 || ColumnNo == -1)
return;
@@ -292,6 +320,9 @@ void SMDiagnostic::print(const char *ProgName, raw_ostream &S) const {
}
S << '\n';
+ if (ShowColors)
+ S.changeColor(raw_ostream::GREEN, true);
+
// Print out the caret line, matching tabs in the source line.
for (unsigned i = 0, e = CaretLine.size(), OutCol = 0; i != e; ++i) {
if (i >= LineContents.size() || LineContents[i] != '\t') {
@@ -306,6 +337,9 @@ void SMDiagnostic::print(const char *ProgName, raw_ostream &S) const {
++OutCol;
} while (OutCol & 7);
}
+
+ if (ShowColors)
+ S.resetColor();
S << '\n';
}
diff --git a/lib/Support/Unix/Process.inc b/lib/Support/Unix/Process.inc
index 2d7fd38..f640462 100644
--- a/lib/Support/Unix/Process.inc
+++ b/lib/Support/Unix/Process.inc
@@ -290,6 +290,10 @@ const char *Process::OutputBold(bool bg) {
return "\033[1m";
}
+const char *Process::OutputReverse() {
+ return "\033[7m";
+}
+
const char *Process::ResetColor() {
return "\033[0m";
}
diff --git a/lib/Support/Windows/Process.inc b/lib/Support/Windows/Process.inc
index 913b073..9a388b4 100644
--- a/lib/Support/Windows/Process.inc
+++ b/lib/Support/Windows/Process.inc
@@ -215,6 +215,38 @@ const char *Process::OutputColor(char code, bool bold, bool bg) {
return 0;
}
+static WORD GetConsoleTextAttribute(HANDLE hConsoleOutput) {
+ CONSOLE_SCREEN_BUFFER_INFO info;
+ GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
+ return info.wAttributes;
+}
+
+const char *Process::OutputReverse() {
+ const WORD attributes
+ = GetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE));
+
+ const WORD foreground_mask = FOREGROUND_BLUE | FOREGROUND_GREEN |
+ FOREGROUND_RED | FOREGROUND_INTENSITY;
+ const WORD background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN |
+ BACKGROUND_RED | BACKGROUND_INTENSITY;
+ const WORD color_mask = foreground_mask | background_mask;
+
+ WORD new_attributes =
+ ((attributes & FOREGROUND_BLUE )?BACKGROUND_BLUE :0) |
+ ((attributes & FOREGROUND_GREEN )?BACKGROUND_GREEN :0) |
+ ((attributes & FOREGROUND_RED )?BACKGROUND_RED :0) |
+ ((attributes & FOREGROUND_INTENSITY)?BACKGROUND_INTENSITY:0) |
+ ((attributes & BACKGROUND_BLUE )?FOREGROUND_BLUE :0) |
+ ((attributes & BACKGROUND_GREEN )?FOREGROUND_GREEN :0) |
+ ((attributes & BACKGROUND_RED )?FOREGROUND_RED :0) |
+ ((attributes & BACKGROUND_INTENSITY)?FOREGROUND_INTENSITY:0) |
+ 0;
+ new_attributes = (attributes & ~color_mask) | (new_attributes & color_mask);
+
+ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), new_attributes);
+ return 0;
+}
+
const char *Process::ResetColor() {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColors());
return 0;
diff --git a/lib/Support/YAMLParser.cpp b/lib/Support/YAMLParser.cpp
index 330519f..d38b51b 100644
--- a/lib/Support/YAMLParser.cpp
+++ b/lib/Support/YAMLParser.cpp
@@ -1732,7 +1732,7 @@ StringRef ScalarNode::unescapeDoubleQuoted( StringRef UnquotedValue
if (UnquotedValue.size() < 3)
// TODO: Report error.
break;
- unsigned int UnicodeScalarValue;
+ unsigned int UnicodeScalarValue = 0;
UnquotedValue.substr(1, 2).getAsInteger(16, UnicodeScalarValue);
encodeUTF8(UnicodeScalarValue, Storage);
UnquotedValue = UnquotedValue.substr(2);
@@ -1742,7 +1742,7 @@ StringRef ScalarNode::unescapeDoubleQuoted( StringRef UnquotedValue
if (UnquotedValue.size() < 5)
// TODO: Report error.
break;
- unsigned int UnicodeScalarValue;
+ unsigned int UnicodeScalarValue = 0;
UnquotedValue.substr(1, 4).getAsInteger(16, UnicodeScalarValue);
encodeUTF8(UnicodeScalarValue, Storage);
UnquotedValue = UnquotedValue.substr(4);
@@ -1752,7 +1752,7 @@ StringRef ScalarNode::unescapeDoubleQuoted( StringRef UnquotedValue
if (UnquotedValue.size() < 9)
// TODO: Report error.
break;
- unsigned int UnicodeScalarValue;
+ unsigned int UnicodeScalarValue = 0;
UnquotedValue.substr(1, 8).getAsInteger(16, UnicodeScalarValue);
encodeUTF8(UnicodeScalarValue, Storage);
UnquotedValue = UnquotedValue.substr(8);
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index 72d3986..86cdca1 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -633,6 +633,19 @@ raw_ostream &raw_fd_ostream::resetColor() {
return *this;
}
+raw_ostream &raw_fd_ostream::reverseColor() {
+ if (sys::Process::ColorNeedsFlush())
+ flush();
+ const char *colorcode = sys::Process::OutputReverse();
+ if (colorcode) {
+ size_t len = strlen(colorcode);
+ write(colorcode, len);
+ // don't account colors towards output characters
+ pos -= len;
+ }
+ return *this;
+}
+
bool raw_fd_ostream::is_displayed() const {
return sys::Process::FileDescriptorIsDisplayed(FD);
}
OpenPOWER on IntegriCloud