open Ast
(*************************************************************************************)
(*****************   This is for debugging and helpers********************************)
(*************************************************************************************)

let rec processLattice lattice = (*input a latticeFields, which is our AST*) 
  match lattice.lattice with 
  | Seqlat(seqlat) -> processSeqlat seqlat
  | Altlat(altlat) -> processAltlat altlat
  | Predicate(pred) -> processPredicate pred
  | Expr(expr) -> processExpr expr

and processSeqlat _seqlat = (*do the seq lat *)
	env.namesOfCurrLat <- _seqlat.symbols; (* side effect *)
	processListOfLattices _seqlat.elements 

and processListOfLattices = function 
	| [] -> []
	| hd::tl -> (processLattice hd) :: (processListOfLattices tl)

and processAltlat _altlat = (*do the alt lat *)
	processListOfLattices alternatives
	
and processPredicate _pred =
	let condValueExpr =  processExpr condition in
		match condValueExpr.exprEval with
			| ConstValue(value) -> (match value with 
				| True -> true
				| False -> false)
			| _ -> false
		
and processExpr _expr = match _expr.exprCode with
	| ConstExpr(const) -> processConst const
	| OpExpr(op) -> processOperation op
	| NameListExpr(nameList) -> try processNameList env.namesOfCurrLat nameList with Not_found -> addToErrorTable(SemUndefinedIdentifier, None)
	| LatticeExpr(lattice) -> processLattice lattice

and processConst = x

and processOperation op = 
	let op1Val = processExpr op.operand1 in
	let op2Val = processExpr op.operand2 in
		match op.operator with
			| Plus -> print_newline() 
			| Minus | Times | Divide | Percent | Or | And | Equal | NotEqual | Less | LessOrEqual | Greater | GreaterOrEqual | Tilde
			| UniMinus | Eval | DontOpt | Let

and processNameList _symbolTable _nameList =
		 match _nameList with 
			| [] -> []
			| hd::tl -> (
				let lat = Ast.symbolTableSearchFor _symbolTable hd in (*latticeFields*)
				match lat.lattice with (*latticeType*)
					| Seqlat(seqlat) ->
						let inLat = symbolTableSearchForLable seqlat.symbols hd in
						processNameList seqlat.symbols hd
					| _ -> (addToErrorTable(SemUndefinedIdentifier, None); raise Not_found)
					)
				
				
		
		
		