2013-11-01 02:52:18 -04:00
|
|
|
#ifndef CGENERATOR_H
|
|
|
|
|
#define CGENERATOR_H
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <iostream>
|
2014-01-01 17:29:19 -06:00
|
|
|
#include <fstream>
|
2014-12-30 01:22:09 -05:00
|
|
|
#include <utility>
|
2015-05-15 15:19:55 -04:00
|
|
|
#include <stack>
|
2014-12-30 01:22:09 -05:00
|
|
|
#include <sys/stat.h>
|
2013-11-01 02:52:18 -04:00
|
|
|
|
2015-05-30 04:43:01 -04:00
|
|
|
#include "CCodeTriple.h"
|
2013-11-01 02:52:18 -04:00
|
|
|
#include "NodeTree.h"
|
|
|
|
|
#include "ASTData.h"
|
2013-12-23 01:26:24 -06:00
|
|
|
#include "Type.h"
|
2013-11-01 02:52:18 -04:00
|
|
|
|
2013-12-19 10:39:36 -06:00
|
|
|
#include "util.h"
|
2014-05-21 13:14:16 -04:00
|
|
|
#include "Poset.h"
|
2013-12-19 10:39:36 -06:00
|
|
|
|
2014-12-30 01:22:09 -05:00
|
|
|
// 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.
|
2013-11-01 02:52:18 -04:00
|
|
|
|
2015-06-25 04:09:19 -04:00
|
|
|
enum ClosureTypeSpecialType { ClosureTypeRegularNone, ClosureFunctionPointerTypeWithClosedParam };
|
|
|
|
|
|
2013-11-01 02:52:18 -04:00
|
|
|
class CGenerator {
|
|
|
|
|
public:
|
|
|
|
|
CGenerator();
|
|
|
|
|
~CGenerator();
|
2014-01-01 17:29:19 -06:00
|
|
|
void generateCompSet(std::map<std::string, NodeTree<ASTData>*> ASTs, std::string outputName);
|
2014-07-28 01:52:15 -07:00
|
|
|
std::string generateClassStruct(NodeTree<ASTData>* from);
|
2014-12-30 01:22:09 -05:00
|
|
|
bool isUnderTranslationUnit(NodeTree<ASTData>* from, NodeTree<ASTData>* typeDefinition);
|
|
|
|
|
NodeTree<ASTData>* highestScope(NodeTree<ASTData>* node);
|
2015-03-11 01:58:10 -04:00
|
|
|
std::pair<std::string, std::string> generateTranslationUnit(std::string name, std::map<std::string, NodeTree<ASTData>*> ASTs);
|
2015-06-25 04:09:19 -04:00
|
|
|
CCodeTriple generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enclosingObject = NULL, bool justFuncName = false, NodeTree<ASTData>* enclosingFunction = NULL);
|
2015-03-11 01:58:10 -04:00
|
|
|
std::string generateAliasChains(std::map<std::string, NodeTree<ASTData>*> ASTs, NodeTree<ASTData>* definition);
|
2015-06-25 04:09:19 -04:00
|
|
|
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);
|
2014-05-10 19:28:36 -04:00
|
|
|
static std::string CifyName(std::string name);
|
2015-04-04 01:32:40 -04:00
|
|
|
static std::string scopePrefix(NodeTree<ASTData>* from);
|
2014-12-30 01:22:09 -05:00
|
|
|
std::string generateObjectMethod(NodeTree<ASTData>* enclosingObject, NodeTree<ASTData>* from, std::string *functionPrototype);
|
2014-06-10 23:59:39 -07:00
|
|
|
NodeTree<ASTData>* getMethodsObjectType(NodeTree<ASTData>* scope, std::string functionName);
|
2015-06-05 00:34:24 -04:00
|
|
|
NodeTree<ASTData>* getMethod(Type* type, std::string method, std::vector<Type> types);
|
|
|
|
|
bool methodExists(Type* type, std::string method, std::vector<Type> types);
|
|
|
|
|
std::string generateMethodIfExists(Type* type, std::string method, std::string parameter, std::vector<Type> methodTypes);
|
2015-05-30 04:43:01 -04:00
|
|
|
std::string emitDestructors(std::vector<NodeTree<ASTData>*> possibleDeclarations, NodeTree<ASTData>* enclosingObject);
|
2015-05-15 15:19:55 -04:00
|
|
|
std::string tabs();
|
2015-05-30 04:43:01 -04:00
|
|
|
std::string getID();
|
2015-05-15 15:19:55 -04:00
|
|
|
|
|
|
|
|
int tabLevel;
|
2015-05-30 04:43:01 -04:00
|
|
|
int id;
|
2015-06-12 14:16:28 -04:00
|
|
|
std::string function_header;
|
2013-12-22 01:34:59 -06:00
|
|
|
std::string generatorString;
|
2015-04-10 00:37:31 -04:00
|
|
|
std::string linkerString;
|
2015-05-22 22:30:25 -04:00
|
|
|
std::string functionTypedefString;
|
2015-06-25 04:09:19 -04:00
|
|
|
std::map<Type, std::pair<std::string, std::string>> functionTypedefMap;
|
2015-05-30 04:43:01 -04:00
|
|
|
std::vector<std::vector<NodeTree<ASTData>*>> distructDoubleStack;
|
|
|
|
|
std::stack<int> loopDistructStackDepth;
|
2015-05-15 15:19:55 -04:00
|
|
|
std::vector<std::vector<NodeTree<ASTData>*>> deferDoubleStack;
|
|
|
|
|
std::stack<int> loopDeferStackDepth;
|
2013-11-01 02:52:18 -04:00
|
|
|
private:
|
|
|
|
|
};
|
2014-06-10 23:59:39 -07:00
|
|
|
#endif
|