mewmew / uc

A compiler for the µC language.
57 stars 5 forks source link

semantics: Consider adding support for multiple errors, notifications and warnings #58

Closed mewmew closed 8 years ago

mewmew commented 8 years ago

Instead of simply returning the first error encountered during semantic analysis, we could try to provide as much useful information as possible. For this to work, we have to rethink how errors are currently processed, and potentially introduce some sort of error list which may store zero or more errors.

Once/if support for error lists are added, we may want to consider introducing a notion of notifications and warnings, which does not terminate the semantic analysis, but may provide useful information to the user or point out potentially incorrect source code constructs.

One potential user of the notification system would be the identifier resolver.

    // Definition already present in scope.
    if astutil.IsDef(decl) {
        // TODO: Consider adding support for multiple errors (and potentially
        // warnings and notifications).
        //
        // If support for notifications are added, add a note of the previous declaration.
        //    errors.Notef(prevIdent.Start(), "previous definition of %q", name)
        return errors.Newf(ident.Start(), "redefinition of %q", name)
    }

Which could produce something along the lines of

(../testdata/incorrect/semantic/se06.c:7) error: redefinition of "a"
int a(int i) {   // Redeclaration of 'a'
    ^
(../testdata/incorrect/semantic/se06.c:3) note: previous definition of "a"
int a(int n) {
    ^
mewmew commented 8 years ago

This issue has been marked as a future ambition. Closing for now.