source: src/Validate/HandleAttributes.cc @ 835d6e8

ADTast-experimental
Last change on this file since 835d6e8 was 9feb34b, checked in by Andrew Beach <ajbeach@…>, 15 months ago

Moved toString and toCString to a new header. Updated includes. cassert was somehow getting instances of toString before but that stopped working so I embedded the new smaller include.

  • Property mode set to 100644
File size: 2.9 KB
Line 
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/Eval.h"
20#include "Common/PassVisitor.h"
21#include "Common/ToString.hpp"
22#include "Common/SemanticError.h"
23#include "ResolvExpr/Resolver.h"
24#include "SynTree/Attribute.h"
25#include "SynTree/Declaration.h"
26#include "SynTree/Type.h"
27
28namespace Validate {
29        namespace {
30                struct HandleAttributes : public WithIndexer {
31                        void previsit( ObjectDecl * decl );
32                        void previsit( FunctionDecl * decl );
33                };
34        } // namespace
35
36        void handleAttributes( std::list< Declaration * > &translationUnit ) {
37                PassVisitor<HandleAttributes> handler;
38                acceptAll( translationUnit, handler );
39        }
40
41        namespace {
42                void HandleAttributes::previsit( ObjectDecl * decl ) {
43                        for ( Attribute * attr : decl->attributes ) {
44                                std::string name = attr->normalizedName();
45                                if (name == "init_priority") {
46                                        // TODO: implement C++-like init_priority attribute
47                                }
48                        }
49                }
50
51                void HandleAttributes::previsit( FunctionDecl * decl ) {
52                        for ( Attribute * attr : decl->attributes ) {
53                                std::string name = attr->normalizedName();
54                                if (name == "constructor" || name == "destructor") {
55                                        if (attr->parameters.size() == 1) {
56                                                Expression *& arg = attr->parameters.front();
57                                                ResolvExpr::findSingleExpression( arg, new BasicType( Type::Qualifiers(), BasicType::LongLongSignedInt ), indexer );
58                                                auto result = eval(arg);
59                                                if (! result.second) {
60                                                        SemanticWarning(attr->location, Warning::GccAttributes,
61                                                                toCString( name, " priorities must be integers from 0 to 65535 inclusive: ", arg ) );
62                                                        return;
63                                                }
64                                                auto priority = result.first;
65                                                if (priority < 101) {
66                                                        SemanticWarning(attr->location, Warning::GccAttributes,
67                                                                toCString( name, " priorities from 0 to 100 are reserved for the implementation" ) );
68                                                } else if (priority < 201 && ! buildingLibrary()) {
69                                                        SemanticWarning(attr->location, Warning::GccAttributes,
70                                                                toCString( name, " priorities from 101 to 200 are reserved for the implementation" ) );
71                                                }
72                                        } else if (attr->parameters.size() > 1) {
73                                                SemanticWarning(attr->location, Warning::GccAttributes, toCString( "too many arguments to ", name, " attribute" ) );
74                                        } else {
75                                                SemanticWarning(attr->location, Warning::GccAttributes, toCString( "too few arguments to ", name, " attribute" ) );
76                                        }
77                                }
78                        }
79                }
80        } // namespace
81} // namespace Validate
82
83// Local Variables: //
84// tab-width: 4 //
85// mode: c++ //
86// compile-command: "make install" //
87// End: //
Note: See TracBrowser for help on using the repository browser.