2013-09-26 15:16:58 -04:00
|
|
|
#ifndef ASTTRANSFORMATION_H
|
|
|
|
|
#define ASTTRANSFORMATION_H
|
|
|
|
|
|
2013-12-27 13:05:07 -06:00
|
|
|
#include <set>
|
|
|
|
|
#include <map>
|
|
|
|
|
|
2014-07-18 08:52:15 -07:00
|
|
|
#include <iterator>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
2014-01-07 13:14:58 -05:00
|
|
|
#include "Type.h"
|
2013-10-02 03:15:20 -04:00
|
|
|
#include "ASTData.h"
|
2013-09-26 15:16:58 -04:00
|
|
|
#include "NodeTransformation.h"
|
2013-12-31 23:43:49 -06:00
|
|
|
#include "Importer.h"
|
|
|
|
|
|
|
|
|
|
class Importer;
|
2013-09-26 15:16:58 -04:00
|
|
|
|
2013-10-02 03:15:20 -04:00
|
|
|
class ASTTransformation: public NodeTransformation<Symbol,ASTData> {
|
2013-09-26 15:16:58 -04:00
|
|
|
public:
|
2013-12-31 23:43:49 -06:00
|
|
|
ASTTransformation(Importer* importerIn);
|
2013-09-26 15:16:58 -04:00
|
|
|
~ASTTransformation();
|
2014-05-24 14:04:32 -04:00
|
|
|
|
2015-05-10 02:18:59 -04:00
|
|
|
NodeTree<Symbol>* getNode(std::string lookup, std::vector<NodeTree<Symbol>*> nodes);
|
|
|
|
|
NodeTree<Symbol>* getNode(std::string lookup, NodeTree<Symbol>* parent);
|
|
|
|
|
std::vector<NodeTree<Symbol>*> getNodes(std::string lookup, std::vector<NodeTree<Symbol>*> nodes);
|
|
|
|
|
std::vector<NodeTree<Symbol>*> getNodes(std::string lookup, NodeTree<Symbol>* parent);
|
|
|
|
|
|
2014-05-24 14:04:32 -04:00
|
|
|
//First pass defines all type_defs (objects and ailises)
|
|
|
|
|
NodeTree<ASTData>* firstPass(std::string fileName, NodeTree<Symbol>* parseTree);
|
2014-07-18 08:52:15 -07:00
|
|
|
std::set<std::string> parseTraits(NodeTree<Symbol>* traitsNode);
|
2014-06-09 00:21:38 -07:00
|
|
|
|
2014-05-24 14:04:32 -04:00
|
|
|
//Second pass defines data inside objects, outside declaration statements, and function prototpyes (since we have type_defs now)
|
|
|
|
|
void secondPass(NodeTree<ASTData>* ast, NodeTree<Symbol>* parseTree);
|
2014-06-10 00:53:30 -07:00
|
|
|
void secondPassDoClassInsides(NodeTree<ASTData>* typeDef, std::vector<NodeTree<Symbol>*> typedefChildren, std::map<std::string, Type*> templateTypeReplacements);
|
2014-05-24 14:04:32 -04:00
|
|
|
NodeTree<ASTData>* secondPassDeclaration(NodeTree<Symbol>* from, NodeTree<ASTData>* scope, std::map<std::string, Type*> templateTypeReplacements);
|
|
|
|
|
NodeTree<ASTData>* secondPassFunction(NodeTree<Symbol>* from, NodeTree<ASTData>* scope, std::map<std::string, Type*> templateTypeReplacements);
|
2014-06-09 00:21:38 -07:00
|
|
|
|
2015-06-28 14:27:48 -04:00
|
|
|
//The third pass does all the function bodies
|
2015-03-24 18:29:21 -04:00
|
|
|
void thirdPass(NodeTree<ASTData>* ast, NodeTree<Symbol>* parseTree);
|
2014-07-23 02:23:21 -07:00
|
|
|
NodeTree<ASTData>* searchScopeForFunctionDef(NodeTree<ASTData>* scope, NodeTree<Symbol>* parseTree, std::map<std::string, Type*> templateTypeReplacements);
|
2015-03-24 18:29:21 -04:00
|
|
|
void thirdPassFunction(NodeTree<Symbol>* from, NodeTree<ASTData>* functionDef, std::map<std::string, Type*> templateTypeReplacements);
|
2014-05-24 14:04:32 -04:00
|
|
|
|
2015-06-28 14:27:48 -04:00
|
|
|
//The fourth pass finishes instantiation of templated objects
|
|
|
|
|
//it used to be a part of the third pass, but it was split out because it has to be done in a loop
|
|
|
|
|
//with all the other asts until none change anymore (it returns a bool if it instantiated a new one)
|
|
|
|
|
bool fourthPass(NodeTree<ASTData>* ast, NodeTree<Symbol>* parseTree);
|
|
|
|
|
|
2013-10-02 03:15:20 -04:00
|
|
|
virtual NodeTree<ASTData>* transform(NodeTree<Symbol>* from);
|
2015-06-12 14:16:28 -04:00
|
|
|
NodeTree<ASTData>* transform(NodeTree<Symbol>* from, NodeTree<ASTData>* scope, std::vector<Type> types, bool limitToFunction, std::map<std::string, Type*> templateTypeReplacements);
|
|
|
|
|
std::vector<NodeTree<ASTData>*> transformChildren(std::vector<NodeTree<Symbol>*> children, std::set<int> skipChildren, NodeTree<ASTData>* scope, std::vector<Type> types, bool limitToFunction, std::map<std::string, Type*> templateTypeReplacements);
|
2013-10-16 01:43:18 -04:00
|
|
|
std::string concatSymbolTree(NodeTree<Symbol>* root);
|
2014-05-09 02:56:55 -04:00
|
|
|
NodeTree<ASTData>* doFunction(NodeTree<ASTData>* scope, std::string lookup, std::vector<NodeTree<ASTData>*> nodes, std::map<std::string, Type*> templateTypeReplacements);
|
2014-07-18 08:52:15 -07:00
|
|
|
|
2015-06-27 18:06:02 -04:00
|
|
|
NodeTree<ASTData>* generateThis(NodeTree<ASTData>* scope);
|
|
|
|
|
std::set<NodeTree<ASTData>*> findVariablesToClose(NodeTree<ASTData>* func, NodeTree<ASTData>* stat, NodeTree<ASTData>* scope);
|
2015-06-25 04:09:19 -04:00
|
|
|
bool inScopeChain(NodeTree<ASTData>* node, NodeTree<ASTData>* scope);
|
2014-07-18 08:52:15 -07:00
|
|
|
NodeTree<ASTData>* functionLookup(NodeTree<ASTData>* scope, std::string lookup, std::vector<Type> types);
|
2015-05-27 00:58:33 -04:00
|
|
|
NodeTree<ASTData>* templateFunctionLookup(NodeTree<ASTData>* scope, std::string lookup, std::vector<Type*>* templateInstantiationTypes, std::vector<Type> types, std::map<std::string, Type*> scopeTypeMap);
|
2014-07-23 02:23:21 -07:00
|
|
|
std::vector<NodeTree<ASTData>*> scopeLookup(NodeTree<ASTData>* scope, std::string lookup, bool includeModules = false);
|
2015-06-01 01:43:23 -04:00
|
|
|
std::vector<NodeTree<ASTData>*> scopeLookup(NodeTree<ASTData>* scope, std::string lookup, bool includeModules, std::set<NodeTree<ASTData>*> visited);
|
2014-06-09 00:21:38 -07:00
|
|
|
|
2015-03-11 01:58:10 -04:00
|
|
|
NodeTree<ASTData>* getUpperTranslationUnit(NodeTree<ASTData>* node);
|
2015-04-04 01:32:40 -04:00
|
|
|
NodeTree<ASTData>* addToScope(std::string name, NodeTree<ASTData>* toAdd, NodeTree<ASTData>* addTo);
|
2014-07-23 02:23:21 -07:00
|
|
|
Type* typeFromTypeNode(NodeTree<Symbol>* typeNode, NodeTree<ASTData>* scope, std::map<std::string, Type*> templateTypeReplacements);
|
2014-07-20 14:21:41 -07:00
|
|
|
NodeTree<ASTData>* templateClassLookup(NodeTree<ASTData>* scope, std::string name, std::vector<Type*> templateInstantiationTypes);
|
2015-05-27 00:58:33 -04:00
|
|
|
void unifyType(NodeTree<Symbol> *syntaxType, Type type, std::map<std::string, Type>* templateTypeMap, std::map<std::string, Type*> typeMap);
|
|
|
|
|
void unifyTemplateFunction(NodeTree<ASTData>* templateFunction, std::vector<Type> types, std::vector<Type*>* templateInstantiationTypes, std::map<std::string, Type*> typeMap);
|
2015-08-03 18:37:42 -04:00
|
|
|
NodeTree<ASTData>* tryToFindOrInstantiateFunctionTemplate(std::string functionName, NodeTree<ASTData>* scope, std::vector<Type> types, std::map<std::string, Type*> templateTypeReplacements);
|
|
|
|
|
NodeTree<ASTData>* findOrInstantiateFunctionTemplate(std::string functionName, NodeTree<ASTData>* scope, std::vector<Type> types, std::map<std::string, Type*> templateTypeReplacements);
|
2014-05-15 17:58:41 -04:00
|
|
|
NodeTree<ASTData>* findOrInstantiateFunctionTemplate(std::vector<NodeTree<Symbol>*> children, NodeTree<ASTData>* scope, std::vector<Type> types, std::map<std::string, Type*> templateTypeReplacements);
|
2015-08-03 18:37:42 -04:00
|
|
|
NodeTree<ASTData>* findOrInstantiateFunctionTemplate(std::string functionName, std::vector<NodeTree<Symbol>*> children, NodeTree<ASTData>* scope, std::vector<Type> types, std::map<std::string, Type*> templateTypeReplacements);
|
2015-05-27 00:58:33 -04:00
|
|
|
std::map<std::string, Type*> makeTemplateFunctionTypeMap(NodeTree<Symbol>* templateNode, std::vector<Type*> types, std::map<std::string, Type*> scopeTypeMap);
|
2014-07-20 14:21:41 -07:00
|
|
|
std::vector<std::pair<std::string, std::set<std::string>>> makeTemplateNameTraitPairs(NodeTree<Symbol>* templateNode);
|
2015-04-04 01:32:40 -04:00
|
|
|
|
2013-09-26 15:16:58 -04:00
|
|
|
private:
|
2013-12-31 23:43:49 -06:00
|
|
|
Importer * importer;
|
2015-04-04 01:32:40 -04:00
|
|
|
NodeTree<ASTData>* builtin_trans_unit; // the top scope for language level stuff
|
2014-06-26 01:45:44 -07:00
|
|
|
std::map<std::string, std::vector<NodeTree<ASTData>*>> languageLevelReservedWords;
|
|
|
|
|
std::map<std::string, std::vector<NodeTree<ASTData>*>> languageLevelOperators;
|
2015-08-08 02:50:36 -04:00
|
|
|
std::map<NodeTree<ASTData>*, NodeTree<ASTData>*> this_map; // used to map implicit "this" variables to their type
|
2014-05-10 19:28:36 -04:00
|
|
|
NodeTree<ASTData>* topScope; //maintained for templates that need to add themselves to the top scope no matter where they are instantiated
|
2015-05-25 22:03:24 -04:00
|
|
|
int lambdaID = 0;
|
2013-09-26 15:16:58 -04:00
|
|
|
};
|
2014-02-18 21:55:00 -05:00
|
|
|
|
2015-06-26 13:29:37 -04:00
|
|
|
std::vector<Type> mapNodesToTypes(std::vector<NodeTree<ASTData>*> nodes);
|
|
|
|
|
std::vector<Type*> mapNodesToTypePointers(std::vector<NodeTree<ASTData>*> nodes);
|
|
|
|
|
|
2013-10-02 03:15:20 -04:00
|
|
|
#endif
|