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 |
|
---|
16 | #include <ostream> // for operator<<, ostream, basic_ostream, endl
|
---|
17 | #include <set>
|
---|
18 |
|
---|
19 | #include "Attribute.h"
|
---|
20 | #include "Common/utility.h" // for cloneAll, deleteAll, printAll
|
---|
21 | #include "Expression.h" // for Expression
|
---|
22 |
|
---|
23 | Attribute::Attribute( const Attribute &other ) : name( other.name ) {
|
---|
24 | cloneAll( other.parameters, parameters );
|
---|
25 | }
|
---|
26 |
|
---|
27 | bool 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 |
|
---|
37 | std::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;
|
---|
46 | }
|
---|
47 |
|
---|
48 | void Attribute::print( std::ostream &os, Indenter indent ) const {
|
---|
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 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | // Local Variables: //
|
---|
62 | // tab-width: 4 //
|
---|
63 | // mode: c++ //
|
---|
64 | // compile-command: "make install" //
|
---|
65 | // End: //
|
---|