Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
KISC-32 Compiler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kaelan Carlos
KISC-32 Compiler
Commits
a98da705
Verified
Commit
a98da705
authored
7 months ago
by
Kaelan Carlos
Browse files
Options
Downloads
Patches
Plain Diff
made error messages nicer
parent
ee64f1ab
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
main
+0
-0
0 additions, 0 deletions
main
main.cpp
+51
-13
51 additions, 13 deletions
main.cpp
messages.hpp
+25
-12
25 additions, 12 deletions
messages.hpp
with
76 additions
and
25 deletions
main
+
0
−
0
View file @
a98da705
No preview for this file type
This diff is collapsed.
Click to expand it.
main.cpp
+
51
−
13
View file @
a98da705
...
...
@@ -57,25 +57,52 @@ int main(int argc, char *argv[]) {
return
EXIT_SUCCESS
;
}
else
if
(
flag
==
"-v"
sv
||
flag
==
"--verbose"
sv
)
{
verbose
=
true
;
summary
=
true
;
}
else
if
(
flag
==
"-s"
sv
||
flag
==
"--summary"
sv
)
{
summary
=
true
;
else
if
(
flag
==
"--messages"
sv
)
{
msgs
::
note
(
"k32c"
,
"hello, world!"
,
" | This compiler is greeting the world.
\n
| Say 'hello' :)"
);
msgs
::
warn
(
"k3.14c"
,
"you're dangerously awesome"
,
" | You are incredibly cool.
\n
| Keep being your amazing self."
);
msgs
::
error
(
"k2.71c"
,
"i'm very grateful to you"
,
" | Thanks for using this small project of mine.
\n
| Have a cookie for your troubles 🍪
\n
(this is 100\% an error, what do you mean?)"
);
return
EXIT_SUCCESS
;
}
else
if
(
flag
==
"-o"
sv
||
flag
==
"--output"
)
{
i
++
;
if
(
i
==
argc
)
{
msgs
::
error
(
"missing filename after '
\033
[1m-o
\033
[0m'"
);
msgs
::
error
(
"k32c"
,
"missing file name after '
\033
[1m"
+
flag
+
"
\033
[0m'"
,
" | The "
+
flag
+
" option is used to change the name of the output binary.
\n
| Please specify a name for the output binary."
);
}
out_file_name
=
argv
[
i
];
}
else
if
(
flag
==
"-s"
sv
||
flag
==
"--summary"
sv
)
{
summary
=
true
;
}
else
if
(
flag
==
"-v"
sv
||
flag
==
"--verbose"
sv
)
{
verbose
=
true
;
summary
=
true
;
}
else
{
msgs
::
warn
(
"unknown option '
\033
[1m"
+
flag
+
"
\033
[0m' has been ignored"
);
msgs
::
warn
(
"k32c"
,
"unknown option '
\033
[1m"
+
flag
+
"
\033
[0m' has been ignored"
,
" | The "
+
flag
+
" option doesn't exist.
\n
| See all options with --help or -h."
);
}
}
...
...
@@ -84,7 +111,10 @@ int main(int argc, char *argv[]) {
std
::
string
arg
(
argv
[
i
]);
if
(
in_file_name
!=
""
sv
)
msgs
::
warn
(
"extraneous argument '
\033
[1m"
+
arg
+
"
\033
[0m' has been ignored"
);
msgs
::
warn
(
"k32c"
,
"extraneous argument '
\033
[1m"
+
arg
+
"
\033
[0m' has been ignored"
,
" | There should only be one file name.
\n
| Check that every option is in the right place."
);
in_file_name
=
arg
;
}
...
...
@@ -92,14 +122,22 @@ int main(int argc, char *argv[]) {
// Sanitise and validate file name
if
(
in_file_name
==
""
sv
)
{
msgs
::
fatal_error
(
"no input files"
);
msgs
::
fatal_error
(
"k32c"
,
"no input file"
,
" | This compiler is unable to compile nothing.
\n
| Please specify a file to compile."
);
}
else
if
(
!
std
::
filesystem
::
exists
(
in_file_name
))
{
msgs
::
fatal_error
(
in_file_name
+
": No such file or directory"
);
msgs
::
fatal_error
(
"k32c"
,
"unable to locate '"
+
in_file_name
+
"'"
,
" | This compiler is unable to compile nothing.
\n
| Please check the specified file name is correct."
);
}
if
(
summary
)
{
std
::
cout
<<
in_file_name
<<
" found, starting compilation."
<<
std
::
endl
;
std
::
cout
<<
out_file_name
<<
" will be the
final
binary."
<<
std
::
endl
;
std
::
cout
<<
out_file_name
<<
" will be the
output
binary."
<<
std
::
endl
;
}
return
EXIT_SUCCESS
;
...
...
This diff is collapsed.
Click to expand it.
messages.hpp
+
25
−
12
View file @
a98da705
...
...
@@ -49,33 +49,46 @@ std::string help = R"(Usage: k32c [options] file...
Options:
--copyright, or -c Display this program's copyright information.
--help, or -h Display this information.
--messages Display test messages.
--output, or -o Change the name of the output binary.
--summary, or -s Display summarised output during compilation.
--verbose, or -v Display more thorough output during compilation.)"
;
std
::
string
warning_prefix
=
"
\033
[1mk32c:
\033
[35mwarning:
\033
[0m"
;
std
::
string
error_prefix
=
"
\033
[1mk32c:
\033
[31merror:
\033
[0m"
;
std
::
string
fatal_error_prefix
=
"
\033
[1mk32c:
\033
[31mfatal error:
\033
[0m"
;
std
::
string
note_prefix
=
"
\033
[36mnote:
\033
[0m"
;
std
::
string
warning_prefix
=
"
\033
[35mwarning:
\033
[0m"
;
std
::
string
error_prefix
=
"
\033
[31merror:
\033
[0m"
;
std
::
string
fatal_error_prefix
=
"
\033
[31mfatal error:
\033
[0m"
;
// HELPER FUNCTIONS
void
warn
(
std
::
string
error_msg
)
{
void
note
(
std
::
string
file
,
std
::
string
summary
,
std
::
string
message
)
{
std
::
cout
<<
"
\033
[1m"
<<
file
<<
": "
;
std
::
cout
<<
note_prefix
;
std
::
cout
<<
summary
<<
std
::
endl
;
std
::
cout
<<
message
<<
std
::
endl
;
}
void
warn
(
std
::
string
file
,
std
::
string
summary
,
std
::
string
message
)
{
std
::
cout
<<
"
\033
[1m"
<<
file
<<
": "
;
std
::
cout
<<
warning_prefix
;
std
::
cout
<<
error_msg
;
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
summary
<<
std
::
endl
;
std
::
cout
<<
message
<<
std
::
endl
;
}
void
error
(
std
::
string
error_msg
)
{
void
error
(
std
::
string
file
,
std
::
string
summary
,
std
::
string
message
)
{
std
::
cout
<<
"
\033
[1m"
<<
file
<<
": "
;
std
::
cout
<<
error_prefix
;
std
::
cout
<<
error_msg
;
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
summary
<<
std
::
endl
;
std
::
cout
<<
message
<<
std
::
endl
;
std
::
cout
<<
"Compilation terminated."
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
void
fatal_error
(
std
::
string
error_msg
)
{
void
fatal_error
(
std
::
string
file
,
std
::
string
summary
,
std
::
string
message
)
{
std
::
cout
<<
"
\033
[1m"
<<
file
<<
": "
;
std
::
cout
<<
fatal_error_prefix
;
std
::
cout
<<
error_msg
;
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
summary
<<
std
::
endl
;
std
::
cout
<<
message
<<
std
::
endl
;
std
::
cout
<<
"Compilation terminated."
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment