source: src/Validate/VerifyCtorDtorAssign.cpp @ 11df881

ADTast-experimentalpthread-emulationqualifiedEnum
Last change on this file since 11df881 was 11df881, checked in by Andrew Beach <ajbeach@…>, 2 years ago

Updated documentation on pre-resolver passes, moving code to headers instead of uses. Note that some comments were just copied over, I don't know if they are accurate.

  • Property mode set to 100644
File size: 1.7 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// VerifyCtorDtorAssign.cpp -- Check the form of operators.
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
21namespace Validate {
22
23namespace {
24
25struct VerifyCore {
26        void previsit( ast::FunctionDecl const * decl );
27};
28
29void 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
51void 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: //
Note: See TracBrowser for help on using the repository browser.