Exemplo n.º 1
0
 internal Expression ParseReferredParameterOrType(TokenStore ts, ParseInfo parseInfo, bool allowType, bool allowVariable, bool allowArrayType)
 {
     Type t = null;
     Expression exp = null;
     StringBuilder var_fullname = new StringBuilder();
     AToken tok = ts.Current;
     while (exp == null && tok != null && tok.tok_type == TOKEN_TYPE.IDENTIFIER)
     {
         var_fullname.Append(tok.value);
         // try local variable
         if (allowVariable && (exp = parseInfo.GetReferredVariable(var_fullname.ToString())) != null) { ts.Next(); break; }
         // try referred parameter
         else if (allowVariable && (t = this.QueryParameterType(var_fullname.ToString())) != null)
         {
             exp = parseInfo.GetReferredParameter(t, tok.value);
             ts.Next();
             break;
         }
         // try static Generic Type
         else if (allowType && ts.PeekTokenValue(1) == "<")
         {
             // v1.1: Generic Type reference
             tok = ts.Next();    // to "<"
             List<Type> param_types = new List<Type>();
             List<Expression> param_list = ParseParameters(ts, parseInfo, param_types, true);
             Assert((t = this.QueryStaticType(var_fullname.Append("`").Append(param_list.Count).ToString()).MakeGenericType(param_types.ToArray())) != null, tok);
             t = ParseStaticTypeExtension(ts, t, allowArrayType);
             exp = Expression.Constant(t);   // Type: (T)x or T.xxx
             break;
         }
         // try static Type
         else if (allowType && (t = this.QueryStaticType(var_fullname.ToString())) != null)
         {
             // Static Type reference
             ts.Next();
             t = ParseStaticTypeExtension(ts, t, allowArrayType);
             exp = Expression.Constant(t);
             break;
         }
         // neither parameter or static type
         if ((tok = ts.Next()) == null || tok.value != ".") break;   // unexpected
         var_fullname.Append(".");
         tok = ts.Next();    // skip "."
     }
     return exp;
 }