#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "c3/tags.h"
#include "c3/tree.h"
#include "c3/util.h"
#include "c3/sema/scope.h"
#include "package.h"
#include "context.h"
int resolve_tree(struct c3tree *);
int serialize_deps(struct c3tree *);
// needs to be able to patch the source...
int t_init(struct c3tree *);
int t_node(uint32_t source);
int expr_init(struct c3tree *);
uint32_t l_fn(uint32_t index);
int expr_finish(void);
int expr_gen_test(void);
static int
anal_execute(struct c3tree *tree)
{
/*
uint32_t i;
uint32_t dep_node;
uint16_t kids = c3nodekids(*tree, tree->graphs.deps);
for(i = 0; i < kids; i += 1){
dep_node = c3nodechild(*tree, tree->graphs.deps, i);
// TODO: comptime engine
if(!t_node(dep_node)){
ERROR("Type analysis failed!", 0);
return 0;
}
if(c3nodetag(*tree, dep_node) == C3_VALUE_FN){
if(l_fn(dep_node) == -1){
ERROR("Failed to extract expression semantics", 0);
return 0;
}
}
}
*/
WARN("analysis is currently disabled, pending major changes being merged.", 0);
return 0;
}
static int
anal_finish(struct c3tree *tree, int good, int out)
{
char c = 1;
// if(!expr_finish())
// return 0;
if(!good)
return 0;
if(out == -1)
return 1;
if(write(out, &c, 1) != 1){
ERROR("Failed to write tree message type", 0);
return 0;
}
if(!c3write(tree, out)){
ERROR("Failed to send tree to parent", 0);
return 0;
}
return 1;
}
int
analysis(struct c3tree *tree, int out)
{
int good;
// if(!t_init(tree))
// return 0;
// if(!expr_init(tree))
// return 0;
if(!resolve_tree(tree)){
ERROR("Tree resolution failed!", 0);
return 0;
}
scope_free();
if(tree->graphs.deps == -1){
ERROR("ICE: dependency graph not found, old analysis is gone!", 0);
return 0;
}
// if(zyg_ctx.tests)
// if(!expr_gen_test())
// return 0;
if(!serialize_deps(tree))
return 0;
if(zyg_ctx.usage_debug)
c3dump(*tree);
good = anal_execute(tree);
return anal_finish(tree, good, out);
}