From 52ae7f1842e0f079152902ee73008a2a00aaeb3f Mon Sep 17 00:00:00 2001
From: David Robillard <d@drobilla.net>
Date: Sun, 15 Mar 2009 15:16:09 +0000
Subject: Set name of closures so defined functions are emitted with meaningful
 names.

git-svn-id: http://svn.drobilla.net/resp/tuplr@103 ad02d1e2-f140-0410-9f75-f8b11f17cedd
---
 tuplr.hpp | 34 ++++++++++++----------------------
 1 file changed, 12 insertions(+), 22 deletions(-)

(limited to 'tuplr.hpp')

diff --git a/tuplr.hpp b/tuplr.hpp
index 21ed121..3e051c1 100644
--- a/tuplr.hpp
+++ b/tuplr.hpp
@@ -146,10 +146,11 @@ extern ostream& operator<<(ostream& out, const AST* ast);
 struct AST {
 	AST(Cursor c=Cursor()) : loc(c) {}
 	virtual ~AST() {}
-	virtual bool operator==(const AST& o)   const = 0;
-	virtual bool contains(const AST* child) const { return false; }
-	virtual void constrain(TEnv& tenv, Constraints& c) const {}
-	virtual void lift(CEnv& cenv)                 {}
+	virtual bool   operator==(const AST& o) const = 0;
+	virtual bool   contains(const AST* child) const { return false; }
+	virtual void   constrain(TEnv& tenv, Constraints& c) const {}
+	virtual void   lift(CEnv& cenv) {}
+	virtual CValue compile(CEnv& cenv) = 0;
 	string str() const { ostringstream ss; ss << this; return ss.str(); }
 	template<typename T> T as() {
 		T t = dynamic_cast<T>(this);
@@ -157,9 +158,6 @@ struct AST {
 		return t;
 	}
 	Cursor loc;
-private:
-	friend class CEnv;
-	virtual CValue compile(CEnv& cenv) = 0;
 };
 
 /// Literal value
@@ -180,12 +178,11 @@ struct ASymbol : public AST {
 	bool   operator==(const AST& rhs) const { return this == &rhs; }
 	void   constrain(TEnv& tenv, Constraints& c) const;
 	CValue compile(CEnv& cenv);
-	mutable LAddr        addr;
+	mutable LAddr  addr;
+	const   string cppstr;
 private:
 	friend class PEnv;
 	ASymbol(const string& s, Cursor c) : AST(c), cppstr(s) {}
-	friend ostream& operator<<(ostream&, const AST*);
-	const string cppstr;
 };
 
 /// Tuple (heterogeneous sequence of fixed length), e.g. "(a b c)"
@@ -208,10 +205,7 @@ struct ATuple : public AST, public vector<AST*> {
 				return false;
 		return true;
 	}
-	void lift(CEnv& cenv) {
-		FOREACH(iterator, t, *this)
-			(*t)->lift(cenv);
-	}
+	void lift(CEnv& cenv) { FOREACH(iterator, t, *this) (*t)->lift(cenv); }
 	bool contains(AST* child) const {
 		if (*this == *child) return true;
 		FOREACH(const_iterator, p, *this)
@@ -300,10 +294,9 @@ struct AClosure : public ATuple {
 	void    liftCall(CEnv& cenv, const vector<AType*>& argsT);
 	CValue  compile(CEnv& cenv);
 	ATuple* prot() const { return dynamic_cast<ATuple*>(at(1)); }
-	Funcs   funcs;
-	mutable Subst*  subst;
-private:
-	string name;
+	Funcs          funcs;
+	mutable Subst* subst;
+	string         name;
 };
 
 /// Function call/application, e.g. "(func arg1 arg2)"
@@ -488,10 +481,7 @@ struct TEnv : public Env< const ASymbol*, pair<AST*, AType*> > {
 	}
 	AST* resolve(AST* ast) {
 		ASymbol* sym = dynamic_cast<ASymbol*>(ast);
-		if (sym)
-			return ref(sym)->first;
-		else
-			return ast;
+		return sym ? ref(sym)->first : ast;
 	}
 	static Subst unify(const Constraints& c);
 
-- 
cgit v1.2.1