<commit_before>/*
 * jETeL/CloverETL - Java based ETL application framework.
 * Copyright (c) Javlin, a.s. (<EMAIL>)
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.jetel.ctl;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import org.jetel.ctl.ASTnode.CLVFAssignment;
import org.jetel.ctl.ASTnode.CLVFBlock;
import org.jetel.ctl.ASTnode.CLVFCaseStatement;
import org.jetel.ctl.ASTnode.CLVFFieldAccessExpression;
import org.jetel.ctl.ASTnode.CLVFForeachStatement;
import org.jetel.ctl.ASTnode.CLVFFunctionDeclaration;
import org.jetel.ctl.ASTnode.CLVFImportSource;
import org.jetel.ctl.ASTnode.CLVFLiteral;
import org.jetel.ctl.ASTnode.CLVFLookupNode;
import org.jetel.ctl.ASTnode.CLVFParameters;
import org.jetel.ctl.ASTnode.CLVFSequenceNode;
import org.jetel.ctl.ASTnode.CLVFStart;
import org.jetel.ctl.ASTnode.CLVFStartExpression;
import org.jetel.ctl.ASTnode.CLVFSwitchStatement;
import org.jetel.ctl.ASTnode.CLVFType;
import org.jetel.ctl.ASTnode.CLVFUnaryExpression;
import org.jetel.ctl.ASTnode.CLVFVariableDeclaration;
import org.jetel.ctl.ASTnode.Node;
import org.jetel.ctl.ASTnode.SimpleNode;
import org.jetel.ctl.data.TLType;
import org.jetel.ctl.data.TLTypePrimitive;
import org.jetel.ctl.data.UnknownTypeException;
import org.jetel.data.Defaults;
import org.jetel.data.lookup.LookupTable;
import org.jetel.data.sequence.Sequence;
import org.jetel.exception.ComponentNotReadyException;
import org.jetel.exception.NotInitializedException;
import org.jetel.graph.TransformationGraph;
import org.jetel.metadata.DataFieldMetadata;
import org.jetel.metadata.DataRecordMetadata;

/**
 * Implementation of semantic checking for CTL compiler.
 * Resolves external references, functions and records.
 * Performs code structure validation, mostly for correct 
 * derivation of expression statements.
 * 
 * @author <NAME> <<EMAIL>>
 *
 */
public class ASTBuilder extends NavigatingVisitor {

	/** Void metadata used by Rollup transforms when no group accumulator is used. */
	private static final DataRecordMetadata VOID_METADATA =
			new DataRecordMetadata(Defaults.CTL.VOID_METADATA_NAME);

	/** Metadata for component's input ports */
	private final DataRecordMetadata[] inputMetadata; // may be null
	/** Metadata for component's output ports */
	private final DataRecordMetadata[] outputMetadata; // may be null
	/** Name -> position mapping for input ports */
	private final TreeMap<String, Integer> inputRecordsMap;
	/** Name -> position mapping for output ports */
	private final TreeMap<String, Integer> outputRecordsMap;
	/** Name/ID -> metadata mapping for record-type variables */
	private final TreeMap<String, DataRecordMetadata> graphMetadata;
	/** Name/ID -> lookup mapping for lookup nodes */
	private final TreeMap<String, LookupTable> lookupMap;
	/** Name/ID -> lookup mapping for sequences */
	private final TreeMap<String, Sequence> sequenceMap;
	/** Function declarations */
	private final Map<String, List<CLVFFunctionDeclaration>> declaredFunctions;
	/** Problem collector */
	private ProblemReporter problemReporter;

	
	
