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-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
|
|
|
|
|
|
|
|
//First pass defines all type_defs (objects and ailises)
|
|
|
|
|
NodeTree<ASTData>* firstPass(std::string fileName, NodeTree<Symbol>* parseTree);
|
|
|
|
|
|
|
|
|
|
//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);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
//Third pass redoes all imports to import the new function prototypes and identifiers
|
|
|
|
|
void thirdPass(NodeTree<ASTData>* ast);
|
|
|
|
|
|
|
|
|
|
//The fourth pass finishes up by doing all function bodies
|
|
|
|
|
void fourthPass(NodeTree<ASTData>* ast, NodeTree<Symbol>* parseTree);
|
|
|
|
|
NodeTree<ASTData>* seachScopeForFunctionDef(NodeTree<ASTData>* scope, NodeTree<Symbol>* parseTree, std::map<std::string, Type*> templateTypeReplacements);
|
|
|
|
|
void fourthPassFunction(NodeTree<Symbol>* from, NodeTree<ASTData>* functionDef, std::map<std::string, Type*> templateTypeReplacements);
|
|
|
|
|
|
2013-10-02 03:15:20 -04:00
|
|
|
virtual NodeTree<ASTData>* transform(NodeTree<Symbol>* from);
|
2014-05-09 02:56:55 -04:00
|
|
|
NodeTree<ASTData>* transform(NodeTree<Symbol>* from, NodeTree<ASTData>* scope, std::vector<Type> types, 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, std::map<std::string, Type*> templateTypeReplacements);
|
2014-03-06 13:13:40 -05:00
|
|
|
std::vector<Type> mapNodesToTypes(std::vector<NodeTree<ASTData>*> nodes);
|
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-03-06 13:13:40 -05:00
|
|
|
NodeTree<ASTData>* scopeLookup(NodeTree<ASTData>* scope, std::string lookup, std::vector<Type> types = std::vector<Type>());
|
2014-05-09 02:56:55 -04:00
|
|
|
Type* typeFromTypeNode(NodeTree<Symbol>* typeNode, NodeTree<ASTData>* scope, 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);
|
2013-09-26 15:16:58 -04:00
|
|
|
private:
|
2013-12-31 23:43:49 -06:00
|
|
|
Importer * importer;
|
2014-03-06 13:13:40 -05:00
|
|
|
std::map<std::string, std::vector<NodeTree<ASTData>*>> languageLevelScope;
|
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
|
2013-09-26 15:16:58 -04:00
|
|
|
};
|
2014-02-18 21:55:00 -05:00
|
|
|
|
2013-10-02 03:15:20 -04:00
|
|
|
#endif
|