source: src/AST/Attribute.cpp @ 7db39f7

Last change on this file since 7db39f7 was b262cb3, checked in by Andrew Beach <ajbeach@…>, 9 months ago

Unified and fixed handling of parameter attributes.

  • Property mode set to 100644
File size: 1.4 KB
Line 
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.cpp --
8//
9// Author           : Aaron B. Moss
10// Created On       : Fri May 10 10:30:00 2019
11// Last Modified By : Aaron B. Moss
12// Created On       : Fri May 10 10:30:00 2019
13// Update Count     : 1
14//
15
16#include "Attribute.hpp"
17
18#include <algorithm> // for transform
19#include <cctype>    // for tolower
20#include <iterator>  // for back_inserter
21#include <string>
22
23namespace ast {
24
25std::string Attribute::normalizedName() const {
26        // trim underscores
27        auto begin = name.find_first_not_of('_');
28        auto end = name.find_last_not_of('_');
29        if ( begin == std::string::npos || end == std::string::npos ) return "";
30
31        // convert to lowercase
32        std::string ret;
33        ret.reserve( end-begin+1 );
34        int (*tolower)(int) = std::tolower;
35        std::transform( &name[begin], &name[end+1], back_inserter( ret ), tolower );
36        return ret;
37}
38
39bool Attribute::isValidOnFuncParam() const {
40        // Attributes produce GCC errors when they appear on function
41        // parameters. This is an allow-list, switching to a forbid-list would
42        // have to at least mention:
43        // aligned
44        std::string norm = normalizedName();
45        return norm == "unused" || norm == "noreturn" || norm == "vector_size";
46}
47
48}
49
50// Local Variables: //
51// tab-width: 4 //
52// mode: c++ //
53// compile-command: "make install" //
54// End: //
Note: See TracBrowser for help on using the repository browser.