[cfe-commits] r158716 - /cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

David Blaikie dblaikie at gmail.com
Tue Jun 19 08:28:41 PDT 2012


On Tue, Jun 19, 2012 at 6:36 AM, Sean Hunt <scshunt at csclub.uwaterloo.ca> wrote:
> Author: coppro
> Date: Tue Jun 19 08:36:02 2012
> New Revision: 158716
>
> URL: http://llvm.org/viewvc/llvm-project?rev=158716&view=rev
> Log:
> Stop abusing StringRef. Fixes the Windows build.
>
> I've also removed the duplicate check for PARSED_ATTR since it seems
> unnecessary, and would have made the code more complicated.
>
> Modified:
>    cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
>
> Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=158716&r1=158715&r2=158716&view=diff
> ==============================================================================
> --- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
> +++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Tue Jun 19 08:36:02 2012
> @@ -966,7 +966,8 @@
>     std::vector<Record*> Spellings = Attr.getValueAsListOfDefs("Spellings");
>
>     for (std::vector<Record*>::const_iterator I = Spellings.begin(), E = Spellings.end(); I != E; ++I) {
> -      StringRef Spelling = (*I)->getValueAsString("Name");
> +      SmallString<64> Spelling;
> +      Spelling += (*I)->getValueAsString("Name");

Using += rather than initialization seems rather strange. Is
SmallString missing the necessary constructor? (or even the necessary
assignment operator). This also defeats the (N)RVO, but I assume the
return type of getValueAsString is std::string not SmallString anyway,
so that doesn't apply - it might be more efficient just to use a
std::string though & rely on (N)RVO if that's applicable here - the
benefit of a SmallString is avoiding allocation, which is going to
occur (or not, depending on the implementation of std::string) anyway
if getValueAsString is returning one.

>       OS << ".Case(\"" << Spelling << "\", true)\n";
>     }
>   }
> @@ -1074,6 +1075,9 @@
>      << "} // end namespace clang\n";
>  }
>
> +}
> +#include <cstdio>
> +namespace clang {
>  // Emits the list of parsed attributes.
>  void EmitClangAttrParsedAttrList(RecordKeeper &Records, raw_ostream &OS) {
>   OS << "// This file is generated by TableGen. Do not edit.\n\n";
> @@ -1083,7 +1087,6 @@
>   OS << "#endif\n\n";
>
>   std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr");
> -  std::set<StringRef> ProcessedAttrs;
>
>   for (std::vector<Record*>::iterator I = Attrs.begin(), E = Attrs.end();
>        I != E; ++I) {
> @@ -1098,16 +1101,12 @@
>
>         for (std::vector<Record*>::const_iterator I = Spellings.begin(),
>              E = Spellings.end(); I != E; ++I) {
> -          StringRef AttrName = (*I)->getValueAsString("Name");
> +          SmallString<64> AttrName;
> +          AttrName += (*I)->getValueAsString("Name");
>
> -          AttrName = NormalizeAttrName(AttrName);
> -          // skip if a normalized version has been processed.
> -          if (ProcessedAttrs.find(AttrName) != ProcessedAttrs.end())
> -            continue;
> -          else
> -            ProcessedAttrs.insert(AttrName);
> +          StringRef Spelling = NormalizeAttrName(AttrName);
>
> -          OS << "PARSED_ATTR(" << AttrName << ")\n";
> +          OS << "PARSED_ATTR(" << Spelling << ")\n";
>         }
>       } else {
>         StringRef AttrName = Attr.getName();
> @@ -1138,9 +1137,10 @@
>
>       for (std::vector<Record*>::const_iterator I = Spellings.begin(),
>            E = Spellings.end(); I != E; ++I) {
> -        StringRef RawSpelling = (*I)->getValueAsString("Name");
> +        SmallString<64> RawSpelling;
> +        RawSpelling += (*I)->getValueAsString("Name");
>         StringRef AttrName = NormalizeAttrName(DistinctSpellings
> -                                                 ? RawSpelling
> +                                                 ? StringRef(RawSpelling)
>                                                  : StringRef(Attr.getName()));
>
>         SmallString<64> Spelling;
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list