Last change
on this file since 16ba4897 was
4ec9513,
checked in by Andrew Beach <ajbeach@…>, 3 years ago
|
Converted validate C, including adding DimensionExpr? to the new ast.
|
-
Property mode set to
100644
|
File size:
1.4 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 | // ReturnCheck.cpp -- Run simple (non-typed) checks on return statements. |
---|
8 | // |
---|
9 | // Author : Andrew Beach |
---|
10 | // Created On : Fri Mar 18 14:07:00 2022 |
---|
11 | // Last Modified By : Andrew Beach |
---|
12 | // Last Modified On : Fri Mar 18 14:26:00 2022 |
---|
13 | // Update Count : 0 |
---|
14 | // |
---|
15 | |
---|
16 | #include "ReturnCheck.hpp" |
---|
17 | |
---|
18 | #include "AST/Decl.hpp" |
---|
19 | #include "AST/Pass.hpp" |
---|
20 | #include "AST/Stmt.hpp" |
---|
21 | #include "AST/TranslationUnit.hpp" |
---|
22 | |
---|
23 | namespace Validate { |
---|
24 | |
---|
25 | namespace { |
---|
26 | |
---|
27 | struct ReturnCore : public ast::WithGuards { |
---|
28 | bool inVoidFunction = false; |
---|
29 | |
---|
30 | void previsit( const ast::FunctionDecl * decl ) { |
---|
31 | GuardValue( inVoidFunction ) = (0 == decl->returns.size()); |
---|
32 | } |
---|
33 | |
---|
34 | void previsit( const ast::ReturnStmt * stmt ) { |
---|
35 | // The only definite error case is an empty return on a non-void |
---|
36 | // functions. Everything else requires resolution. (You can have |
---|
37 | // a void expression in a return statement. |
---|
38 | if ( !stmt->expr && !inVoidFunction ) { |
---|
39 | SemanticError( stmt, "Non-void function returns no values: " ); |
---|
40 | } |
---|
41 | } |
---|
42 | }; |
---|
43 | |
---|
44 | } // namespace |
---|
45 | |
---|
46 | void checkReturnStatements( ast::TranslationUnit & translationUnit ) { |
---|
47 | ast::Pass<ReturnCore>::run( translationUnit ); |
---|
48 | } |
---|
49 | |
---|
50 | } // namespace Validate |
---|
51 | |
---|
52 | // Local Variables: // |
---|
53 | // tab-width: 4 // |
---|
54 | // mode: c++ // |
---|
55 | // compile-command: "make install" // |
---|
56 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.