source: src/SynTree/Attribute.cc@ df00c78

ADT ast-experimental pthread-emulation
Last change on this file since df00c78 was 17129659, checked in by Aaron Moss <a3moss@…>, 7 years ago

Fix line numbers in tests

  • 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
[17129659]23Attribute::Attribute( const Attribute &other ) : BaseSyntaxNode( other ), name( other.name ) {
[54c9000]24 cloneAll( other.parameters, parameters );
[db175c8]25}
26
27Attribute::~Attribute() {
[54c9000]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;
[db175c8]50}
51
[50377a4]52void Attribute::print( std::ostream &os, Indenter indent ) const {
[54c9000]53 using std::endl;
54 using std::string;
55
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 }
[db175c8]63}
64
65// Local Variables: //
66// tab-width: 4 //
67// mode: c++ //
68// compile-command: "make install" //
69// End: //
Note: See TracBrowser for help on using the repository browser.