001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.transformer.bytecode.statement; 020 021import java.util.Map; 022 023import lucee.runtime.type.FunctionArgumentImpl; 024import lucee.transformer.bytecode.Literal; 025import lucee.transformer.bytecode.cast.CastBoolean; 026import lucee.transformer.bytecode.cast.CastString; 027import lucee.transformer.bytecode.expression.ExprBoolean; 028import lucee.transformer.bytecode.expression.ExprString; 029import lucee.transformer.bytecode.expression.Expression; 030import lucee.transformer.bytecode.literal.LitInteger; 031import lucee.transformer.bytecode.literal.LitString; 032 033public final class Argument { 034 035 036 private static final Expression DEFAULT_TYPE_NULL = LitInteger.toExpr(FunctionArgumentImpl.DEFAULT_TYPE_NULL); 037 private static final Expression DEFAULT_TYPE_LITERAL = LitInteger.toExpr(FunctionArgumentImpl.DEFAULT_TYPE_LITERAL); 038 private static final Expression DEFAULT_TYPE_RUNTIME_EXPRESSION = LitInteger.toExpr(FunctionArgumentImpl.DEFAULT_TYPE_RUNTIME_EXPRESSION); 039 private static final LitString RUNTIME_EXPRESSION = (LitString) LitString.toExprString("[runtime expression]"); 040 041 042 private ExprString name; 043 private ExprString type; 044 private ExprBoolean required; 045 private Expression defaultValue; 046 private ExprString displayName; 047 private ExprString hint; 048 private Map meta; 049 private ExprBoolean passByReference; 050 051 052 /** 053 * Constructor of the class 054 * @param name 055 * @param type 056 * @param required 057 * @param defaultValue 058 * @param displayName 059 * @param hint 060 * @param hint2 061 * @param meta 062 */ 063 public Argument(Expression name, Expression type, Expression required, Expression defaultValue, ExprBoolean passByReference,Expression displayName, Expression hint, Map meta) { 064 this.name=CastString.toExprString(name); 065 this.type=CastString.toExprString(type); 066 this.required=CastBoolean.toExprBoolean(required); 067 this.defaultValue=defaultValue; 068 this.displayName=litString(CastString.toExprString(displayName),RUNTIME_EXPRESSION); 069 this.hint=litString(hint, RUNTIME_EXPRESSION); 070 this.passByReference=passByReference; 071 this.meta=meta; 072 } 073 074 private LitString litString(Expression expr, LitString defaultValue) { 075 ExprString str = CastString.toExprString(expr); 076 if(str instanceof LitString) return (LitString) str; 077 return defaultValue; 078 } 079 080 /** 081 * @return the defaultValue 082 */ 083 public Expression getDefaultValue() { 084 return defaultValue; 085 } 086 087 public Expression getDefaultValueType(){ 088 if(defaultValue==null) return DEFAULT_TYPE_NULL; 089 if(defaultValue instanceof Literal) return DEFAULT_TYPE_LITERAL; 090 return DEFAULT_TYPE_RUNTIME_EXPRESSION; 091 } 092 093 /** 094 * @return the displayName 095 */ 096 public ExprString getDisplayName() { 097 return displayName; 098 } 099 100 /** 101 * @return the hint 102 */ 103 public ExprString getHint() { 104 return hint; 105 } 106 107 /** 108 * @return the name 109 */ 110 public ExprString getName() { 111 return name; 112 } 113 114 /** 115 * @return the passBy 116 */ 117 public ExprBoolean isPassByReference() { 118 return passByReference; 119 } 120 121 /** 122 * @return the required 123 */ 124 public ExprBoolean getRequired() { 125 return required; 126 } 127 128 /** 129 * @return the type 130 */ 131 public ExprString getType() { 132 return type; 133 } 134 public Map getMetaData() { 135 return meta; 136 } 137 138}