-
Notifications
You must be signed in to change notification settings - Fork 273
[SEC-179] Add annotations to java_class_typet #1831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
peterschrammel
merged 7 commits into
diffblue:develop
from
NathanJPhillips:feature/class-annotations
Apr 13, 2018
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ce1f4d2
Add annotations to java_class_typet, its methods and fields
NathanJPhillips 3ac6d17
Add type_dynamic_cast and friends for java_class_typet
NathanJPhillips e22b95b
Fix spurious virtual function related keywords
NathanJPhillips e6fb3bf
Pretty printing of java_class_typet
NathanJPhillips b06a27d
Introduce abstract qualifierst base class
NathanJPhillips ca77b4e
Add test for added annotations
NathanJPhillips 9a8d937
Add to_annotated_type and enable type_checked_cast for annotated_typet
NathanJPhillips File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@interface ClassAnnotation { | ||
} | ||
|
||
@interface MethodAnnotation { | ||
} | ||
|
||
@interface FieldAnnotation { | ||
} | ||
|
||
@ClassAnnotation | ||
public class annotations | ||
{ | ||
@FieldAnnotation | ||
public int x; | ||
|
||
@FieldAnnotation | ||
public static int y; | ||
|
||
@MethodAnnotation | ||
public void main() | ||
{ | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
regression/cbmc-java/annotations1/show_annotation_symbol.desc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CORE | ||
annotations.class | ||
--verbosity 10 --show-symbol-table | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^Type\.\.\.\.\.\.\.\.: @java::ClassAnnotation struct annotations | ||
^Type\.\.\.\.\.\.\.\.: @java::MethodAnnotation \(struct annotations \*\) -> void$ | ||
^Type\.\.\.\.\.\.\.\.: @java::FieldAnnotation int$ | ||
-- | ||
-- | ||
The purpose of the test is ensuring that annotations can be shown in the symbol | ||
table. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,27 @@ Author: Daniel Kroening, [email protected] | |
#include "c_qualifiers.h" | ||
|
||
#include <ostream> | ||
#include <util/make_unique.h> | ||
|
||
c_qualifierst &c_qualifierst::operator=(const c_qualifierst &other) | ||
{ | ||
is_constant = other.is_constant; | ||
is_volatile = other.is_volatile; | ||
is_restricted = other.is_restricted; | ||
is_atomic = other.is_atomic; | ||
is_noreturn = other.is_noreturn; | ||
is_ptr32 = other.is_ptr32; | ||
is_ptr64 = other.is_ptr64; | ||
is_transparent_union = other.is_transparent_union; | ||
return *this; | ||
} | ||
|
||
std::unique_ptr<qualifierst> c_qualifierst::clone() const | ||
{ | ||
auto other = util_make_unique<c_qualifierst>(); | ||
*other = *this; | ||
return std::move(other); | ||
} | ||
|
||
std::string c_qualifierst::as_string() const | ||
{ | ||
|
@@ -120,9 +141,7 @@ void c_qualifierst::clear(typet &dest) | |
} | ||
|
||
/// pretty-print the qualifiers | ||
std::ostream &operator << ( | ||
std::ostream &out, | ||
const c_qualifierst &c_qualifiers) | ||
std::ostream &operator<<(std::ostream &out, const qualifierst &qualifiers) | ||
{ | ||
return out << c_qualifiers.as_string(); | ||
return out << qualifiers.as_string(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,53 @@ Author: Daniel Kroening, [email protected] | |
#define CPROVER_ANSI_C_C_QUALIFIERS_H | ||
|
||
#include <iosfwd> | ||
#include <memory> | ||
|
||
#include <util/expr.h> | ||
|
||
class c_qualifierst | ||
class qualifierst | ||
{ | ||
protected: | ||
// Only derived classes can construct | ||
qualifierst() = default; | ||
|
||
public: | ||
// Copy/move construction/assignment is deleted here and in derived classes | ||
qualifierst(const qualifierst &) = delete; | ||
qualifierst(qualifierst &&) = delete; | ||
qualifierst &operator=(const qualifierst &) = delete; | ||
qualifierst &operator=(qualifierst &&) = delete; | ||
|
||
// Destruction is virtual | ||
virtual ~qualifierst() = default; | ||
|
||
public: | ||
virtual std::unique_ptr<qualifierst> clone() const = 0; | ||
|
||
virtual qualifierst &operator+=(const qualifierst &b) = 0; | ||
|
||
virtual std::size_t count() const = 0; | ||
|
||
virtual void clear() = 0; | ||
|
||
virtual void read(const typet &src) = 0; | ||
virtual void write(typet &src) const = 0; | ||
|
||
// Comparisons | ||
virtual bool is_subset_of(const qualifierst &q) const = 0; | ||
virtual bool operator==(const qualifierst &other) const = 0; | ||
bool operator!=(const qualifierst &other) const | ||
{ | ||
return !(*this == other); | ||
} | ||
|
||
// String conversion | ||
virtual std::string as_string() const = 0; | ||
friend std::ostream &operator<<(std::ostream &, const qualifierst &); | ||
}; | ||
|
||
|
||
class c_qualifierst : public qualifierst | ||
{ | ||
public: | ||
c_qualifierst() | ||
|
@@ -28,7 +71,12 @@ class c_qualifierst | |
read(src); | ||
} | ||
|
||
void clear() | ||
protected: | ||
c_qualifierst &operator=(const c_qualifierst &other); | ||
public: | ||
virtual std::unique_ptr<qualifierst> clone() const override; | ||
|
||
virtual void clear() override | ||
{ | ||
is_constant=false; | ||
is_volatile=false; | ||
|
@@ -50,62 +98,60 @@ class c_qualifierst | |
|
||
// will likely add alignment here as well | ||
|
||
std::string as_string() const; | ||
void read(const typet &src); | ||
void write(typet &src) const; | ||
virtual std::string as_string() const override; | ||
virtual void read(const typet &src) override; | ||
virtual void write(typet &src) const override; | ||
|
||
static void clear(typet &dest); | ||
|
||
bool is_subset_of(const c_qualifierst &q) const | ||
virtual bool is_subset_of(const qualifierst &other) const override | ||
{ | ||
return (!is_constant || q.is_constant) && | ||
(!is_volatile || q.is_volatile) && | ||
(!is_restricted || q.is_restricted) && | ||
(!is_atomic || q.is_atomic) && | ||
(!is_ptr32 || q.is_ptr32) && | ||
(!is_ptr64 || q.is_ptr64) && | ||
(!is_noreturn || q.is_noreturn); | ||
const c_qualifierst *cq = dynamic_cast<const c_qualifierst *>(&other); | ||
return | ||
(!is_constant || cq->is_constant) && | ||
(!is_volatile || cq->is_volatile) && | ||
(!is_restricted || cq->is_restricted) && | ||
(!is_atomic || cq->is_atomic) && | ||
(!is_ptr32 || cq->is_ptr32) && | ||
(!is_ptr64 || cq->is_ptr64) && | ||
(!is_noreturn || cq->is_noreturn); | ||
|
||
// is_transparent_union isn't checked | ||
} | ||
|
||
bool operator==(const c_qualifierst &other) const | ||
virtual bool operator==(const qualifierst &other) const override | ||
{ | ||
return is_constant==other.is_constant && | ||
is_volatile==other.is_volatile && | ||
is_restricted==other.is_restricted && | ||
is_atomic==other.is_atomic && | ||
is_ptr32==other.is_ptr32 && | ||
is_ptr64==other.is_ptr64 && | ||
is_transparent_union==other.is_transparent_union && | ||
is_noreturn==other.is_noreturn; | ||
const c_qualifierst *cq = dynamic_cast<const c_qualifierst *>(&other); | ||
return | ||
is_constant == cq->is_constant && | ||
is_volatile == cq->is_volatile && | ||
is_restricted == cq->is_restricted && | ||
is_atomic == cq->is_atomic && | ||
is_ptr32 == cq->is_ptr32 && | ||
is_ptr64 == cq->is_ptr64 && | ||
is_transparent_union == cq->is_transparent_union && | ||
is_noreturn == cq->is_noreturn; | ||
} | ||
|
||
bool operator!=(const c_qualifierst &other) const | ||
virtual qualifierst &operator+=(const qualifierst &other) override | ||
{ | ||
return !(*this==other); | ||
} | ||
|
||
c_qualifierst &operator+=(const c_qualifierst &b) | ||
{ | ||
is_constant|=b.is_constant; | ||
is_volatile|=b.is_volatile; | ||
is_restricted|=b.is_restricted; | ||
is_atomic|=b.is_atomic; | ||
is_ptr32|=b.is_ptr32; | ||
is_ptr64|=b.is_ptr64; | ||
is_transparent_union|=b.is_transparent_union; | ||
is_noreturn|=b.is_noreturn; | ||
const c_qualifierst *cq = dynamic_cast<const c_qualifierst *>(&other); | ||
is_constant |= cq->is_constant; | ||
is_volatile |= cq->is_volatile; | ||
is_restricted |= cq->is_restricted; | ||
is_atomic |= cq->is_atomic; | ||
is_ptr32 |= cq->is_ptr32; | ||
is_ptr64 |= cq->is_ptr64; | ||
is_transparent_union |= cq->is_transparent_union; | ||
is_noreturn |= cq->is_noreturn; | ||
return *this; | ||
} | ||
|
||
unsigned count() const | ||
virtual std::size_t count() const override | ||
{ | ||
return is_constant+is_volatile+is_restricted+is_atomic+ | ||
is_ptr32+is_ptr64+is_noreturn; | ||
} | ||
}; | ||
|
||
std::ostream &operator << (std::ostream &, const c_qualifierst &); | ||
|
||
#endif // CPROVER_ANSI_C_C_QUALIFIERS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ Author: Daniel Kroening, [email protected] | |
#include <util/std_code.h> | ||
#include <util/std_expr.h> | ||
|
||
class c_qualifierst; | ||
class qualifierst; | ||
class namespacet; | ||
|
||
class expr2ct | ||
|
@@ -36,7 +36,7 @@ class expr2ct | |
|
||
virtual std::string convert_rec( | ||
const typet &src, | ||
const c_qualifierst &qualifiers, | ||
const qualifierst &qualifiers, | ||
const std::string &declarator); | ||
|
||
virtual std::string convert_struct_type( | ||
|
@@ -53,12 +53,12 @@ class expr2ct | |
|
||
virtual std::string convert_array_type( | ||
const typet &src, | ||
const c_qualifierst &qualifiers, | ||
const qualifierst &qualifiers, | ||
const std::string &declarator_str); | ||
|
||
std::string convert_array_type( | ||
const typet &src, | ||
const c_qualifierst &qualifiers, | ||
const qualifierst &qualifiers, | ||
const std::string &declarator_str, | ||
bool inc_size_if_possible); | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,12 +19,22 @@ Author: Daniel Kroening, [email protected] | |
#include <util/arith_tools.h> | ||
#include <util/ieee_float.h> | ||
|
||
#include <ansi-c/c_qualifiers.h> | ||
#include <ansi-c/c_misc.h> | ||
#include <ansi-c/expr2c_class.h> | ||
|
||
#include "java_qualifiers.h" | ||
#include "java_types.h" | ||
|
||
std::string expr2javat::convert(const typet &src) | ||
{ | ||
return convert_rec(src, java_qualifierst(ns), ""); | ||
} | ||
|
||
std::string expr2javat::convert(const exprt &src) | ||
{ | ||
return expr2ct::convert(src); | ||
} | ||
|
||
std::string expr2javat::convert_code_function_call( | ||
const code_function_callt &src, | ||
unsigned indent) | ||
|
@@ -241,10 +251,11 @@ std::string expr2javat::convert_constant( | |
|
||
std::string expr2javat::convert_rec( | ||
const typet &src, | ||
const c_qualifierst &qualifiers, | ||
const qualifierst &qualifiers, | ||
const std::string &declarator) | ||
{ | ||
c_qualifierst new_qualifiers(qualifiers); | ||
std::unique_ptr<qualifierst> clone = qualifiers.clone(); | ||
qualifierst &new_qualifiers = *clone; | ||
new_qualifiers.read(src); | ||
|
||
const std::string d= | ||
|
@@ -307,7 +318,7 @@ std::string expr2javat::convert_rec( | |
const typet &return_type=code_type.return_type(); | ||
dest+=" -> "+convert(return_type); | ||
|
||
return dest; | ||
return q + dest; | ||
} | ||
else | ||
return expr2ct::convert_rec(src, qualifiers, declarator); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you even want to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To implement
clone
in derived classes we create an instance of the derived object, use this assignment to copy the base class data members to the new instance and then copy the derived class data.