123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- //注册C语言错误处理问题
- Namespace.register("U.CD.CE");
- //所有错误类型全局变量!
- U.CD.CE.EI = [
- [ "case label does not reduce to an integer constant", "GCC中,case语句后面只能跟常量,比如:1,2等,不能是表达式!也不能是变量" ],
- [ "duplicate case value", "Switch语句的每个case必须有一个唯一的常量表达式值。否则导致此类错误发生." ],
- [ "undeclared (first use in this function)", "前面的变量没有定义,需要明确定义为 int aaa,或者其他类型." ],
- [ "unknown type name ‘student’", "定义结构体时发生的错误,不知道的类型 student." ],
- [ "incompatible types when assigning to type ‘char[10]’ from type ‘char *’","不能给字符串数组直接赋值,只能用字符串拷贝函数strcpy拷贝。"],
- [ "expected ‘;’ before ‘for’", "for循环前面变量没有定义,错误在前面一句话。" ],
- ["expected ‘;’ before ‘int’", "在整形前面没有分号,其实是上一句前面少一个分号!"],
- ["unknown type name", "变量未定义,请定义为int 或者其他类型。"],
- ["expected ‘;’ before ‘)’ token", "在括号前要加分号!"],
- ["warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat]", "printf打印语句%d必须对应一个变量"],
- ["stray", "不能输入中文字符!"]
- ];
- U.CD.CE.Net = [
- ["The name `printf' does not exist in the current context"," 系统中不存在此函数!"],
- ["Literal of type double cannot be implicitly converted to type `float'. Add suffix `f' to create a literal of this type", "浮点型变量定义必须在数字后面加f"],
- ["Unexpected symbol `class', expecting `.', `::', `;', `<', or `='","using语句后面没有加;分号"],
- ["does not contain a static `Main' method suitable for an entry point", "必须有一个名字为Main的静态函数"],
- ["Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type", "C#数组定义方法和C不一样,是这样定义的int[] i"],
- ["Array initializers can only be used in a variable or field initializer. Try using a new expression instead",""],
- ["An object reference is required to access non-static member `main.max(int, int)'", "方法必须定义为静态的才能给Main调用"],
- ["Array type specifier, [], must appear before parameter name",""],
- ["System.Console' does not contain a definition for `Wrtie'","输出语句的Write您打错了"],
- ["Wrong preprocessor directive",""],
- [],
- []
- ];
- U.CD.CE.Python = [
- ["Non-ASCII character '\xe5' in file ./userfiles/cb58171ad95315b8bc6c3dc095b660b2.py on line 1, but no encoding declared", "暂时不支持中文!"],
- ["expected an indented block",""],
- []
- ];
- U.CD.CE.Ruby = [
- ["undefined method `[]' for nil:NilClass", "Ruby循环和传统语言不一样,是小于等于,不是小于,意味着循环10次是从0到9,不是从0到10."],
- ["undefined local variable or method","没有定义的变量或者方法,需要定义!"],
- []
- ]
- //-----------------------------------------------错误处理逻辑--------------------------------------------
- //判断编译是否成功。
- U.CD.CE.BuildErr = function (s) {
- var z = s.replace(/\r\n/g, '\n').split('\n'), i;
- for (i = 0; i < z.length; i++) if (z[i].indexOf('标准错误输出') > -1) return true;
- return false;
- }
- //默认的错误处理函数,不指定行数,也不定义帮助
- U.CD.CE.DefErr = function (d, s) {
- s = s.replace(/标准错误输出:/g, ""); //替换掉所有标准错误输出只留下第一个
- var z = s.replace(/\r\n/g, '\n').split('\n'), i;
- d.innerHTML = ""; //行号清空
- for (i = 0; i < z.length; i++) { $$("div", { "className": "UCD_R_E_L", "innerText": z[i] }, d); } //绘制行号
- }
- //C语言错误处理方法。
- U.CD.CE.CErr = function (d, s) {
- var z = s.replace(/\r\n/g, '\n').split('\n'), t, b,i;
- d.innerHTML = ""; //行号清空
- for (i = 0; i < z.length; i++) {
- //标准错误输出:./output/de135e620dfcb01a10d36297a54708c2.c:5:1: error: ‘asfdsadf’ undeclared (first use in this function)
- t = z[i].split(':'); //需要把上面的字符拆分出来,以指出具体错误。
- t.splice(1, 1); //去掉output/文件名.物理删除
- z[i] = t.join(':'); //合并截取掉的字符串输出。
- //如果是错误输出,追加帮助信息,警告信息暂时不理,其他信息也不理了。
- if (t[3] && t[3].trim() == "error") {
- b = $$("div", { "className": "UCD_R_E_L", "innerText": z[i], "onclick": [U.CD.CE.CErrLine, ([t, "retElement"])] }, d);
- $$("span", { "innerText": " 帮助", "className": "UCD_R_E_Help", "onclick": [[U.M.StopBubble], [U.CD.CE.CErrHelp, ([t])]] }, b);
- }
- else {
- $$("div", { "className": "UCD_R_E_L", "innerText": z[i] }, d); ; //绘制行号
- }
- }
- }
- //单击错误时转到相应错误行。传入的参数为行列
- U.CD.CE.CErrLine = function (t, o) {
- var l = $("#UCD_CT_Code_CT")[0], row;
- var r = t[1] - 1, c = t[2];
- //如果数组第三位是错误,则智能标识错误。
- if (U.CD.R.CErrF != null) U.CD.R.CErrF.style.backgroundColor = "white"; //把以前的错误信息颜色重置。
- U.CD.R.CErrF = l.getElementsByTagName("div")[r];
- U.CD.R.CErrF.style.backgroundColor = "red";
- }
- //具体错误帮助
- U.CD.CE.CErrHelp = function (t) {
- //首先判断是否已经有帮助在后面
- var b = U.CD.CE.EI, i, r = null;
- for (i = 0; i < b.length; i++) {
- if (t[4].indexOf(b[i][0]) > -1) {
- r = b[i];
- }
- }
- if (r) { U.UI.SUForms(r[1], "错误处理窗口", "UCD_R_ErrHelp", "color:red;", 300, 200); }
- else { alert("暂未收录此错误,请到反馈意见中添加此错误类型!"); }
- }
- //Nodejs错误处理,nodejs错误只会显示第一次出错的地方,有多个"标准错误输出:",需要截取掉。组成一行。
- U.CD.CE.NodeErr = function (d, s) {
- s = s.replace(/标准错误输出:/g, ""); //替换掉所有标准错误输出只留下第一个
- var z = s.replace(/\r\n/g, '\n').split('\n'), t, b;
- d.innerHTML = ""; //行号清空
- for (i = 0; i < z.length; i++) {
- //如果是错误输出,追加帮助信息,警告信息暂时不理,其他信息也不理了。
- if (z[i].indexOf("标准错误输出:test.js:")>-1) {
- b = $$("div", { "className": "UCD_R_E_L", "innerText": z[i], "onclick": [U.CD.CE.NodeErrLine, ([z[i], "retElement"])] }, d);
- $$("span", { "innerText": " 帮助", "className": "UCD_R_E_Help", "onclick": [[U.M.StopBubble], [U.CD.CE.NodeErrHelp, ([t])]] }, b);
- }
- else { $$("div", { "className": "UCD_R_E_L", "innerText": z[i] }, d); } //绘制行号
- }
- }
- U.CD.CE.NodeErrLine = function (t, o) {
- var l = $("#UCD_CT_Code_CT")[0];
- var r = parseInt(t.split(':')[2])-1;
- //如果数组第三位是错误,则智能标识错误。
- if (U.CD.R.CErrF != null) U.CD.R.CErrF.style.backgroundColor = "white"; //把以前的错误信息颜色重置。
- U.CD.R.CErrF = l.getElementsByTagName("div")[r];
- U.CD.R.CErrF.style.backgroundColor = "red";
- }
- U.CD.CE.NodeErrHelp = function () {
- //首先判断是否已经有帮助在后面
- var b = U.CD.CE.EI, i, r = null;
- for (i = 0; i < b.length; i++) {
- if (t[4].indexOf(b[i][0]) > -1) {
- r = b[i];
- }
- }
- if (r) { U.UI.SUForms(r[1], "错误处理窗口", "UCD_R_ErrHelp", "color:red;", 300, 200); }
- else { alert("暂未收录此错误,请到反馈意见中添加此错误类型!"); }
- }
- //PHP语言错误处理方法
- U.CD.PHPErr = function (d, s) {
-
- }
- //--------------lisp语言错误处理方式-----------------
- //lisp语言由于bug的原因会报EFAULT Bad address错误,需要另外处理,以弹出正确结构。因为是Bug,暂时放在前台处理。
- U.CD.CE.LispErr = function (d,s) {
- //判断标准错误输出和运行环境Linux+Lisp语言中间是否有字符,或者判断第二行是否有字符,如果程序错误z[2]中应该包含了标准错误输出
- //lisp print语句会先换行导致z[1]为空 format不会先换行,所以这里有点麻烦
- var z = s.replace(/\r\n/g, '\n').split('\n'), i, r = "";
- var k = s.substring(17, s.indexOf("标准错误输出")); //截取"运行环境Linux+Lisp语言"和"标准错误输出"之间的字符串,如果为空则表示有错误
- if (k.lTrim().length == 0) {
- //U.CD.CE.DefErr($("#UCD_CT_SM_IF")[0], "Linux+Lisp程序出错,请把 (format t \"hello\")语句放在第一行,逐行判断错误!");
- U.CD.CE.DefErr($("#UCD_CT_SM_IF")[0], s);
- }
- //去掉标准错误字样,只显示正确结果
- else {
- for (i = 0; i < z.length; i++) { if (z[i].indexOf("标准错误输出") > -1) break; else r += z[i] + "\n"; }
- U.CD.R.ORAsynOK(r);
- }
- }
|