/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * 
 * Author: pgess <v.melnychenko@xreate.org>
 * 
 * dfapass.h
 * Data Flow Graph building pass
 */

#ifndef DFGPASS_H
#define DFGPASS_H

#include "abstractpass.h"
#include "analysis/dfagraph.h"

namespace xreate {
    class TranscendLayer;
}

namespace xreate { namespace dfa {
    
struct ProcessingCache {
    std::vector<SymbolNode> operands;
    std::vector<SymbolNode> blocks;
}; 
    
/** \brief Data Flow Analysis Pass(%DFA) */
class DFAPass: public AbstractPass<SymbolNode> {
public:
    DFAPass(PassManager* manager);
    
protected:
    virtual void processAnnotations(const Expression& expression, PassContext context, const SymbolNode& ident);
    virtual SymbolNode process(const Expression& expression, PassContext context, const std::string& varDecl="") override;
    virtual SymbolNode process(CodeScope* scope, PassContext context, const std::string& hintBlockDecl="") override;
    virtual SymbolNode process(ManagedFnPtr function) override;

    void init();
    void finish() override;
    
    DFAGraph* graph;
    TranscendLayer* transcend;
    
private:
    void processCallInstance(const Expression& expr, PassContext context, const SymbolNode& result);
    void processDependencies(const SymbolNode& node, const Expression& expression, PassContext context, ProcessingCache& cache);
};

}}  //end of xreate::dfa  namespace

#endif
