Page Menu
Home
Xreate
Search
Configure Global Search
Log In
Docs
Questions
Repository
Issues
Patches
Internal API
Files
F4000746
adhocpass.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jul 9, 4:46 AM
Size
2 KB
Mime Type
text/x-c++
Expires
Sat, Jul 11, 4:46 AM (1 d, 4 h)
Engine
blob
Format
Raw Data
Handle
273344
Attached To
rXR Xreate
adhocpass.cpp
View Options
/*
* adhoc.cpp
*
* Created on: Nov 28, 2015
* Author: pgess
*/
#include "pass/adhocpass.h"
#include "query/context.h"
//TODO use ADT/templated types rather than adhocs. remove adhocs.
namespace xreate { namespace adhoc {
AdhocExpression::AdhocExpression(): Expression(Operator::ADHOC, {})
{}
AdhocExpression::AdhocExpression(const Expression& base): Expression(base)
{}
void
AdhocExpression::setCommand(const Expression& comm){
this->addTags({Expression(Operator::CALL, {Atom<Identifier_t>("adhoc"), comm})});
}
Expression
AdhocExpression::getCommand() const{
assert(this->tags.count("adhoc"));
return this->tags.at("adhoc").getOperands().at(0);
}
AdhocScheme*
AdhocPass::findAssotiatedScheme(CodeScope* entry){
const ScopePacked scopeId = man->clasp->pack(entry);
const context::Domain& domain = queryContext->getContext(scopeId);
AdhocScheme* scheme = nullptr;
for (const Expression& context: domain){
if (!(context.__state == Expression::COMPOUND && context.op == Operator::CALL)) continue;
if (__schemes.count(context.getValueString())){
assert(!scheme && "Can't determine relevant scheme, ambiguous context");
scheme = __schemes.at(context.getValueString());
}
}
assert(scheme && "Context doesn't define any ad hoc scheme");
return scheme;
}
const TypeAnnotation&
AdhocScheme::getResultType(){
return __resultType;
}
CodeScope*
AdhocScheme::getCommandImplementation(const Expression& comm) {
assert(comm.__state == Expression::COMPOUND && comm.op == Operator::CALL && comm.operands.size() == 0);
const std::string commSerialized = comm.getValueString();
assert(__commands.count(commSerialized) && "Command isn't defined for a selected scheme");
return __commands.at(commSerialized);
}
AdhocScheme::AdhocScheme(const Expression& scheme):
__resultType(scheme.type), __name(scheme.getValueString()) {
Expression exprCasesList = scheme.getOperands()[0];
for (const Expression& exprSingleCase: exprCasesList.getOperands()){
std::string command = exprSingleCase.tags.begin()->second.getValueString();
CodeScope* blockImpl = *(exprSingleCase.blocks.begin());
__commands.emplace(command, blockImpl);
}
}
const std::string&
AdhocScheme::getName(){
return __name;
}
void
AdhocPass::run(){
queryContext = reinterpret_cast<context::ContextQuery*>(man->clasp->registerQuery(new context::ContextQuery(), QueryId::ContextQuery));
auto range = man->root->__interfacesData.equal_range(ASTInterface::Adhoc);
for (auto i=range.first; i!= range.second; ++i){
AdhocScheme* scheme = new AdhocScheme(i->second);
__schemes.emplace(scheme->getName(), scheme);
}
}
}} //end of namespace xreate::adhoc
Event Timeline
Log In to Comment