1 | //
|
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2018 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 | // HandleAttributes.cc --
|
---|
8 | //
|
---|
9 | // Author : Rob Schluntz
|
---|
10 | // Created On : Fri Jul 27 10:15:06 2018
|
---|
11 | // Last Modified By : Rob Schluntz
|
---|
12 | // Last Modified On : Fri Jul 27 10:16:43 2018
|
---|
13 | // Update Count : 2
|
---|
14 | //
|
---|
15 |
|
---|
16 | #include "HandleAttributes.h"
|
---|
17 |
|
---|
18 | #include "CompilationState.h"
|
---|
19 | #include "Common/PassVisitor.h"
|
---|
20 | #include "Common/SemanticError.h"
|
---|
21 | #include "ResolvExpr/Resolver.h"
|
---|
22 | #include "SynTree/Attribute.h"
|
---|
23 | #include "SynTree/Declaration.h"
|
---|
24 | #include "SynTree/Type.h"
|
---|
25 |
|
---|
26 | namespace Validate {
|
---|
27 | namespace {
|
---|
28 | struct HandleAttributes : public WithIndexer {
|
---|
29 | void previsit( ObjectDecl * decl );
|
---|
30 | void previsit( FunctionDecl * decl );
|
---|
31 | };
|
---|
32 | } // namespace
|
---|
33 |
|
---|
34 | void handleAttributes( std::list< Declaration * > &translationUnit ) {
|
---|
35 | PassVisitor<HandleAttributes> handler;
|
---|
36 | acceptAll( translationUnit, handler );
|
---|
37 | }
|
---|
38 |
|
---|
39 | namespace {
|
---|
40 | void HandleAttributes::previsit( ObjectDecl * decl ) {
|
---|
41 | for ( Attribute * attr : decl->attributes ) {
|
---|
42 | std::string name = attr->normalizedName();
|
---|
43 | if (name == "init_priority") {
|
---|
44 | // TODO: implement C++-like init_priority attribute
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | void HandleAttributes::previsit( FunctionDecl * decl ) {
|
---|
50 | for ( Attribute * attr : decl->attributes ) {
|
---|
51 | std::string name = attr->normalizedName();
|
---|
52 | if (name == "constructor" || name == "destructor") {
|
---|
53 | if (attr->parameters.size() == 1) {
|
---|
54 | Expression *& arg = attr->parameters.front();
|
---|
55 | ResolvExpr::findSingleExpression( arg, new BasicType( Type::Qualifiers(), BasicType::LongLongSignedInt ), indexer );
|
---|
56 | auto result = eval(arg);
|
---|
57 | if (! result.second) {
|
---|
58 | SemanticWarning(attr->location, Warning::GccAttributes,
|
---|
59 | toCString( name, " priorities must be integers from 0 to 65535 inclusive: ", arg ) );
|
---|
60 | return;
|
---|
61 | }
|
---|
62 | auto priority = result.first;
|
---|
63 | if (priority < 101) {
|
---|
64 | SemanticWarning(attr->location, Warning::GccAttributes,
|
---|
65 | toCString( name, " priorities from 0 to 100 are reserved for the implementation" ) );
|
---|
66 | } else if (priority < 201 && ! buildingLibrary()) {
|
---|
67 | SemanticWarning(attr->location, Warning::GccAttributes,
|
---|
68 | toCString( name, " priorities from 101 to 200 are reserved for the implementation" ) );
|
---|
69 | }
|
---|
70 | } else if (attr->parameters.size() > 1) {
|
---|
71 | SemanticWarning(attr->location, Warning::GccAttributes, toCString( "too many arguments to ", name, " attribute" ) );
|
---|
72 | } else {
|
---|
73 | SemanticWarning(attr->location, Warning::GccAttributes, toCString( "too few arguments to ", name, " attribute" ) );
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 | }
|
---|
78 | } // namespace
|
---|
79 | } // namespace Validate
|
---|
80 |
|
---|
81 | // Local Variables: //
|
---|
82 | // tab-width: 4 //
|
---|
83 | // mode: c++ //
|
---|
84 | // compile-command: "make install" //
|
---|
85 | // End: //
|
---|