Browse Source

Parse errors and warnings (part 1)

dev/git-series/gccdum
Matt Godbolt 7 years ago
parent
commit
f5a3f7653c
  1. 14
      .idea/libraries/gcc_explorer_node_modules.xml
  2. 9
      static/compiler.js
  3. 57
      static/editor.js
  4. 43
      static/explorer.css

14
.idea/libraries/gcc_explorer_node_modules.xml

@ -0,0 +1,14 @@
<component name="libraryTable">
<library name="gcc-explorer node_modules" type="javaScript">
<properties>
<option name="frameworkName" value="node_modules" />
<sourceFilesUrls>
<item url="file://$PROJECT_DIR$/node_modules" />
</sourceFilesUrls>
</properties>
<CLASSES>
<root url="file://$PROJECT_DIR$/node_modules" />
</CLASSES>
<SOURCES />
</library>
</component>

9
static/compiler.js

@ -29,6 +29,7 @@ define(function (require) {
this.compiler = state.compiler || options.defaultCompiler;
this.options = state.options || options.compileOptions;
this.filters = state.filters || getFilters(this.domRoot);
this.editorState = {};
this.domRoot.find(".compiler").selectize({
sortField: 'name',
@ -76,10 +77,14 @@ define(function (require) {
container.on('open', resize);
container.setTitle("Compiled");
container.on('close', function () {
if (self.sourceEditor) self.sourceEditor.onCompilerDetach(self);
hub.removeCompiler(self);
});
}
// TODO: old gcc explorer used keyboard events to prevent compiling if you were
// still typing and not even changing anything. This new approach here means
// 500ms after the last _change_ we compile.
var debouncedAjax = _.debounce($.ajax, 500);
Compiler.prototype.compile = function (fromEditor) {
@ -125,16 +130,20 @@ define(function (require) {
ga('send', 'event', 'Compile', request.compiler, request.options, result.code);
ga('send', 'timing', 'Compile', 'Timing', Date.now() - request.timestamp)
this.setAssembly(result.asm || fakeAsm("[no output]"));
if (this.sourceEditor) this.sourceEditor.onCompileResponse(this, result);
};
Compiler.prototype.onEditorListChange = function () {
// TODO: if we can't find our source, select none?
// TODO: Update dropdown of source
// TODO: remember if we change editor source we must detach and re-attach
};
Compiler.prototype.onEditorChange = function (editor) {
if (this.sourceEditor) this.sourceEditor.onCompilerDetach(this);
if (editor.getId() == this.source) {
this.sourceEditor = editor;
if (this.sourceEditor) this.sourceEditor.onCompilerAttach(this);
this.compile();
}
};

57
static/editor.js

@ -84,5 +84,62 @@ define(function (require) {
return this.id;
};
function makeErrorNode(text) {
var clazz = "error";
if (text.match(/^warning/)) clazz = "warning";
if (text.match(/^note/)) clazz = "note";
var node = $('<div class="' + clazz + ' inline-msg"><span class="icon">!!</span><span class="msg"></span></div>');
node.find(".msg").text(text);
return node[0];
}
function parseLines(lines, callback) {
var re = /^\/tmp\/[^:]+:([0-9]+)(:([0-9]+))?:\s+(.*)/;
$.each(lines.split('\n'), function (_, line) {
line = line.trim();
if (line !== "") {
var match = line.match(re);
if (match) {
callback(parseInt(match[1]), match[4].trim());
} else {
callback(null, line);
}
}
});
}
Editor.prototype.removeWidgets = function (compiler) {
var self = this;
_.each(compiler.editorState.widgets, function (widget) {
self.editor.removeLineWidget(widget);
});
};
Editor.prototype.onCompilerAttach = function (compiler) {
compiler.editorState = {
widgets: []
};
};
Editor.prototype.onCompilerDetach = function (compiler) {
this.removeWidgets(compiler);
compiler.editorState = {};
};
Editor.prototype.onCompileResponse = function (compiler, result) {
var output = (result.stdout || "") + (result.stderr || "");
var self = this;
this.removeWidgets(compiler);
parseLines(output, function (lineNum, msg) {
if (lineNum) {
var widget = self.editor.addLineWidget(
lineNum - 1,
makeErrorNode(msg),
{coverGutter: false, noHScroll: true});
compiler.editorState.widgets.push(widget);
}
});
};
return Editor;
});

43
static/explorer.css

@ -36,3 +36,46 @@
#flattr_button {
width: 120px;
}
.inline-msg {
font-family: arial;
font-size: 70%;
padding: 2px 5px 3px;
}
span.icon {
border-radius: 50%;
padding: 0 3px;
margin-right: 7px;
}
.error {
background: #faa !important;
color: #a00;
}
.error span.icon {
color: white;
background-color: red;
font-weight: bold;
}
.warning {
background: #ffa !important;
color: #440;
}
.warning span.icon {
color: black;
background-color: yellow;
}
.note {
background: #aaf !important;
color: #00a;
}
.note span.icon {
color: white;
background-color: blue;
}

Loading…
Cancel
Save