| File src/tooling/common.cpp changed (mode: 100644) (index c69a8e8..4bdfb7f) |
| ... |
... |
namespace po = boost::program_options; |
| 41 |
41 |
|
|
| 42 |
42 |
static po::variables_map parseOptions(const std::vector<std::string> &args, |
static po::variables_map parseOptions(const std::vector<std::string> &args, |
| 43 |
43 |
po::options_description &options); |
po::options_description &options); |
| 44 |
|
static optional_t<Tree> buildTreeFromFile(Environment &env, |
|
|
44 |
|
static optional_t<Tree> buildTreeFromFile(const CommonArgs &args, |
| 45 |
45 |
TimeReport &tr, |
TimeReport &tr, |
|
46 |
|
const Attrs &attrs, |
| 46 |
47 |
const std::string &path, |
const std::string &path, |
| 47 |
48 |
const std::string &contents, |
const std::string &contents, |
| 48 |
49 |
cpp17::pmr::memory_resource *mr); |
cpp17::pmr::memory_resource *mr); |
| |
| ... |
... |
optional_t<Tree> buildTreeFromFile(Environment &env, |
| 140 |
141 |
const std::string &path, |
const std::string &path, |
| 141 |
142 |
cpp17::pmr::memory_resource *mr) |
cpp17::pmr::memory_resource *mr) |
| 142 |
143 |
{ |
{ |
| 143 |
|
return buildTreeFromFile(env, env.getTimeKeeper(), path, mr); |
|
|
144 |
|
Attrs attrs = env.getConfig().lookupAttrs(path); |
|
145 |
|
return buildTreeFromFile(env, env.getTimeKeeper(), attrs, path, mr); |
| 144 |
146 |
} |
} |
| 145 |
147 |
|
|
| 146 |
148 |
optional_t<Tree> |
optional_t<Tree> |
| 147 |
|
buildTreeFromFile(Environment &env, TimeReport &tr, const std::string &path, |
|
|
149 |
|
buildTreeFromFile(Environment &env, |
|
150 |
|
TimeReport &tr, |
|
151 |
|
const Attrs &attrs, |
|
152 |
|
const std::string &path, |
| 148 |
153 |
cpp17::pmr::memory_resource *mr) |
cpp17::pmr::memory_resource *mr) |
| 149 |
154 |
{ |
{ |
| 150 |
|
return buildTreeFromFile(env, tr, path, readFile(path), mr); |
|
|
155 |
|
return buildTreeFromFile(env.getCommonArgs(), |
|
156 |
|
tr, |
|
157 |
|
attrs, |
|
158 |
|
path, |
|
159 |
|
readFile(path), |
|
160 |
|
mr); |
|
161 |
|
} |
|
162 |
|
|
|
163 |
|
optional_t<Tree> buildTreeFromFile(Environment &env, |
|
164 |
|
TimeReport &tr, |
|
165 |
|
const Attrs &attrs, |
|
166 |
|
const std::string &path, |
|
167 |
|
const std::string &contents, |
|
168 |
|
cpp17::pmr::memory_resource *mr) |
|
169 |
|
{ |
|
170 |
|
return buildTreeFromFile(env.getCommonArgs(), |
|
171 |
|
tr, |
|
172 |
|
attrs, |
|
173 |
|
path, |
|
174 |
|
contents, |
|
175 |
|
mr); |
| 151 |
176 |
} |
} |
| 152 |
177 |
|
|
| 153 |
178 |
optional_t<Tree> |
optional_t<Tree> |
| 154 |
|
buildTreeFromFile(Environment &env, const std::string &path, |
|
| 155 |
|
const std::string &contents, cpp17::pmr::memory_resource *mr) |
|
|
179 |
|
buildTreeFromFile(Environment &env, |
|
180 |
|
const std::string &path, |
|
181 |
|
const std::string &contents, |
|
182 |
|
cpp17::pmr::memory_resource *mr) |
| 156 |
183 |
{ |
{ |
| 157 |
|
return buildTreeFromFile(env, env.getTimeKeeper(), path, contents, mr); |
|
|
184 |
|
Attrs attrs = env.getConfig().lookupAttrs(path); |
|
185 |
|
return buildTreeFromFile(env.getCommonArgs(), |
|
186 |
|
env.getTimeKeeper(), |
|
187 |
|
attrs, |
|
188 |
|
path, |
|
189 |
|
contents, |
|
190 |
|
mr); |
| 158 |
191 |
} |
} |
| 159 |
192 |
|
|
| 160 |
193 |
// Parses a file to build its tree. |
// Parses a file to build its tree. |
| 161 |
|
static optional_t<Tree> buildTreeFromFile(Environment &env, |
|
|
194 |
|
static optional_t<Tree> buildTreeFromFile(const CommonArgs &args, |
| 162 |
195 |
TimeReport &tr, |
TimeReport &tr, |
|
196 |
|
const Attrs &attrs, |
| 163 |
197 |
const std::string &path, |
const std::string &path, |
| 164 |
198 |
const std::string &contents, |
const std::string &contents, |
| 165 |
199 |
cpp17::pmr::memory_resource *mr) |
cpp17::pmr::memory_resource *mr) |
| 166 |
200 |
{ |
{ |
| 167 |
201 |
auto timer = tr.measure("parsing: " + path); |
auto timer = tr.measure("parsing: " + path); |
| 168 |
202 |
|
|
| 169 |
|
const CommonArgs &args = env.getCommonArgs(); |
|
| 170 |
|
|
|
| 171 |
|
Attrs attrs = env.getConfig().lookupAttrs(path); |
|
| 172 |
|
const int tabWidth = attrs.tabWidth; |
|
| 173 |
|
|
|
| 174 |
203 |
std::string langName = args.lang; |
std::string langName = args.lang; |
| 175 |
204 |
if (langName.empty()) { |
if (langName.empty()) { |
| 176 |
205 |
langName = attrs.lang; |
langName = attrs.lang; |
| 177 |
206 |
} |
} |
| 178 |
207 |
|
|
| 179 |
|
std::unique_ptr<Language> lang = Language::create(path, langName); |
|
|
208 |
|
std::unique_ptr<Language> lang = Language::create(path, attrs.lang); |
| 180 |
209 |
|
|
| 181 |
210 |
cpp17::pmr::monolithic localMR; |
cpp17::pmr::monolithic localMR; |
| 182 |
211 |
|
|
| 183 |
|
TreeBuilder tb = lang->parse(contents, path, tabWidth, args.debug, localMR); |
|
|
212 |
|
TreeBuilder tb = |
|
213 |
|
lang->parse(contents, path, attrs.tabWidth, args.debug, localMR); |
| 184 |
214 |
if (tb.hasFailed()) { |
if (tb.hasFailed()) { |
| 185 |
215 |
return {}; |
return {}; |
| 186 |
216 |
} |
} |
| File src/tooling/common.hpp changed (mode: 100644) (index af5aea3..b68da71) |
| ... |
... |
optional_t<Tree> buildTreeFromFile(Environment &env, |
| 95 |
95 |
cpp17::pmr::memory_resource *mr); |
cpp17::pmr::memory_resource *mr); |
| 96 |
96 |
|
|
| 97 |
97 |
// Reads and parses a file to build its tree. This form allows specifying |
// Reads and parses a file to build its tree. This form allows specifying |
| 98 |
|
// custom time keeper, which might be necessary for non-main threads. |
|
| 99 |
|
optional_t<Tree> buildTreeFromFile(Environment &env, TimeReport &tr, |
|
|
98 |
|
// custom time keeper, which might be necessary for non-main threads. It also |
|
99 |
|
// accepts custom attributes to apply attributes of one file on another. |
|
100 |
|
optional_t<Tree> buildTreeFromFile(Environment &env, |
|
101 |
|
TimeReport &tr, |
|
102 |
|
const Attrs &attrs, |
|
103 |
|
const std::string &path, |
|
104 |
|
cpp17::pmr::memory_resource *mr); |
|
105 |
|
|
|
106 |
|
// As above, but with contents. |
|
107 |
|
optional_t<Tree> buildTreeFromFile(Environment &env, |
|
108 |
|
TimeReport &tr, |
|
109 |
|
const Attrs &attrs, |
| 100 |
110 |
const std::string &path, |
const std::string &path, |
|
111 |
|
const std::string &contents, |
| 101 |
112 |
cpp17::pmr::memory_resource *mr); |
cpp17::pmr::memory_resource *mr); |
| 102 |
113 |
|
|
| 103 |
114 |
// Parses a file to build its tree. |
// Parses a file to build its tree. |
| File tools/diff/diff.cpp changed (mode: 100644) (index 3e0743e..0b9b2d8) |
| ... |
... |
run(Environment &env, const Args &args) |
| 138 |
138 |
|
|
| 139 |
139 |
using overload = optional_t<Tree> (*)(Environment &, |
using overload = optional_t<Tree> (*)(Environment &, |
| 140 |
140 |
TimeReport &, |
TimeReport &, |
|
141 |
|
const Attrs &, |
| 141 |
142 |
const std::string &, |
const std::string &, |
| 142 |
143 |
cpp17::pmr::memory_resource *); |
cpp17::pmr::memory_resource *); |
| 143 |
144 |
overload func = &buildTreeFromFile; |
overload func = &buildTreeFromFile; |
| |
| ... |
... |
run(Environment &env, const Args &args) |
| 145 |
146 |
const std::string oldFile = (args.gitDiff ? args.pos[1] : args.pos[0]); |
const std::string oldFile = (args.gitDiff ? args.pos[1] : args.pos[0]); |
| 146 |
147 |
const std::string newFile = (args.gitDiff ? args.pos[4] : args.pos[1]); |
const std::string newFile = (args.gitDiff ? args.pos[4] : args.pos[1]); |
| 147 |
148 |
|
|
|
149 |
|
// New file should be in-tree. |
|
150 |
|
Attrs attrs = env.getConfig().lookupAttrs(newFile); |
|
151 |
|
|
| 148 |
152 |
TimeReport &tr = env.getTimeKeeper(); |
TimeReport &tr = env.getTimeKeeper(); |
| 149 |
153 |
TimeReport nestedTr(tr); |
TimeReport nestedTr(tr); |
| 150 |
|
std::future<optional_t<Tree>> newTreeFuture = |
|
| 151 |
|
std::async(std::launch::async, func, std::ref(env), std::ref(nestedTr), |
|
| 152 |
|
newFile, &mrB); |
|
| 153 |
|
|
|
| 154 |
|
if (optional_t<Tree> &&tree = buildTreeFromFile(env, oldFile, &mrA)) { |
|
|
154 |
|
std::future<optional_t<Tree>> newTreeFuture = std::async(std::launch::async, |
|
155 |
|
func, |
|
156 |
|
std::ref(env), |
|
157 |
|
std::ref(nestedTr), |
|
158 |
|
attrs, |
|
159 |
|
newFile, |
|
160 |
|
&mrB); |
|
161 |
|
|
|
162 |
|
if (optional_t<Tree> &&tree = func(env, tr, attrs, oldFile, &mrA)) { |
| 155 |
163 |
treeA = *tree; |
treeA = *tree; |
| 156 |
164 |
} else { |
} else { |
| 157 |
165 |
// Wait the other thread to finish to avoid data races. |
// Wait the other thread to finish to avoid data races. |
| File tools/gdiff/ZSDiff.cpp changed (mode: 100644) (index 2fb7490..9d92d0b) |
| ... |
... |
ZSDiff::loadDiff(const DiffEntry &diffEntry) |
| 302 |
302 |
|
|
| 303 |
303 |
updateTitle(); |
updateTitle(); |
| 304 |
304 |
|
|
|
305 |
|
// New file should be in-tree. |
|
306 |
|
Attrs attrs = env.getConfig().lookupAttrs(diffEntry.updated.path); |
|
307 |
|
|
| 305 |
308 |
// TODO: parse in parallel like zs-diff does. |
// TODO: parse in parallel like zs-diff does. |
| 306 |
309 |
|
|
| 307 |
310 |
if (optional_t<Tree> &&tree = buildTreeFromFile(env, |
if (optional_t<Tree> &&tree = buildTreeFromFile(env, |
|
311 |
|
timeReport, |
|
312 |
|
attrs, |
| 308 |
313 |
diffEntry.original.path, |
diffEntry.original.path, |
| 309 |
314 |
diffEntry.original.contents, |
diffEntry.original.contents, |
| 310 |
315 |
&mr)) { |
&mr)) { |
| |
| ... |
... |
ZSDiff::loadDiff(const DiffEntry &diffEntry) |
| 316 |
321 |
} |
} |
| 317 |
322 |
|
|
| 318 |
323 |
if (optional_t<Tree> &&tree = buildTreeFromFile(env, |
if (optional_t<Tree> &&tree = buildTreeFromFile(env, |
|
324 |
|
timeReport, |
|
325 |
|
attrs, |
| 319 |
326 |
diffEntry.updated.path, |
diffEntry.updated.path, |
| 320 |
327 |
diffEntry.updated.contents, |
diffEntry.updated.contents, |
| 321 |
328 |
&mr)) { |
&mr)) { |