forked from avast/retdec
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,35 @@ | ||
|
||
#ifndef RETDEC_CTYPES_NAMED_TYPE_H | ||
#define RETDEC_CTYPES_NAMED_TYPE_H | ||
|
||
#include "retdec/ctypes/type.h" | ||
#include "retdec/ctypes/context.h" | ||
|
||
namespace retdec { | ||
namespace ctypes { | ||
|
||
/** | ||
* @brief A representation of custom types. | ||
*/ | ||
class NamedType: public Type { | ||
public: | ||
static std::shared_ptr<NamedType> create( | ||
const std::shared_ptr<Context> &context, | ||
const std::string &name | ||
); | ||
|
||
/// @name Visitor interface. | ||
/// @{ | ||
void accept(Visitor *v) override; | ||
/// @} | ||
|
||
bool isNamed() const override; | ||
|
||
private: | ||
explicit NamedType(const std::string &name); | ||
}; | ||
|
||
} // namespace ctypes | ||
} // namespace retdec | ||
|
||
#endif //RETDEC_CTYPES_NAMED_TYPE_H |
This file contains 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 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 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 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 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 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,62 @@ | ||
/** | ||
* @file src/ctypes/named_type.cpp | ||
* @brief Implementation of custom types. | ||
* @copyright (c) 2018 Avast Software, licensed under the MIT license | ||
*/ | ||
|
||
#include <cassert> | ||
|
||
#include "retdec/ctypes/named_type.h" | ||
#include "retdec/ctypes/visitor.h" | ||
|
||
namespace retdec { | ||
namespace ctypes { | ||
|
||
/** | ||
* @brief Constructs new NamedType | ||
*/ | ||
NamedType::NamedType(const std::string &name) : Type(name, 0) {} | ||
|
||
/** | ||
* @brief Creates named type. | ||
* | ||
* @param context Storage for already created functions, types. | ||
* @param name Name of new named type. | ||
* | ||
* @par Preconditions | ||
* - @a context is not null | ||
* | ||
* Does not create new name type, if one | ||
* has already been created and stored in @c context. | ||
*/ | ||
std::shared_ptr<NamedType> NamedType::create( | ||
const std::shared_ptr<retdec::ctypes::Context> &context, | ||
const std::string &name) | ||
{ | ||
assert(context && "violated precondition - context cannot be null"); | ||
|
||
auto type = context->getNamedType(name); | ||
if (type && type->isNamed()) { | ||
return std::static_pointer_cast<NamedType>(type); | ||
} | ||
|
||
std::shared_ptr<NamedType> newType(new NamedType(name)); | ||
context->addNamedType(newType); | ||
return newType; | ||
} | ||
|
||
/** | ||
* Returns @c true when Type is class, @c false otherwise. | ||
*/ | ||
bool NamedType::isNamed() const | ||
{ | ||
return true; | ||
} | ||
|
||
void NamedType::accept(retdec::ctypes::Visitor *v) | ||
{ | ||
v->visit(std::static_pointer_cast<NamedType>(shared_from_this())); | ||
} | ||
|
||
} // namespace ctypes | ||
} // namespace retdec |
This file contains 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 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