001 package railo.transformer.bytecode.statement; 002 003 import java.util.Map; 004 005 import railo.runtime.type.FunctionArgumentImpl; 006 import railo.transformer.bytecode.Literal; 007 import railo.transformer.bytecode.cast.CastBoolean; 008 import railo.transformer.bytecode.cast.CastString; 009 import railo.transformer.bytecode.expression.ExprBoolean; 010 import railo.transformer.bytecode.expression.ExprString; 011 import railo.transformer.bytecode.expression.Expression; 012 import railo.transformer.bytecode.literal.LitInteger; 013 import railo.transformer.bytecode.literal.LitString; 014 015 public final class Argument { 016 017 018 private static final Expression DEFAULT_TYPE_NULL = LitInteger.toExpr(FunctionArgumentImpl.DEFAULT_TYPE_NULL, -1); 019 private static final Expression DEFAULT_TYPE_LITERAL = LitInteger.toExpr(FunctionArgumentImpl.DEFAULT_TYPE_LITERAL, -1); 020 private static final Expression DEFAULT_TYPE_RUNTIME_EXPRESSION = LitInteger.toExpr(FunctionArgumentImpl.DEFAULT_TYPE_RUNTIME_EXPRESSION, -1); 021 private static final LitString RUNTIME_EXPRESSION = (LitString) LitString.toExprString("[runtime expression]"); 022 023 024 private ExprString name; 025 private ExprString type; 026 private ExprBoolean required; 027 private Expression defaultValue; 028 private ExprString displayName; 029 private ExprString hint; 030 private Map meta; 031 private ExprBoolean passByReference; 032 033 034 /** 035 * Constructor of the class 036 * @param name 037 * @param type 038 * @param required 039 * @param defaultValue 040 * @param displayName 041 * @param hint 042 * @param hint2 043 * @param meta 044 */ 045 public Argument(Expression name, Expression type, Expression required, Expression defaultValue, ExprBoolean passByReference,Expression displayName, Expression hint, Map meta) { 046 this.name=CastString.toExprString(name); 047 this.type=CastString.toExprString(type); 048 this.required=CastBoolean.toExprBoolean(required); 049 this.defaultValue=defaultValue; 050 this.displayName=litString(CastString.toExprString(displayName),RUNTIME_EXPRESSION); 051 this.hint=litString(hint, RUNTIME_EXPRESSION); 052 this.passByReference=passByReference; 053 this.meta=meta; 054 } 055 056 private LitString litString(Expression expr, LitString defaultValue) { 057 ExprString str = CastString.toExprString(expr); 058 if(str instanceof LitString) return (LitString) str; 059 return defaultValue; 060 } 061 062 /** 063 * @return the defaultValue 064 */ 065 public Expression getDefaultValue() { 066 return defaultValue; 067 } 068 069 public Expression getDefaultValueType(){ 070 if(defaultValue==null) return DEFAULT_TYPE_NULL; 071 if(defaultValue instanceof Literal) return DEFAULT_TYPE_LITERAL; 072 return DEFAULT_TYPE_RUNTIME_EXPRESSION; 073 } 074 075 /** 076 * @return the displayName 077 */ 078 public ExprString getDisplayName() { 079 return displayName; 080 } 081 082 /** 083 * @return the hint 084 */ 085 public ExprString getHint() { 086 return hint; 087 } 088 089 /** 090 * @return the name 091 */ 092 public ExprString getName() { 093 return name; 094 } 095 096 /** 097 * @return the passBy 098 */ 099 public ExprBoolean isPassByReference() { 100 return passByReference; 101 } 102 103 /** 104 * @return the required 105 */ 106 public ExprBoolean getRequired() { 107 return required; 108 } 109 110 /** 111 * @return the type 112 */ 113 public ExprString getType() { 114 return type; 115 } 116 public Map getMetaData() { 117 return meta; 118 } 119 120 }