File src/srcml/SrcmlTransformer.cpp changed (mode: 100644) (index 342709f..eec97cb) |
... |
... |
SrcmlTransformer::SrcmlTransformer(const std::string &contents, |
94 |
94 |
const std::unordered_set<std::string> &keywords) |
const std::unordered_set<std::string> &keywords) |
95 |
95 |
: contents(contents), path(path), tb(tb), language(language), |
: contents(contents), path(path), tb(tb), language(language), |
96 |
96 |
map(map), keywords(keywords) |
map(map), keywords(keywords) |
97 |
|
{ |
|
98 |
|
} |
|
|
97 |
|
{ } |
99 |
98 |
|
|
100 |
99 |
void |
void |
101 |
100 |
SrcmlTransformer::transform() |
SrcmlTransformer::transform() |
|
... |
... |
SrcmlTransformer::transform() |
117 |
116 |
std::string xml = readCommandOutput(cmd, std::string()); |
std::string xml = readCommandOutput(cmd, std::string()); |
118 |
117 |
|
|
119 |
118 |
ti::XMLDocument doc; |
ti::XMLDocument doc; |
120 |
|
doc.Parse(xml.data(), xml.size()); |
|
|
119 |
|
if (doc.Parse(xml.data(), xml.size()) == ti::XML_SUCCESS && |
|
120 |
|
doc.RootElement() == nullptr) { |
|
121 |
|
|
|
122 |
|
// Work around srcml's issues with parsing files. Sometimes it can't |
|
123 |
|
// read them from file (when extension is ".z" it thinks it's an |
|
124 |
|
// archive) and sometimes from stdin (bugs of previous versions), so try |
|
125 |
|
// both ways. |
|
126 |
|
cmd.pop_back(); |
|
127 |
|
xml = readCommandOutput(cmd, contents); |
|
128 |
|
doc.Parse(xml.data(), xml.size()); |
|
129 |
|
} |
|
130 |
|
|
121 |
131 |
if (doc.Error()) { |
if (doc.Error()) { |
122 |
132 |
throw std::runtime_error("Failed to parse: " + |
throw std::runtime_error("Failed to parse: " + |
123 |
133 |
std::string(doc.ErrorStr())); |
std::string(doc.ErrorStr())); |
|
... |
... |
SrcmlTransformer::transform() |
134 |
144 |
PNode * |
PNode * |
135 |
145 |
SrcmlTransformer::visit(ti::XMLNode *node, int level) |
SrcmlTransformer::visit(ti::XMLNode *node, int level) |
136 |
146 |
{ |
{ |
|
147 |
|
if (node == nullptr) { |
|
148 |
|
return tb.addNode(); |
|
149 |
|
} |
|
150 |
|
|
137 |
151 |
SType stype = {}; |
SType stype = {}; |
138 |
152 |
auto it = map.find(node->Value()); |
auto it = map.find(node->Value()); |
139 |
153 |
if (it != map.end()) { |
if (it != map.end()) { |