Traits for function templates working! Need to finish for objects and specilizations, and I think also else statements.

This commit is contained in:
Nathan Braswell
2014-07-18 08:52:15 -07:00
parent 46b9fc8b7f
commit 64fcb6b0b7
14 changed files with 396 additions and 174 deletions

View File

@@ -4,6 +4,9 @@
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include "Type.h"
#include "ASTData.h"
#include "NodeTransformation.h"
@@ -18,6 +21,7 @@ class ASTTransformation: public NodeTransformation<Symbol,ASTData> {
//First pass defines all type_defs (objects and ailises)
NodeTree<ASTData>* firstPass(std::string fileName, NodeTree<Symbol>* parseTree);
std::set<std::string> parseTraits(NodeTree<Symbol>* traitsNode);
//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);
@@ -39,10 +43,15 @@ class ASTTransformation: public NodeTransformation<Symbol,ASTData> {
std::vector<Type> mapNodesToTypes(std::vector<NodeTree<ASTData>*> nodes);
std::string concatSymbolTree(NodeTree<Symbol>* root);
NodeTree<ASTData>* doFunction(NodeTree<ASTData>* scope, std::string lookup, std::vector<NodeTree<ASTData>*> nodes, std::map<std::string, Type*> templateTypeReplacements);
NodeTree<ASTData>* scopeLookup(NodeTree<ASTData>* scope, std::string lookup, std::vector<Type> types = std::vector<Type>());
NodeTree<ASTData>* functionLookup(NodeTree<ASTData>* scope, std::string lookup, std::vector<Type> types);
NodeTree<ASTData>* templateFunctionLookup(NodeTree<ASTData>* scope, std::string lookup, std::vector<Type*> templateInstantiationTypes, std::vector<Type> types);
std::vector<NodeTree<ASTData>*> scopeLookup(NodeTree<ASTData>* scope, std::string lookup);
Type* typeFromTypeNode(NodeTree<Symbol>* typeNode, NodeTree<ASTData>* scope, std::map<std::string, Type*> templateTypeReplacements, bool instantiateTemplates);
NodeTree<ASTData>* findOrInstantiateFunctionTemplate(std::vector<NodeTree<Symbol>*> children, NodeTree<ASTData>* scope, std::vector<Type> types, std::map<std::string, Type*> templateTypeReplacements);
std::map<std::string, Type*> makeTemplateFunctionTypeMap(NodeTree<Symbol>* templateNode, std::vector<Type*> types);
std::vector<std::pair<std::string, std::set<std::string>>> makeTemplateFunctionNameTraitPairs(NodeTree<Symbol>* templateNode);
private:
Importer * importer;
std::map<std::string, std::vector<NodeTree<ASTData>*>> languageLevelReservedWords;

View File

@@ -5,12 +5,9 @@
#define NULL ((void*)0)
#endif
#ifndef SEGFAULT
#define SEGFAULT (*((char*)0)), std::cout << "\t\t\t\tNEGATIVE*************************************************************************" << std::endl;
#endif
#include <string>
#include <iostream>
#include <set>
//Circular dependency
class ASTData;
@@ -23,12 +20,12 @@ enum ValueType {none, template_type, template_type_type, void_type, boolean, int
class Type {
public:
Type();
Type(ValueType typeIn, int indirectionIn);
Type(ValueType typeIn);
Type(NodeTree<ASTData>* typeDefinitionIn);
Type(NodeTree<ASTData>* typeDefinitionIn, int indirectionIn);
Type(ValueType typeIn, NodeTree<ASTData>* typeDefinitionIn, int indirectionIn);
Type(ValueType typeIn, NodeTree<Symbol>* templateDefinitionIn);
Type(ValueType typeIn, int indirectionIn = 0);
Type(ValueType typeIn, std::set<std::string> traitsIn); //Mostly for template type type's
Type(NodeTree<ASTData>* typeDefinitionIn, int indirectionIn = 0);
Type(NodeTree<ASTData>* typeDefinitionIn, std::set<std::string> traitsIn);
Type(ValueType typeIn, NodeTree<ASTData>* typeDefinitionIn, int indirectionIn, std::set<std::string> traitsIn);
Type(ValueType typeIn, NodeTree<Symbol>* templateDefinitionIn, std::set<std::string> traitsIn = std::set<std::string>());
~Type();
bool const operator==(const Type &other)const;
bool const operator!=(const Type &other)const;
@@ -39,13 +36,13 @@ class Type {
void increaseIndirection();
void decreaseIndirection();
void modifyIndirection(int mod);
void check();
ValueType baseType;
NodeTree<ASTData>* typeDefinition;
NodeTree<Symbol>* templateDefinition;
std::map<std::string, Type*> templateTypeReplacement;
private:
std::set<std::string> traits;
private:
int indirection;
};