本文整理汇总了C#中ICLS_Environment.GetTypeByKeyword方法的典型用法代码示例。如果您正苦于以下问题:C# ICLS_Environment.GetTypeByKeyword方法的具体用法?C# ICLS_Environment.GetTypeByKeyword怎么用?C# ICLS_Environment.GetTypeByKeyword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICLS_Environment
的用法示例。
在下文中一共展示了ICLS_Environment.GetTypeByKeyword方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compiler_Expression_DefineArray
public ICLS_Expression Compiler_Expression_DefineArray(IList<Token> tlist, ICLS_Environment content, int pos, int posend)
{
CLS_Expression_Define define = new CLS_Expression_Define(pos, posend, tlist[pos].line, tlist[posend].line);
{
ICLS_Type type = content.GetTypeByKeyword(tlist[pos].text+"[]");
define.value_type = type.type;
}
define.value_name = tlist[pos + 3].text;
return define;
}
示例2: Compiler_Expression_Define
public ICLS_Expression Compiler_Expression_Define(IList<Token> tlist, ICLS_Environment content, int pos, int posend)
{
CLS_Expression_Define define = new CLS_Expression_Define(pos, posend, tlist[pos].line, tlist[posend].line);
if (tlist[pos].text == "bool")
{
define.value_type = typeof(bool);
}
else
{
ICLS_Type type = content.GetTypeByKeyword(tlist[pos].text);
define.value_type = type.type;
}
define.value_name = tlist[pos+1].text;
return define;
}
示例3: Compiler_Expression_FunctionNew
public ICLS_Expression Compiler_Expression_FunctionNew(IList<Token> tlist, ICLS_Environment content, int pos, int posend)
{
int begin = pos + 3;
int dep;
int end = FindCodeAnyInFunc(tlist, ref begin, out dep);
if (tlist[pos + 2].type == TokenType.PUNCTUATION && tlist[pos + 2].text == "(")
{
//一般函数
CLS_Expression_FunctionNew func = new CLS_Expression_FunctionNew(pos, posend, tlist[pos].line, tlist[posend].line);
func.type = content.GetTypeByKeyword(tlist[pos + 1].text);
do
{
ICLS_Expression param;
bool succ = Compiler_Expression(tlist, content, begin, end, out param);
if (succ && param != null)
{
func.listParam.Add(param);
}
begin = end + 2;
end = FindCodeAnyInFunc(tlist, ref begin, out dep);
}
while (end < posend && begin <= end);
return func;
}
else if (tlist[pos + 2].type == TokenType.PUNCTUATION && tlist[pos + 2].text == "[")//数组实例化表达式
{
CLS_Expression_FunctionNewArray func = new CLS_Expression_FunctionNewArray(pos, posend, tlist[pos].line, tlist[posend].line);
func.type = content.GetTypeByKeyword(tlist[pos + 1].text + "[]");
int valuebegin = 0;
ICLS_Expression count = null;
if (tlist[pos + 3].text == "]")
{
valuebegin = pos + 4;
}
else
{
int nbegin = pos + 3;
int dep2;
int end2 = FindCodeAny(tlist, ref nbegin, out dep2);
bool succ = Compiler_Expression(tlist, content, nbegin, end2, out count);
if (!succ)
{
throw new Exception("数组数量无法识别:" + tlist[pos].ToString());
}
valuebegin = end2 + 2;
}
func.listParam.Add(count);
if (tlist[valuebegin].text == "{")//InitValue
{
int nbegin = valuebegin + 1;
do
{
int dep2;
int nend = FindCodeAny(tlist, ref nbegin, out dep2);
ICLS_Expression valueI;
bool succ = Compiler_Expression(tlist, content, nbegin, nend, out valueI);
if (!succ)
{
//throw new Exception("数组初始值无法识别");
}
else
{
func.listParam.Add(valueI);
}
if (tlist[nend + 1].text != ",")
break;
nbegin = nend + 2;
}
while (nbegin >= pos && nbegin < posend);
}
return func;
}
return null;
}
示例4: Compiler_Expression_Math
public ICLS_Expression Compiler_Expression_Math(IList<Token> tlist, ICLS_Environment content, int pos, int posend)
{
IList<int> sps = SplitExpressionWithOp(tlist, pos, posend);
int oppos = GetLowestMathOp(tlist, sps);
if (oppos < 0)
{
////也有可能是类型转换
//if (posend >= pos + 3 && tlist[pos].text == "(" && tlist[pos].type == TokenType.PUNCTUATION && tlist[pos + 2].text == ")" && tlist[pos + 2].type == TokenType.PUNCTUATION
// && tlist[pos + 1].type == TokenType.TYPE
// )
//{
// ICLS_Expression v;
// bool succ = Compiler_Expression(tlist, content, pos + 3, posend, out v);
// CLS_Expression_TypeConvert convert = new CLS_Expression_TypeConvert();
// convert.listParam.Add(v);
// convert.targettype = content.environment.GetTypeByKeyword(tlist[pos + 1].text).type;
// return convert;
//}
//else if (tlist[pos + 1].type == TokenType.PUNCTUATION && tlist[pos + 1].text == "[")//函数表达式
//{
// return Compiler_Expression_IndexFind(tlist, content, pos, posend);
//}
if (tlist[pos + 1].type == TokenType.PUNCTUATION && tlist[pos + 1].text == "(")//函数表达式
{
return Compiler_Expression_Function(tlist, content, pos, posend);
}
else
{
//if (!bTest && tlist[expbegin + 1].type == TokenType.PUNCTUATION && tlist[expbegin + 1].text == "(")//函数表达式
//{
// ICLS_Expression subvalue = Compiler_Expression_Function(tlist,content, expbegin, expend);
// if (null == subvalue) return false;
// else
// values.Add(subvalue);
// bTest = true;
//}
}
return null;
}
Token tkCur = tlist[oppos];
if (tkCur.text == "=>")
{//lambda
return Compiler_Expression_Lambda(tlist, content, pos, posend);
}
else if (tkCur.text == "." && pos == oppos - 1 && tlist[pos].type == TokenType.TYPE)
{
int right = oppos + 1;
int rightend = posend;
ICLS_Expression valueright;
bool succ2 = Compiler_Expression(tlist, content, right, rightend, out valueright);
if (succ2)
{
CLS_Expression_GetValue vg = valueright as CLS_Expression_GetValue;
CLS_Expression_Function vf = valueright as CLS_Expression_Function;
if (vg != null)
{
CLS_Expression_StaticFind value = new CLS_Expression_StaticFind(pos, rightend, tlist[pos].line, tlist[rightend].line);
value.staticmembername = vg.value_name;
value.type = content.GetTypeByKeyword(tlist[pos].text);
return value;
}
else if (vf != null)
{
CLS_Expression_StaticFunction value = new CLS_Expression_StaticFunction(pos, rightend, tlist[pos].line, tlist[rightend].line);
value.functionName = vf.funcname;
value.type = content.GetTypeByKeyword(tlist[pos].text);
//value.listParam.Add(valueleft);
value.listParam.AddRange(vf.listParam.ToArray());
return value;
}
else if (valueright is CLS_Expression_SelfOp)
{
CLS_Expression_SelfOp vr = valueright as CLS_Expression_SelfOp;
CLS_Expression_StaticMath value = new CLS_Expression_StaticMath(pos, rightend, tlist[pos].line, tlist[rightend].line);
value.type = content.GetTypeByKeyword(tlist[pos].text);
value.staticmembername = vr.value_name;
value.mathop = vr.mathop;
return value;
}
else
{
throw new Exception("不可识别的表达式:" + tkCur.ToString() + tkCur.SourcePos());
}
}
else
{
throw new Exception("不可识别的表达式:" + tkCur.ToString() + tkCur.SourcePos());
}
}
//.........这里部分代码省略.........
示例5: Compiler_Class
ICLS_Type Compiler_Class(ICLS_Environment env, string classname, IList<string> baseTypeNames, string filename, IList<Token> tokens, int ibegin, int iend, bool EmbDebugToken, bool onlyGotType = false, IList<string> usinglist = null)
{
CLS_Type_Class sClass = env.GetTypeByKeywordQuiet(classname) as CLS_Type_Class;
if (sClass == null)
sClass = new CLS_Type_Class(classname, filename);
sClass.compiled = false;
(sClass.function as SType).functions.Clear();
(sClass.function as SType).members.Clear();
if (onlyGotType)
return sClass;
// 调试Token
if (EmbDebugToken)
(sClass.function as SType).EmbDebugToken(tokens);
bool bStatic = false;
int sortIndex = 0;
for (int i = ibegin; i <= iend; i++)
{
if (tokens[i].type == TokenType.KEYWORD && tokens[i].text == "static")
{
bStatic = true;
continue;
}
if (tokens[i].type == TokenType.ProtoIndex)
{
sortIndex = int.Parse(tokens[i].text);
continue;
}
if (tokens[i].type == TokenType.TYPE || (tokens[i].type == TokenType.IDENTIFIER && tokens[i].text == classname))//发现类型
{
ICLS_Type idtype = env.GetTypeByKeyword("null");
bool bctor = false;
if (tokens[i].type == TokenType.TYPE)
{
if (tokens[i].text == classname && tokens[i + 1].text == "(")
{
//构造函数
bctor = true;
i--;
}
else if (tokens[i + 1].text == "[" && tokens[i + 2].text == "]")
{
idtype = env.GetTypeByKeyword(tokens[i].text + "[]");
i += 2;
}
else if (tokens[i].text == "void")
{
}
else
{
idtype = env.GetTypeByKeyword(tokens[i].text);
}
}
if (tokens[i + 1].type == CSLE.TokenType.IDENTIFIER || bctor) //类型后面是名称
{
string idname = tokens[i + 1].text;
if (tokens[i + 2].type == CSLE.TokenType.PUNCTUATION && tokens[i + 2].text == "(")//参数开始,这是函数
{
logger.Log("发现函数:" + idname);
SType.Function func = new SType.Function();
func.bStatic = bStatic;
int funcparambegin = i + 2;
int funcparamend = FindBlock(env, tokens, funcparambegin);
if (funcparamend - funcparambegin > 1)
{
int start = funcparambegin + 1;
for (int j = funcparambegin + 1; j <= funcparamend; j++)
{
if (tokens[j].text == "," || tokens[j].text == ")")
{
string ptype = "";
for (int k = start; k <= j - 2; k++)
ptype += tokens[k].text;
var pid = tokens[j - 1].text;
var type = env.GetTypeByKeyword(ptype);
if (type == null)
{
throw new Exception(filename + ":不可识别的函数头参数:" + tokens[funcparambegin].ToString());
}
func._paramnames.Add(pid);
func._paramtypes.Add(type);
start = j + 1;
}
}
}
int funcbegin = funcparamend + 1;
if (tokens[funcbegin].text == "{")
//.........这里部分代码省略.........
示例6: Compiler_Class
ICLS_Type Compiler_Class(ICLS_Environment env, string classname, bool bInterface, IList<string> basetype, string filename, IList<Token> tokens, int ibegin, int iend, bool EmbDebugToken, bool onlyGotType, IList<string> usinglist)
{
CLS_Type_Class stype = env.GetTypeByKeywordQuiet(classname) as CLS_Type_Class;
if (stype == null)
stype = new CLS_Type_Class(classname, bInterface, filename);
if (basetype != null && basetype.Count != 0 && onlyGotType == false)
{
List<ICLS_Type> basetypess = new List<ICLS_Type>();
foreach (string t in basetype)
{
ICLS_Type type = env.GetTypeByKeyword(t);
basetypess.Add(type);
}
stype.SetBaseType(basetypess);
}
if (onlyGotType) return stype;
//if (env.useNamespace && usinglist != null)
//{//使用命名空间,替换token
// List<Token> newTokens = new List<Token>();
// for (int i = ibegin; i <= iend; i++)
// {
// if (tokens[i].type == TokenType.IDENTIFIER)
// {
// string ntype = null;
// string shortname = tokens[i].text;
// int startpos = i;
// while (ntype == null)
// {
// foreach (var u in usinglist)
// {
// string ttype = u + "." + shortname;
// if (env.GetTypeByKeywordQuiet(ttype) != null)
// {
// ntype = ttype;
// break;
// }
// }
// if (ntype != null) break;
// if ((startpos + 2) <= iend && tokens[startpos + 1].text == "." && tokens[startpos + 2].type == TokenType.IDENTIFIER)
// {
// shortname += "." + tokens[startpos + 2].text;
// startpos += 2;
// if (env.GetTypeByKeywordQuiet(shortname) != null)
// {
// ntype = shortname;
// break;
// }
// continue;
// }
// else
// {
// break;
// }
// }
// if (ntype != null)
// {
// var t = tokens[i];
// t.text = ntype;
// t.type = TokenType.TYPE;
// newTokens.Add(t);
// i = startpos;
// continue;
// }
// }
// newTokens.Add(tokens[i]);
// }
// tokens = newTokens;
// ibegin = 0;
// iend = tokens.Count - 1;
//}
stype.compiled = false;
(stype.function as SType).functions.Clear();
(stype.function as SType).members.Clear();
//搜寻成员定义和函数
//定义语法 //Type id[= expr];
//函数语法 //Type id([Type id,]){block};
//属性语法 //Type id{get{},set{}};
bool bPublic = false;
bool bStatic = false;
if (EmbDebugToken)//SType 嵌入Token
{
stype.EmbDebugToken(tokens);
}
for (int i = ibegin; i <= iend; i++)
{
if (tokens[i].type == TokenType.KEYWORD && tokens[i].text == "public")
{
//.........这里部分代码省略.........
示例7: Compiler_Expression_Math
public ICLS_Expression Compiler_Expression_Math(IList<Token> tlist, ICLS_Environment environment, int pos, int posend)
{
IList<int> sps = SplitExpressionWithOp(tlist, pos, posend);
if (sps == null)
LogError(tlist, "SplitExpressionWithOp return null", pos, posend);
int oppos = GetLowestMathOp(tlist, sps);
if (oppos < 0)
{
if (tlist[pos + 1].type == TokenType.PUNCTUATION && tlist[pos + 1].text == "(")//函数表达式
{
CLS_Expression_Function func = (CLS_Expression_Function)Compiler_Expression_Function(tlist, environment, pos, posend);
if (func != null)
{
if (environment.GetFunction(func.funcname) != null)
{
CLS_Expression_GlobalFunction globalFunc = new CLS_Expression_GlobalFunction(func.listParam, func.tokenBegin, func.tokenEnd, func.lineBegin, func.lineEnd);
globalFunc.funcname = func.funcname;
return globalFunc;
}
}
return func;
}
return null;
}
Token tkCur = tlist[oppos];
if (tkCur.text == "=>")
{
return Compiler_Expression_Lambda(tlist, environment, pos, posend);
}
else if (tkCur.text == "." && pos == oppos - 1 && tlist[pos].type == TokenType.TYPE)
{
int right = oppos + 1;
int rightend = posend;
ICLS_Expression valueright;
bool succ2 = Compiler_Expression(tlist, environment, right, rightend, out valueright);
if (succ2)
{
CLS_Expression_GetValue vg = valueright as CLS_Expression_GetValue;
CLS_Expression_Function vf = valueright as CLS_Expression_Function;
if (vg != null)
{
// 优化枚举常量表达式
try
{
System.Type sysType = environment.GetTypeByKeyword(tlist[pos].text).type;
if (sysType != null && sysType.IsEnum)
{
CLS_Expression_Enum enumVal = new CLS_Expression_Enum(sysType);
enumVal.tokenBegin = pos;
enumVal.tokenEnd = rightend;
enumVal.lineBegin = tlist[pos].line;
enumVal.lineEnd = tlist[rightend].line;
enumVal.value = Enum.Parse(sysType, vg.value_name);
return enumVal;
}
}
catch (Exception ex)
{
logger.Log_Warn("Enum expression: " + ex.Message);
}
CLS_Expression_StaticFind value = new CLS_Expression_StaticFind(pos, rightend, tlist[pos].line, tlist[rightend].line);
value.staticmembername = vg.value_name;
value.type = environment.GetTypeByKeyword(tlist[pos].text);
return value;
}
else if (vf != null)
{
CLS_Expression_StaticFunction value = new CLS_Expression_StaticFunction(pos, rightend, tlist[pos].line, tlist[rightend].line);
value.functionName = vf.funcname;
value.type = environment.GetTypeByKeyword(tlist[pos].text);
value.listParam.AddRange(vf.listParam.ToArray());
return value;
}
else if (valueright is CLS_Expression_SelfOp)
{
CLS_Expression_SelfOp vr = valueright as CLS_Expression_SelfOp;
CLS_Expression_StaticMath value = new CLS_Expression_StaticMath(pos, rightend, tlist[pos].line, tlist[rightend].line);
value.type = environment.GetTypeByKeyword(tlist[pos].text);
value.staticmembername = vr.value_name;
value.mathop = vr.mathop;
return value;
}
else
{
throw new Exception("不可识别的表达式:" + tkCur.ToString());
}
}
else
{
throw new Exception("不可识别的表达式:" + tkCur.ToString());
}
}
else
{
int left = pos;
int leftend = oppos - 1;
int right = oppos + 1;
int rightend = posend;
if (tkCur.text == "(")
//.........这里部分代码省略.........
示例8: Compiler_Expression_DefineAndSet
public ICLS_Expression Compiler_Expression_DefineAndSet(IList<Token> tlist, ICLS_Environment content, int pos, int posend)
{
int expbegin =pos+3;
int bdep;
int expend = FindCodeAny(tlist, ref expbegin, out bdep);
if(expend!=posend)
{
expend = posend;
}
ICLS_Expression v;
bool succ = Compiler_Expression(tlist,content, expbegin, expend, out v);
if(succ&&v!=null)
{
CLS_Expression_Define define = new CLS_Expression_Define(pos, posend, tlist[pos].line, tlist[posend].line);
if (tlist[pos].text == "bool")
{
define.value_type = typeof(bool);
}
else
{
ICLS_Type type = content.GetTypeByKeyword(tlist[pos].text);
define.value_type = type.type;
}
define.value_name = tlist[pos + 1].text;
define.listParam.Add(v);
return define;
}
LogError(tlist,"不正确的定义表达式:" , pos,posend);
return null;
}