Skip to content

Commit 2bdaafc

Browse files
Add more doxygen to language.h and mode.h
1 parent 74c2c3d commit 2bdaafc

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/langapi/language.h

+21
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,42 @@ class languaget:public messaget
114114

115115
// conversion of expressions
116116

117+
/// Formats the given expression in a language-specific way
118+
/// \param expr: the expression to format
119+
/// \param code: the formatted expression
120+
/// \param ns: a namespace
121+
/// \return false if conversion succeeds
117122
virtual bool from_expr(
118123
const exprt &expr,
119124
std::string &code,
120125
const namespacet &ns);
121126

127+
/// Formats the given type in a language-specific way
128+
/// \param type: the type to format
129+
/// \param code: the formatted type
130+
/// \param ns: a namespace
131+
/// \return false if conversion succeeds
122132
virtual bool from_type(
123133
const typet &type,
124134
std::string &code,
125135
const namespacet &ns);
126136

137+
/// Encodes the given type in a language-specific way
138+
/// \param type: the type to encode
139+
/// \param name: the encoded type
140+
/// \param ns: a namespace
141+
/// \return false if the conversion succeeds
127142
virtual bool type_to_name(
128143
const typet &type,
129144
std::string &name,
130145
const namespacet &ns);
131146

147+
/// Parses the given string into an expression
148+
/// \param code: the string to parse
149+
/// \param module: prefix to be used for identifiers
150+
/// \param expr: the parsed expression
151+
/// \param ns: a namespace
152+
/// \return false if the conversion succeeds
132153
virtual bool to_expr(
133154
const std::string &code,
134155
const std::string &module,

src/langapi/mode.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ struct language_entryt
3131
typedef std::list<language_entryt> languagest;
3232
languagest languages;
3333

34+
/// Register a language
35+
/// Note: registering a language is required for using the functions
36+
/// in language_util.h
37+
/// \param factory: a language factory, e.g. `new_ansi_c_language`
3438
void register_language(language_factoryt factory)
3539
{
3640
languages.push_back(language_entryt());
@@ -40,6 +44,9 @@ void register_language(language_factoryt factory)
4044
languages.back().mode=l->id();
4145
}
4246

47+
/// Get the language corresponding to the given mode
48+
/// \param mode: the mode, e.g. `ID_C`
49+
/// \return the language or `nullptr` if the language has not been registered
4350
std::unique_ptr<languaget> get_language_from_mode(const irep_idt &mode)
4451
{
4552
for(const auto &language : languages)
@@ -87,6 +94,10 @@ get_language_from_identifier(const namespacet &ns, const irep_idt &identifier)
8794
return language;
8895
}
8996

97+
/// Get the language corresponding to the registered file name extensions
98+
/// \param filename: a filename
99+
/// \return the corresponding language or `nullptr` if the extension cannot
100+
/// be resolved to any registered language
90101
std::unique_ptr<languaget> get_language_from_filename(
91102
const std::string &filename)
92103
{
@@ -122,6 +133,8 @@ std::unique_ptr<languaget> get_language_from_filename(
122133
return nullptr;
123134
}
124135

136+
/// Returns the default language
137+
/// \return the first registered language
125138
std::unique_ptr<languaget> get_default_language()
126139
{
127140
PRECONDITION(!languages.empty());

0 commit comments

Comments
 (0)