source: src/SynTree/Attribute.cc@ 6fa409e

new-env
Last change on this file since 6fa409e was 68f9c43, checked in by Aaron Moss <a3moss@…>, 8 years ago

First pass at delete removal

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[db175c8]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// Attribute.cc --
8//
9// Author : Rob Schluntz
10// Created On : Mon June 06 14:51:16 2016
11// Last Modified By : Rob Schluntz
12// Last Modified On : Mon June 06 14:54:48 2016
13// Update Count : 1
14//
15
[ea6332d]16#include <ostream> // for operator<<, ostream, basic_ostream, endl
[54c9000]17#include <set>
[db175c8]18
19#include "Attribute.h"
[ea6332d]20#include "Common/utility.h" // for cloneAll, deleteAll, printAll
21#include "Expression.h" // for Expression
[db175c8]22
23Attribute::Attribute( const Attribute &other ) : name( other.name ) {
[54c9000]24 cloneAll( other.parameters, parameters );
[db175c8]25}
26
[54c9000]27bool Attribute::isValidOnFuncParam() const {
28 // attributes such as aligned, cleanup, etc. produce GCC errors when they appear
29 // on function parameters. Maintain here a whitelist of attribute names that are
30 // allowed to appear on parameters.
31 static std::set< std::string > valid = {
32 "noreturn", "unused"
33 };
34 return valid.count( normalizedName() );
35}
36
37std::string Attribute::normalizedName() const {
38 // trim beginning/ending _, convert to lowercase
39 auto begin = name.find_first_not_of('_');
40 auto end = name.find_last_not_of('_');
41 if (begin == std::string::npos || end == std::string::npos) return "";
42 std::string ret;
43 ret.reserve( end-begin+1 );
44 std::transform( &name[begin], &name[end+1], back_inserter( ret ), tolower );
45 return ret;
[db175c8]46}
47
[50377a4]48void Attribute::print( std::ostream &os, Indenter indent ) const {
[54c9000]49 using std::endl;
50 using std::string;
51
52 if ( ! empty() ) {
53 os << "Attribute with name: " << name;
54 if ( ! parameters.empty() ) {
55 os << " with parameters: " << endl;
56 printAll( parameters, os, indent+1 );
57 }
58 }
[db175c8]59}
60
61// Local Variables: //
62// tab-width: 4 //
63// mode: c++ //
64// compile-command: "make install" //
65// End: //
Note: See TracBrowser for help on using the repository browser.