[1931bb01] | 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 | // |
---|
[11df881] | 7 | // VerifyCtorDtorAssign.cpp -- Check the form of operators. |
---|
[1931bb01] | 8 | // |
---|
| 9 | // Author : Andrew Beach |
---|
| 10 | // Created On : Mon Jul 4 10:26:00 2022 |
---|
| 11 | // Last Modified By : Andrew Beach |
---|
| 12 | // Last Modified On : Mon Jul 12 11:26:00 2022 |
---|
| 13 | // Update Count : 0 |
---|
| 14 | // |
---|
| 15 | |
---|
| 16 | #include "VerifyCtorDtorAssign.hpp" |
---|
| 17 | |
---|
| 18 | #include "AST/Pass.hpp" |
---|
| 19 | #include "CodeGen/OperatorTable.h" |
---|
| 20 | |
---|
| 21 | namespace Validate { |
---|
| 22 | |
---|
| 23 | namespace { |
---|
| 24 | |
---|
| 25 | struct VerifyCore { |
---|
| 26 | void previsit( ast::FunctionDecl const * decl ); |
---|
| 27 | }; |
---|
| 28 | |
---|
| 29 | void VerifyCore::previsit( ast::FunctionDecl const * decl ) { |
---|
| 30 | // Skip any of the functions we are not checking. |
---|
| 31 | // Should get contructors, destructors and all forms of assignment. |
---|
| 32 | if ( !CodeGen::isCtorDtorAssign( decl->name ) ) { |
---|
| 33 | return; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | if ( 0 == decl->params.size() ) { |
---|
| 37 | SemanticError( decl->location, "Constructors, destructors, and assignment functions require at least one parameter." ); |
---|
| 38 | } |
---|
| 39 | auto refType = decl->type->params.front().as<ast::ReferenceType>(); |
---|
| 40 | if ( !refType ) { |
---|
| 41 | SemanticError( decl->location, "First parameter of a constructor, destructor, or assignment function must be a reference." ); |
---|
| 42 | } |
---|
| 43 | if ( CodeGen::isCtorDtor( decl->name ) && 0 != decl->returns.size() |
---|
| 44 | && !decl->returns.front()->get_type()->isVoid() ) { |
---|
| 45 | SemanticError( decl->location, "Constructors and destructors cannot have explicit return values." ); |
---|
| 46 | } |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | } // namespace |
---|
| 50 | |
---|
| 51 | void verifyCtorDtorAssign( ast::TranslationUnit & translationUnit ) { |
---|
| 52 | ast::Pass<VerifyCore>::run( translationUnit ); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | } // namespace Validate |
---|
| 56 | |
---|
| 57 | // Local Variables: // |
---|
| 58 | // tab-width: 4 // |
---|
| 59 | // mode: c++ // |
---|
| 60 | // compile-command: "make install" // |
---|
| 61 | // End: // |
---|