Ignore:
Timestamp:
Feb 13, 2018, 11:12:25 AM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
490ff5c3
Parents:
7a052e34
git-author:
Rob Schluntz <rschlunt@…> (02/12/18 16:21:06)
git-committer:
Rob Schluntz <rschlunt@…> (02/13/18 11:12:25)
Message:

Fix missing attribute warning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Attribute.cc

    r7a052e34 r54c9000  
    1515
    1616#include <ostream>           // for operator<<, ostream, basic_ostream, endl
     17#include <set>
    1718
    1819#include "Attribute.h"
     
    2122
    2223Attribute::Attribute( const Attribute &other ) : name( other.name ) {
    23   cloneAll( other.parameters, parameters );
     24        cloneAll( other.parameters, parameters );
    2425}
    2526
    2627Attribute::~Attribute() {
    27   deleteAll( parameters );
     28        deleteAll( parameters );
     29}
     30
     31bool Attribute::isValidOnFuncParam() const {
     32        // attributes such as aligned, cleanup, etc. produce GCC errors when they appear
     33        // on function parameters. Maintain here a whitelist of attribute names that are
     34        // allowed to appear on parameters.
     35        static std::set< std::string > valid = {
     36                "noreturn", "unused"
     37        };
     38        return valid.count( normalizedName() );
     39}
     40
     41std::string Attribute::normalizedName() const {
     42        // trim beginning/ending _, convert to lowercase
     43        auto begin = name.find_first_not_of('_');
     44        auto end = name.find_last_not_of('_');
     45        if (begin == std::string::npos || end == std::string::npos) return "";
     46        std::string ret;
     47        ret.reserve( end-begin+1 );
     48        std::transform( &name[begin], &name[end+1], back_inserter( ret ), tolower );
     49        return ret;
    2850}
    2951
    3052void Attribute::print( std::ostream &os, Indenter indent ) const {
    31   using std::endl;
    32   using std::string;
     53        using std::endl;
     54        using std::string;
    3355
    34   if ( ! empty() ) {
    35     os << "Attribute with name: " << name;
    36     if ( ! parameters.empty() ) {
    37       os << " with parameters: " << endl;
    38       printAll( parameters, os, indent+1 );
    39     }
    40   }
     56        if ( ! empty() ) {
     57                os << "Attribute with name: " << name;
     58                if ( ! parameters.empty() ) {
     59                        os << " with parameters: " << endl;
     60                        printAll( parameters, os, indent+1 );
     61                }
     62        }
    4163}
    4264
Note: See TracChangeset for help on using the changeset viewer.