Page Menu
Home
Xreate
Search
Configure Global Search
Log In
Docs
Questions
Repository
Issues
Patches
Internal API
Files
F4001096
xreatemanager-modules.h
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, 5:52 AM
Size
3 KB
Mime Type
text/x-c++
Expires
Sat, Jul 11, 5:52 AM (1 d, 4 h)
Engine
blob
Format
Raw Data
Handle
272880
Attached To
rXR Xreate
xreatemanager-modules.h
View Options
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* File: PassManagerModular.h
* Author: pgess <v.melnychenko@xreate.org>
*
* Created on June 22, 2017, 5:32 PM
*/
/**
* \file xreatemanager-modules.h
* \brief XreateManager's decorator to support [Modules](/d/syntax/modules/).
*/
#ifndef PASSMANAGERMODULAR_H
#define PASSMANAGERMODULAR_H
#include "ast.h"
#include "modules.h"
#include "modules/Parser.h"
#include "main/Parser.h"
namespace xreate{namespace modules {
template<class Parent>
/** \brief XreateManager decorator to support [Modules](/d/syntax/modules/).
*
* Scans source code looking for other modules requirements.
* Finds and connects other modules to satisfy a current module's requirements
* \extends XreateManager
* \sa ModulesSolver, ModuleRecord
*/
class XreateManagerDecoratorModules: public Parent{
public:
XreateManagerDecoratorModules(){}
void prepareCode(std::string&& code) override {
Scanner scannerModules(reinterpret_cast<const unsigned char*>(code.c_str()), code.size());
std::list<std::string> listIncludedFiles;
parseModulesGrammar(scannerModules, listIncludedFiles);
grammar::main::Scanner scannerMain(reinterpret_cast<const unsigned char*>(code.c_str()), code.size());
parseMainGrammar(scannerMain, listIncludedFiles);
}
void prepareCode(FILE* code) override {
Scanner scannerModules(code);
std::list<std::string> listIncludedFiles;
parseModulesGrammar(scannerModules, listIncludedFiles);
grammar::main::Scanner scannerMain(code);
parseMainGrammar(scannerMain, listIncludedFiles);
}
private:
void parseModulesGrammar(Scanner& scanner, std::list<std::string>& listIncludedFiles){
ModulesSolver solver;
Parser parser(&scanner);
parser.Parse();
parser.module.__path = "";
solver.init("", parser.module);
std::list<std::string> modulesExternal = solver.run(parser.module);
std::string programBase = solver.__program.str();
for (const std::string module: modulesExternal){
parseModulesGrammar(module, programBase, listIncludedFiles);
}
}
void parseModulesGrammar(const std::string& path, std::string base, std::list<std::string>& listIncludedFiles){
FILE* input = fopen(path.c_str(), "r");
assert(input != nullptr);
Scanner scanner(input);
Parser parser(&scanner);
parser.Parse();
parser.module.__path = path;
fclose(input);
ModulesSolver solver;
solver.init(base, parser.module);
std::list<std::string>&& modulesExternal = solver.run(parser.module);
std::string programBase = solver.__program.str();
for (const std::string module: modulesExternal){
parseModulesGrammar(module, programBase, listIncludedFiles);
}
listIncludedFiles.push_back(path);
}
void parseMainGrammar(grammar::main::Scanner& scanner, std::list<std::string>& listIncludedFiles){
details::inconsistent::AST* ast = new AST;
grammar::main::Parser parser(&scanner);
parser.root = ast;
parser.Parse();
assert(!parser.errors->count && "Parser errors");
for (auto file: listIncludedFiles){
FILE* fileContent = fopen(file.c_str(), "r");
grammar::main::Scanner scanner(fileContent);
grammar::main::Parser parser(&scanner);
parser.root = ast;
parser.Parse();
fclose(fileContent);
assert(!parser.errors->count && "Parser errors");
}
PassManager::prepare(ast->finalize());
}
};
}} //end namespace xreate::modules
#endif /* PASSMANAGERMODULAR_H */
Event Timeline
Log In to Comment