#ifndef ASTTRANSFORMATION_H #define ASTTRANSFORMATION_H #include #include #include #include #include "Type.h" #include "ASTData.h" #include "NodeTransformation.h" #include "Importer.h" class Importer; class ASTTransformation: public NodeTransformation { public: ASTTransformation(Importer* importerIn); ~ASTTransformation(); NodeTree* getNode(std::string lookup, std::vector*> nodes); NodeTree* getNode(std::string lookup, NodeTree* parent); std::vector*> getNodes(std::string lookup, std::vector*> nodes); std::vector*> getNodes(std::string lookup, NodeTree* parent); //First pass defines all type_defs (objects and ailises) NodeTree* firstPass(std::string fileName, NodeTree* parseTree); std::set parseTraits(NodeTree* traitsNode); //Second pass defines data inside objects, outside declaration statements, and function prototpyes (since we have type_defs now) void secondPass(NodeTree* ast, NodeTree* parseTree); void secondPassDoClassInsides(NodeTree* typeDef, std::vector*> typedefChildren, std::map templateTypeReplacements); NodeTree* secondPassDeclaration(NodeTree* from, NodeTree* scope, std::map templateTypeReplacements); NodeTree* secondPassFunction(NodeTree* from, NodeTree* scope, std::map templateTypeReplacements); //The third pass does all the function bodies void thirdPass(NodeTree* ast, NodeTree* parseTree); NodeTree* searchScopeForFunctionDef(NodeTree* scope, NodeTree* parseTree, std::map templateTypeReplacements); void thirdPassFunction(NodeTree* from, NodeTree* functionDef, std::map templateTypeReplacements); //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* ast, NodeTree* parseTree); virtual NodeTree* transform(NodeTree* from); NodeTree* transform(NodeTree* from, NodeTree* scope, std::vector types, bool limitToFunction, std::map templateTypeReplacements); std::vector*> transformChildren(std::vector*> children, std::set skipChildren, NodeTree* scope, std::vector types, bool limitToFunction, std::map templateTypeReplacements); std::string concatSymbolTree(NodeTree* root); NodeTree* doFunction(NodeTree* scope, std::string lookup, std::vector*> nodes, std::map templateTypeReplacements); NodeTree* generateThis(NodeTree* scope); std::set*> findVariablesToClose(NodeTree* func, NodeTree* stat, NodeTree* scope); bool inScopeChain(NodeTree* node, NodeTree* scope); NodeTree* functionLookup(NodeTree* scope, std::string lookup, std::vector types); NodeTree* templateFunctionLookup(NodeTree* scope, std::string lookup, std::vector* templateInstantiationTypes, std::vector types, std::map scopeTypeMap); std::vector*> scopeLookup(NodeTree* scope, std::string lookup, bool includeModules = false); std::vector*> scopeLookup(NodeTree* scope, std::string lookup, bool includeModules, std::set*> visited); NodeTree* getUpperTranslationUnit(NodeTree* node); NodeTree* addToScope(std::string name, NodeTree* toAdd, NodeTree* addTo); Type* typeFromTypeNode(NodeTree* typeNode, NodeTree* scope, std::map templateTypeReplacements); NodeTree* templateClassLookup(NodeTree* scope, std::string name, std::vector templateInstantiationTypes); void unifyType(NodeTree *syntaxType, Type type, std::map* templateTypeMap, std::map typeMap); void unifyTemplateFunction(NodeTree* templateFunction, std::vector types, std::vector* templateInstantiationTypes, std::map typeMap); NodeTree* tryToFindOrInstantiateFunctionTemplate(std::string functionName, NodeTree* scope, std::vector types, std::map templateTypeReplacements); NodeTree* findOrInstantiateFunctionTemplate(std::string functionName, NodeTree* scope, std::vector types, std::map templateTypeReplacements); NodeTree* findOrInstantiateFunctionTemplate(std::vector*> children, NodeTree* scope, std::vector types, std::map templateTypeReplacements); NodeTree* findOrInstantiateFunctionTemplate(std::string functionName, std::vector*> children, NodeTree* scope, std::vector types, std::map templateTypeReplacements); std::map makeTemplateFunctionTypeMap(NodeTree* templateNode, std::vector types, std::map scopeTypeMap); std::vector>> makeTemplateNameTraitPairs(NodeTree* templateNode); private: Importer * importer; NodeTree* builtin_trans_unit; // the top scope for language level stuff std::map*>> languageLevelReservedWords; std::map*>> languageLevelOperators; std::map*, NodeTree*> this_map; // used to map implicit "this" variables to their type NodeTree* topScope; //maintained for templates that need to add themselves to the top scope no matter where they are instantiated int lambdaID = 0; }; std::vector mapNodesToTypes(std::vector*> nodes); std::vector mapNodesToTypePointers(std::vector*> nodes); #endif