[PATCH] cpp11-migrate: Write header replacements to disk
Edwin Vane
edwin.vane at intel.com
Wed Jul 17 19:22:54 PDT 2013
================
Comment at: cpp11-migrate/tool/Cpp11Migrate.cpp:210
@@ -208,3 +209,3 @@
// written to disk for testing purposes.
- for (HeaderOverrides::const_iterator HeaderI = Overrides.headers_begin(),
+ for (HeaderOverrides::iterator HeaderI = Overrides.headers_begin(),
HeaderE = Overrides.headers_end();
----------------
Tareq A. Siraj wrote:
> Edwin Vane wrote:
> > Tareq A. Siraj wrote:
> > > Guillaume Papin wrote:
> > > > Is this non-const iterator really necessary? Seems to me that the HeaderOverrides is not really modified, just read.
> > > >
> > > Writing vector<MigratorReplacements> to YAML requires the vector to be non-const (not entirely sure why they did it like that) and thus the HeaderOverrides need to be non-const.
> > Can we fix the yaml-writing code?
> Not without major refactoring. The internals of the macro `LLVM_YAML_IS_SEQUENCE_VECTOR` has an `element()` which require the vector to be non-const (it allocates an element if it doesn't exist). The docs also mention this: http://llvm.org/docs/YamlIO.html#sequence
Try this:
# Stop using LLVM_YAML_IS_SEQUENCE_VECTOR
# Define your own SequenceTraits class where T= const std::vector<MigratorReplacement>
# In element() assert that the incoming i < size of container.
================
Comment at: cpp11-migrate/Core/ReplacementsYaml.h:41
@@ +40,2 @@
+
+#endif // CPP11_MIGRATE_REPLACEMENTS_YAML_H
----------------
Here's something else to try as well. Instead of having this MigratorReplacement structure mirror replacements, how about create a struct like this:
```
struct TransformReplacements {
std::string TransformID;
Replacements GeneratedReplacements;
};
```
Then create a vector of these in HeaderOverrides, one entry for each transform.
Now, you can define MappingTraits for TransformReplacements and Replacements and a SequenceTraits for `std::vector<TransformReplacements>` which will result in the transform id being written only once for a set of replacements instead of for every replacement.
http://llvm-reviews.chandlerc.com/D1142
More information about the cfe-commits
mailing list