	public ASTBuilder(TransformationGraph graph, DataRecordMetadata[] inputMetadata,
			DataRecordMetadata[] outputMetadata, Map<String, List<CLVFFunctionDeclaration>> declaredFunctions, ProblemReporter problemReporter) {
		super();
		this.inputMetadata = inputMetadata;
		this.outputMetadata = outputMetadata;
		this.inputRecordsMap = new TreeMap<String, Integer>();
		this.outputRecordsMap = new TreeMap<String, Integer>();
		this.graphMetadata = new TreeMap<String, DataRecordMetadata>();
		this.lookupMap = new TreeMap<String, LookupTable>();
		this.sequenceMap = new TreeMap<String, Sequence>();
		this.declaredFunctions = declaredFunctions;
		this.problemReporter = problemReporter;
<commit_msg>MINOR: Code clean-up.<commit_after>/*
 * jETeL/CloverETL - Java based ETL application framework.
 * Copyright (c) Javlin, a.s. (<EMAIL>)
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.jetel.ctl;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import org.jetel.ctl.ASTnode.CLVFAssignment;
import org.jetel.ctl.ASTnode.CLVFBlock;
import org.jetel.ctl.ASTnode.CLVFCaseStatement;
import org.jetel.ctl.ASTnode.CLVFFieldAccessExpression;
import org.jetel.ctl.ASTnode.CLVFForeachStatement;
import org.jetel.ctl.ASTnode.CLVFFunctionDeclaration;
import org.jetel.ctl.ASTnode.CLVFImportSource;
import org.jetel.ctl.ASTnode.CLVFLiteral;
import org.jetel.ctl.ASTnode.CLVFLookupNode;
import org.jetel.ctl.ASTnode.CLVFParameters;
import org.jetel.ctl.ASTnode.CLVFSequenceNode;
import org.jetel.ctl.ASTnode.CLVFStart;
import org.jetel.ctl.ASTnode.CLVFStartExpression;
import org.jetel.ctl.ASTnode.CLVFSwitchStatement;
import org.jetel.ctl.ASTnode.CLVFType;
import org.jetel.ctl.ASTnode.CLVFUnaryExpression;
import org.jetel.ctl.ASTnode.CLVFVariableDeclaration;
import org.jetel.ctl.ASTnode.Node;
import org.jetel.ctl.ASTnode.SimpleNode;
import org.jetel.ctl.data.TLType;
import org.jetel.ctl.data.TLTypePrimitive;
import org.jetel.ctl.data.UnknownTypeException;
import org.jetel.data.Defaults;
import org.jetel.data.lookup.LookupTable;
import org.jetel.data.sequence.Sequence;
import org.jetel.exception.ComponentNotReadyException;
import org.jetel.exception.NotInitializedException;
import org.jetel.graph.TransformationGraph;
import org.jetel.metadata.DataFieldMetadata;
import org.jetel.metadata.DataRecordMetadata;

/**
 * Implementation of semantic checking for CTL compiler.
 * Resolves external references, functions and records.
 * Performs code structure validation, mostly for correct 
 * derivation of expression statements.
 * 
 * @author <NAME> <<EMAIL>>
 *
 */
public class ASTBuilder extends NavigatingVisitor {

	/** Void metadata used by Rollup transforms when no group accumulator is used. */
	private static final DataRecordMetadata VOID_METADATA =
			new DataRecordMetadata(Defaults.CTL.VOID_METADATA_NAME);

	/** Metadata for component's input ports */
	private final DataRecordMetadata[] inputMetadata; // may be null
	/** Metadata for component's output ports */
	private final DataRecordMetadata[] outputMetadata; // may be null
	/** Name -> position mapping for input ports */
	private final Map<String, Integer> inputRecordsMap;
	/** Name -> position mapping for output ports */
	private final Map<String, Integer> outputRecordsMap;
	/** Name/ID -> metadata mapping for record-type variables */
	private final Map<String, DataRecordMetadata> graphMetadata;
	/** Name/ID -> lookup mapping for lookup nodes */
	private final Map<String, LookupTable> lookupMap;
	/** Name/ID -> lookup mapping for sequences */
	private final Map<String, Sequence> sequenceMap;
	/** Function declarations */
	private final Map<String, List<CLVFFunctionDeclaration>> declaredFunctions;
	/** Problem collector */
	private ProblemReporter problemReporter;

	
	
	public ASTBuilder(TransformationGraph graph, DataRecordMetadata[] inputMetadata,
			DataRecordMetadata[] outputMetadata, Map<String, List<CLVFFunctionDeclaration>> declaredFunctions, ProblemReporter problemReporter) {
		super();
		this.inputMetadata = inputMetadata;
		this.outputMetadata = outputMetadata;
		this.inputRecordsMap = new TreeMap<String, Integer>();
		this.outputRecordsMap = new TreeMap<String, Integer>();
		this.graphMetadata = new TreeMap<String, DataRecordMetadata>();
		this.lookupMap = new TreeMap<String, LookupTable>();
		this.sequenceMap = new TreeMap<String, Sequence>();
		this.declaredFunctions = declaredFunctions;
		this.problemReporter = problemReporter;

{'fraction_non_alphanumeric': 0.0945830667519727, 'fraction_numerical': 0.0034122414160801876, 'mean_word_length': 5.2401862940785096, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '129273', 'n_tokens_mistral': 2780, 'n_tokens_neox': 2675, 'n_words': 790}