All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cfml.parsing.cfscript.script.CFCompDeclStatement Maven / Gradle / Ivy

There is a newer version: 2.11.0
Show newest version
package cfml.parsing.cfscript.script;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.antlr.v4.runtime.Token;

import cfml.parsing.cfscript.CFContext;
import cfml.parsing.cfscript.CFExpression;
import cfml.parsing.cfscript.CFLiteral;
import cfml.parsing.reporting.ParseException;

public class CFCompDeclStatement extends CFParsedStatement {
	
	private static final long serialVersionUID = 1L;
	
	private Map attributes;
	private CFScriptStatement body;
	
	private byte access;
	
	public byte getAccess() {
		return access;
	}
	
	public String getReturnType() {
		return returnType;
	}
	
	private String returnType;
	
	// TODO: prevent function declared inside function. May want to do this elsewhere
	public CFCompDeclStatement(Token _t, Map _attr, CFScriptStatement _body) {
		super(_t);
		body = _body;
		// handle the function attributes
		attributes = new HashMap();
		if (_attr != null) {
			Iterator keys = _attr.keySet().iterator();
			while (keys.hasNext()) {
				String nextKey = keys.next().Decompile(0);
				CFExpression nextExpr = _attr.get(nextKey);
				if (!(nextExpr instanceof CFLiteral)) {
					throw new ParseException(_t,
							"The attribute " + nextKey.toUpperCase() + " must have a constant value");
				}
				
				attributes.put(nextKey, ((CFLiteral) nextExpr).getStringImage());
			}
		}
		
	}
	
	public CFScriptStatement getBody() {
		return body;
	}
	
	@Override
	public void checkIndirectAssignments(String[] scriptSource) {
		body.checkIndirectAssignments(scriptSource);
	}
	
	public CFStatementResult Exec(CFContext context) {
		return null;
	}
	
	@Override
	public String Decompile(int indent) {
		StringBuilder sb = new StringBuilder();
		sb.append(Indent(indent));
		sb.append(" component ");
		sb.append(body.Decompile(indent + 2));
		sb.append("\n");
		sb.append(Indent(indent));
		sb.append("}");
		
		return sb.toString();
	}
	
	public Map getAttributes() {
		return attributes;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy