protected static void AddFunction(Class cl, Json.Object mem, string name) { Function f = new Function(name, ((Json.Object)mem.GetValue("returnType"))); Json.Value meta; if ((meta = mem.GetValue("meta")) != null) { Dictionary <string, Json.Value> .KeyCollection keys = ((Json.Object)meta).GetKeys(); if (keys.Contains("static") == true) { f.is_static = true; } } Json.Array args = (Json.Array)mem.GetValue("arguments"); Json.Object arg; Function.Arg farg; for (int i = 0; i < args.GetCount(); ++i) { arg = (Json.Object)args.GetValue(i); farg = new Function.Arg( ((Json.String)arg.GetValue("name")).GetValue(), ((Json.Object)arg.GetValue("type"))); f.args.Add(farg); } cl.funcs.Add(f); }
public Function FunctionAnalyzer(int startindex) { Function function = new Function(); TOKEN tk = GetCurrentToken(); if (tk.Type != TOKEN_TYPE.Identifier) { ThrowException("함수의 이름에는 식별자가 와야 합니다.", tk); } string funcname = tk.Value; function.funcname = funcname; CursorLocation cl = CursorLocation.None; int argstartoffset = tk.EndOffset; int argendoffset = 0; if (!CheckCurrentToken(TOKEN_TYPE.Symbol, "(")) { ThrowException("함수의 이름 다음에는 인자선언이 와야 합니다.", tk); } while (true) { Function.Arg arg = new Function.Arg(); tk = GetCurrentToken(); if (tk.Type == TOKEN_TYPE.Identifier) { string argname = tk.Value; arg.argname = argname; } else { if (function.args.Count == 0) { if (tk.Type != TOKEN_TYPE.Symbol) { //무조건 심불이 와야됨 ThrowException("잘못된 인자 선언입니다. )가 와야합니다.", tk); } if (tk.Value == ")") { argendoffset = tk.EndOffset; break; } //인자가 없을 수 있음. } ThrowException("잘못된 인자 선언입니다. 인자 이름이 와야 합니다.", tk); } tk = GetCurrentToken(); if (tk.Type != TOKEN_TYPE.Symbol) { //무조건 심불이 와야됨 ThrowException("잘못된 인자 선언입니다. ) , :가 와야합니다.", tk); } if (tk.Value == ")") { argendoffset = tk.EndOffset; break; } else if (tk.Value == ",") { } else if (tk.Value == ":") { tk = GetCommentTokenIten(); if (tk.Type == TOKEN_TYPE.Identifier) { //일반 타입 arg.argtype = tk.Value; GetCurrentToken(); } else if (tk.Type == TOKEN_TYPE.Comment) { //특수처리된 타입 arg.argtype = tk.Value; GetCurrentToken(); } else { ThrowException("인자 타입을 선언해야 합니다.", tk); } } function.args.Add(arg); } if (cl == CursorLocation.None) { if (argstartoffset <= startindex && startindex <= argendoffset) { cl = CursorLocation.FunctionArgName; } } function.cursorLocation = cl; function.preCompletion = new ObjectItem(CompletionWordType.Function, funcname); return(function); }