#ifndef CGENERATOR_H #define CGENERATOR_H #include #include #include #include #include #include #include "CCodeTriple.h" #include "NodeTree.h" #include "ASTData.h" #include "Type.h" // for mapNodesToTypes #include "ASTTransformation.h" #include "util.h" #include "Poset.h" // Note the use of std::pair to hold two strings - the running string for the header file and the running string for the c file. enum ClosureTypeSpecialType { ClosureTypeRegularNone, ClosureFunctionPointerTypeWithoutClosedParam, ClosureFunctionPointerTypeWithClosedParam }; class CGenerator { public: CGenerator(); ~CGenerator(); void generateCompSet(std::map*> ASTs, std::string outputName); std::string generateClassStruct(NodeTree* from); bool isUnderTranslationUnit(NodeTree* from, NodeTree* typeDefinition); NodeTree* highestScope(NodeTree* node); std::pair generateTranslationUnit(std::string name, std::map*> ASTs); CCodeTriple generate(NodeTree* from, NodeTree* enclosingObject = NULL, bool justFuncName = false, NodeTree* enclosingFunction = NULL); std::string generateAliasChains(std::map*> ASTs, NodeTree* definition); std::string closureStructType(std::set*> closedVariables); std::string ValueTypeToCType(Type *type, std::string, ClosureTypeSpecialType closureSpecial = ClosureTypeRegularNone); std::string ValueTypeToCTypeDecoration(Type *type, ClosureTypeSpecialType closureSpecial = ClosureTypeRegularNone); std::string ValueTypeToCTypeThingHelper(Type *type, std::string ptrStr, ClosureTypeSpecialType closureSpecial); static std::string CifyName(std::string name); static std::string scopePrefix(NodeTree* from); std::string generateObjectMethod(NodeTree* enclosingObject, NodeTree* from, std::string *functionPrototype); NodeTree* getMethodsObjectType(NodeTree* scope, std::string functionName); NodeTree* getMethod(Type* type, std::string method, std::vector types); bool methodExists(Type* type, std::string method, std::vector types); std::string generateMethodIfExists(Type* type, std::string method, std::string parameter, std::vector methodTypes); std::string emitDestructors(std::vector*> possibleDeclarations, NodeTree* enclosingObject); std::string tabs(); std::string getID(); int tabLevel; int id; std::string function_header; std::string generatorString; std::string linkerString; std::string functionTypedefString; std::string functionTypedefStringPre; std::map> functionTypedefMap; std::map*>, std::string> closureStructMap; std::vector*>> distructDoubleStack; std::stack loopDistructStackDepth; std::vector*>> deferDoubleStack; std::stack loopDeferStackDepth; private: }; #endif