-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of SCode in C++ (#11428)
- Implements classes for the SCode/Absyn records used by the frontend, so far mostly just handling the conversion from MetaModelica to C++ and implementing some simple printing. Everything is merged into one Absyn namespace since the long term goal is to get rid of SCode and only have a single abstract syntax representation.
- Loading branch information
Showing
70 changed files
with
5,831 additions
and
30 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "Util.h" | ||
#include "Algorithm.h" | ||
|
||
using namespace OpenModelica; | ||
using namespace OpenModelica::Absyn; | ||
|
||
Algorithm::Algorithm(MetaModelica::Record value) | ||
: _statements{value[0].mapVector<Statement>()} | ||
{ | ||
|
||
} | ||
|
||
std::ostream& OpenModelica::Absyn::operator<< (std::ostream &os, const Algorithm &algorithm) | ||
{ | ||
os << "algorithm\n"; | ||
|
||
for (auto &s: algorithm.statements()) { | ||
s.print(os, " "); | ||
os << ";\n"; | ||
} | ||
|
||
return os; | ||
} |
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,23 @@ | ||
#ifndef ABSYN_ALGORITHM_H | ||
#define ABSYN_ALGORITHM_H | ||
|
||
#include "MetaModelica.h" | ||
#include "Statement.h" | ||
|
||
namespace OpenModelica::Absyn | ||
{ | ||
class Algorithm | ||
{ | ||
public: | ||
Algorithm(MetaModelica::Record value); | ||
|
||
const std::vector<Statement>& statements() const noexcept { return _statements; } | ||
|
||
private: | ||
std::vector<Statement> _statements; | ||
}; | ||
|
||
std::ostream& operator<< (std::ostream &os, const Algorithm &algorithm); | ||
}; | ||
|
||
#endif /* ABSYN_ALGORITHM_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <ostream> | ||
|
||
#include "Annotation.h" | ||
|
||
using namespace OpenModelica::Absyn; | ||
|
||
Annotation::Annotation(MetaModelica::Record value) | ||
: _modifier{value[0]} | ||
{ | ||
|
||
} | ||
|
||
void Annotation::print(std::ostream &os, std::string_view indent) const noexcept | ||
{ | ||
if (!_modifier.isEmpty()) { | ||
os << indent << "annotation" << _modifier; | ||
} | ||
} | ||
|
||
std::ostream& OpenModelica::Absyn::operator<< (std::ostream &os, const Annotation &annotation) noexcept | ||
{ | ||
annotation.print(os); | ||
return os; | ||
} |
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,29 @@ | ||
#ifndef ABSYN_ANNOTATION_H | ||
#define ABSYN_ANNOTATION_H | ||
|
||
#include <string_view> | ||
#include <iosfwd> | ||
|
||
#include "MetaModelica.h" | ||
#include "Modifier.h" | ||
|
||
namespace OpenModelica::Absyn | ||
{ | ||
class Annotation | ||
{ | ||
public: | ||
Annotation() = default; | ||
Annotation(MetaModelica::Record value); | ||
|
||
const Modifier& modifier() const noexcept { return _modifier; } | ||
|
||
void print(std::ostream &os, std::string_view indent = {}) const noexcept; | ||
|
||
private: | ||
Modifier _modifier; | ||
}; | ||
|
||
std::ostream& operator<< (std::ostream &os, const Annotation &annotation) noexcept; | ||
} | ||
|
||
#endif /* ANNOTATION_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
set(OMC_FRONTEND_CPP_ABSYN_SOURCES | ||
Algorithm.cpp | ||
Annotation.cpp | ||
Class.cpp | ||
ClassDef.cpp | ||
Comment.cpp | ||
Component.cpp | ||
ComponentRef.cpp | ||
ConstrainingClass.cpp | ||
DefineUnit.cpp | ||
Element.cpp | ||
ElementAttributes.cpp | ||
ElementPrefixes.cpp | ||
Equation.cpp | ||
Expression.cpp | ||
Extends.cpp | ||
ExternalDecl.cpp | ||
FunctionArgs.cpp | ||
FunctionArgsList.cpp | ||
FunctionArgsIter.cpp | ||
Import.cpp | ||
ImportPath.cpp | ||
Iterator.cpp | ||
Modifier.cpp | ||
Operator.cpp | ||
Statement.cpp | ||
Subscript.cpp | ||
TypeSpec.cpp) | ||
|
||
add_library(omcfrontendcppabsyn STATIC) | ||
add_library(omc::compiler::frontendcpp::absyn ALIAS omcfrontendcppabsyn) | ||
|
||
target_sources(omcfrontendcppabsyn PRIVATE ${OMC_FRONTEND_CPP_ABSYN_SOURCES}) | ||
|
||
target_include_directories(omcfrontendcppabsyn PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..) |
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,40 @@ | ||
#include <ostream> | ||
|
||
#include "Class.h" | ||
|
||
using namespace OpenModelica::Absyn; | ||
|
||
Class::Class(MetaModelica::Record value) | ||
: Element::Base(SourceInfo{value[7]}), | ||
_name{value[0].toString()}, | ||
_prefixes{value[1]}, | ||
_encapsulated{value[2]}, | ||
_partial{value[3]}, | ||
_restriction{value[4]}, | ||
_classDef{value[5]}, | ||
_comment{value[6]} | ||
{ | ||
|
||
} | ||
|
||
const std::string& Class::name() const noexcept | ||
{ | ||
return _name; | ||
} | ||
|
||
const Comment& Class::comment() const noexcept | ||
{ | ||
return _comment; | ||
} | ||
|
||
std::unique_ptr<Element::Base> Class::clone() const noexcept | ||
{ | ||
return std::make_unique<Class>(*this); | ||
} | ||
|
||
void Class::print(std::ostream &os, Each each) const noexcept | ||
{ | ||
_prefixes.print(os, each); | ||
os << _encapsulated.unparse() << _partial.unparse() << _restriction << ' '; | ||
_classDef.print(os, *this); | ||
} |
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,37 @@ | ||
#ifndef ABSYN_CLASS_H | ||
#define ABSYN_CLASS_H | ||
|
||
#include <string> | ||
|
||
#include "MetaModelica.h" | ||
#include "Element.h" | ||
#include "ElementPrefixes.h" | ||
#include "Restriction.h" | ||
#include "ClassDef.h" | ||
#include "Comment.h" | ||
|
||
namespace OpenModelica::Absyn | ||
{ | ||
class Class : public Element::Base | ||
{ | ||
public: | ||
Class(MetaModelica::Record value); | ||
|
||
const std::string& name() const noexcept; | ||
const Comment& comment() const noexcept; | ||
|
||
std::unique_ptr<Element::Base> clone() const noexcept override; | ||
void print(std::ostream &os, Each each) const noexcept override; | ||
|
||
private: | ||
std::string _name; | ||
ElementPrefixes _prefixes; | ||
Encapsulated _encapsulated; | ||
Partial _partial; | ||
Restriction _restriction; | ||
ClassDef _classDef; | ||
Comment _comment; | ||
}; | ||
} | ||
|
||
#endif /* ABSYN_CLASS_H */ |
Oops, something went wrong.