private ParsedFunc parse_func() { ParsedFunc func = new ParsedFunc(); string tok; string prev = ""; bool arg_list_started = false; bool arg_list_ended = false; func.return_type = ""; //might not have return value - constructor/destructor int scope_depth = 0; int template_scope_depth = 0; func.args_list = new List<ParsedArgument>(); ParsedArgument arg = new ParsedArgument(); //bool first_arg = true; tok = m_MainTokenizer.NextToken(); prev = tok; //using one lookahead. while (tok!=null) { tok = m_MainTokenizer.NextToken(); //note: i do not support const functions. if (";" == tok) { if (prev == "}") { return null; } if (func.func_name == func.return_type) { //constructor/destructor func.return_type = ""; } return func; } if ("<" == prev) { template_scope_depth++; } else if (">" == prev) { template_scope_depth--; } if ("{" == prev) { scope_depth++; } else if ("}" == prev) { scope_depth--; if (scope_depth < 0) return null; } else { //if we're in deeper scope, then it's function definition which we don't care about. if (0 == scope_depth) { if ("(" == tok) { arg_list_started = true; func.func_name = prev; } else if (")" == prev) { arg_list_ended = true; } else /*if (";" == prev) { if (func.func_name == func.return_type) { //constructor/destructor func.return_type = ""; } return func; } else*/ { if (!arg_list_started && !arg_list_ended) { if (prev.Contains("__declspec") || prev.Contains("__stdcall") || prev.Contains("virtual") ) { if (!prev.Contains("__declspec(dllimport)") && !prev.Contains("__declspec(nothrow)") && !prev.Contains("virtual")) { if (func.call_type != "") { func.call_type += " "; } func.call_type += prev; } } else { if (func.return_type != "") { func.return_type += " "; } func.return_type += prev; } } else if (arg_list_started == true && !arg_list_ended) { if ( ("(" != prev && "," != prev) || 0!=template_scope_depth) { if (("," == tok || ")" == tok) && 0 == template_scope_depth) // if next is "," or ")" and we're not inside a template definition { arg.arg_name = prev; func.args_list.Add(arg); arg = new ParsedArgument(); } else { arg.arg_type += prev + " "; } } } } } } prev = tok; } Debug.Print("Error! text ended before func declaration ended.\n"); return null; }