mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Change @return! syntax to require ":" after faults. Update all contracts to consistently use ":" before the description.
This commit is contained in:
@@ -136,7 +136,7 @@ fn usz! File.read(&self, char[] buffer) @dynamic
|
||||
|
||||
<*
|
||||
@param [out] buffer
|
||||
@require self.file != null `File must be initialized`
|
||||
@require self.file != null : `File must be initialized`
|
||||
*>
|
||||
fn usz! File.write(&self, char[] buffer) @dynamic
|
||||
{
|
||||
@@ -164,8 +164,8 @@ fn char! File.read_byte(&self) @dynamic
|
||||
Load up to buffer.len characters. Returns IoError.OVERFLOW if the file is longer
|
||||
than the buffer.
|
||||
|
||||
@param filename "The path to the file to read"
|
||||
@param [in] buffer "The buffer to read to"
|
||||
@param filename : "The path to the file to read"
|
||||
@param [in] buffer : "The buffer to read to"
|
||||
*>
|
||||
fn char[]! load_buffer(String filename, char[] buffer)
|
||||
{
|
||||
@@ -222,7 +222,7 @@ fn void! save(String filename, char[] data)
|
||||
}
|
||||
|
||||
<*
|
||||
@require self.file != null `File must be initialized`
|
||||
@require self.file != null : `File must be initialized`
|
||||
*>
|
||||
fn void! File.flush(&self) @dynamic
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ macro bool is_struct_with_default_print($Type)
|
||||
<*
|
||||
Introspect a struct and print it to a formatter
|
||||
|
||||
@require @typekind(value) == STRUCT `This macro is only valid on macros`
|
||||
@require @typekind(value) == STRUCT : `This macro is only valid on macros`
|
||||
*>
|
||||
macro usz! struct_to_format(value, Formatter* f, bool $force_dump)
|
||||
{
|
||||
|
||||
@@ -138,9 +138,9 @@ fn FloatType! float_from_any(any arg) @private
|
||||
<*
|
||||
Read a simple integer value, typically for formatting.
|
||||
|
||||
@param [inout] len_ptr "the length remaining."
|
||||
@param [in] buf "the buf to read from."
|
||||
@param maxlen "the maximum len that can be read."
|
||||
@param [inout] len_ptr : "the length remaining."
|
||||
@param [in] buf : "the buf to read from."
|
||||
@param maxlen : "the maximum len that can be read."
|
||||
@return "The result of the atoi."
|
||||
*>
|
||||
fn uint simple_atoi(char* buf, usz maxlen, usz* len_ptr) @inline @private
|
||||
|
||||
@@ -50,9 +50,9 @@ fault IoError
|
||||
or to the end of the stream, whatever comes first.
|
||||
"\r" will be filtered from the String.
|
||||
|
||||
@param stream `The stream to read from.`
|
||||
@require @is_instream(stream) `The stream must implement InStream.`
|
||||
@param [inout] allocator `the allocator to use.`
|
||||
@param stream : `The stream to read from.`
|
||||
@require @is_instream(stream) : `The stream must implement InStream.`
|
||||
@param [inout] allocator : `the allocator to use.`
|
||||
@return `The string containing the data read.`
|
||||
*>
|
||||
macro String! readline(Allocator allocator, stream = io::stdin())
|
||||
@@ -94,8 +94,8 @@ macro String! readline(Allocator allocator, stream = io::stdin())
|
||||
Reads a string, see `readline`, except the it is allocated
|
||||
on the temporary allocator and does not need to be freed.
|
||||
|
||||
@param stream `The stream to read from.`
|
||||
@require @is_instream(stream) `The stream must implement InStream.`
|
||||
@param stream : `The stream to read from.`
|
||||
@require @is_instream(stream) : `The stream must implement InStream.`
|
||||
@return `The temporary string containing the data read.`
|
||||
*>
|
||||
macro String! treadline(stream = io::stdin())
|
||||
@@ -106,9 +106,9 @@ macro String! treadline(stream = io::stdin())
|
||||
<*
|
||||
Print a value to a stream.
|
||||
|
||||
@param out `the stream to print to`
|
||||
@param x `the value to print`
|
||||
@require @is_outstream(out) `The output must implement OutStream.`
|
||||
@param out : `the stream to print to`
|
||||
@param x : `the value to print`
|
||||
@require @is_outstream(out) : `The output must implement OutStream.`
|
||||
@return `the number of bytes printed.`
|
||||
*>
|
||||
macro usz! fprint(out, x)
|
||||
@@ -137,8 +137,8 @@ macro usz! fprint(out, x)
|
||||
Prints using a 'printf'-style formatting string.
|
||||
See `printf` for details on formatting.
|
||||
|
||||
@param [inout] out `The OutStream to print to`
|
||||
@param [in] format `The printf-style format string`
|
||||
@param [inout] out : `The OutStream to print to`
|
||||
@param [in] format : `The printf-style format string`
|
||||
@return `the number of characters printed`
|
||||
*>
|
||||
fn usz! fprintf(OutStream out, String format, args...)
|
||||
@@ -152,8 +152,8 @@ fn usz! fprintf(OutStream out, String format, args...)
|
||||
Prints using a 'printf'-style formatting string,
|
||||
appending '\n' at the end. See `printf`.
|
||||
|
||||
@param [inout] out `The OutStream to print to`
|
||||
@param [in] format `The printf-style format string`
|
||||
@param [inout] out : `The OutStream to print to`
|
||||
@param [in] format : `The printf-style format string`
|
||||
@return `the number of characters printed`
|
||||
*>
|
||||
fn usz! fprintfn(OutStream out, String format, args...) @maydiscard
|
||||
@@ -167,7 +167,7 @@ fn usz! fprintfn(OutStream out, String format, args...) @maydiscard
|
||||
}
|
||||
|
||||
<*
|
||||
@require @is_outstream(out) "The output must implement OutStream"
|
||||
@require @is_outstream(out) : "The output must implement OutStream"
|
||||
*>
|
||||
macro usz! fprintn(out, x = "")
|
||||
{
|
||||
@@ -193,7 +193,7 @@ macro void print(x)
|
||||
<*
|
||||
Print any value to stdout, appending an '\n’ after.
|
||||
|
||||
@param x "The value to print"
|
||||
@param x : "The value to print"
|
||||
*>
|
||||
macro void printn(x = "")
|
||||
{
|
||||
@@ -211,7 +211,7 @@ macro void eprint(x)
|
||||
<*
|
||||
Print any value to stderr, appending an '\n’ after.
|
||||
|
||||
@param x "The value to print"
|
||||
@param x : "The value to print"
|
||||
*>
|
||||
macro void eprintn(x)
|
||||
{
|
||||
@@ -248,7 +248,7 @@ fn void! out_putchar_fn(void* data @unused, char c) @private
|
||||
To create a custom output for a type, implement
|
||||
the Printable interface.
|
||||
|
||||
@param [in] format `The printf-style format string`
|
||||
@param [in] format : `The printf-style format string`
|
||||
@return `the number of characters printed`
|
||||
*>
|
||||
fn usz! printf(String format, args...) @maydiscard
|
||||
@@ -262,7 +262,7 @@ fn usz! printf(String format, args...) @maydiscard
|
||||
Prints using a 'printf'-style formatting string,
|
||||
appending '\n' at the end. See `printf`.
|
||||
|
||||
@param [in] format `The printf-style format string`
|
||||
@param [in] format : `The printf-style format string`
|
||||
@return `the number of characters printed`
|
||||
*>
|
||||
fn usz! printfn(String format, args...) @maydiscard
|
||||
@@ -279,7 +279,7 @@ fn usz! printfn(String format, args...) @maydiscard
|
||||
Prints using a 'printf'-style formatting string
|
||||
to stderr.
|
||||
|
||||
@param [in] format `The printf-style format string`
|
||||
@param [in] format : `The printf-style format string`
|
||||
@return `the number of characters printed`
|
||||
*>
|
||||
fn usz! eprintf(String format, args...) @maydiscard
|
||||
@@ -295,7 +295,7 @@ fn usz! eprintf(String format, args...) @maydiscard
|
||||
Prints using a 'printf'-style formatting string,
|
||||
to stderr appending '\n' at the end. See `printf`.
|
||||
|
||||
@param [in] format `The printf-style format string`
|
||||
@param [in] format : `The printf-style format string`
|
||||
@return `the number of characters printed`
|
||||
*>
|
||||
fn usz! eprintfn(String format, args...) @maydiscard
|
||||
@@ -313,8 +313,8 @@ fn usz! eprintfn(String format, args...) @maydiscard
|
||||
Prints using a 'printf'-style formatting string,
|
||||
to a string buffer. See `printf`.
|
||||
|
||||
@param [inout] buffer `The buffer to print to`
|
||||
@param [in] format `The printf-style format string`
|
||||
@param [inout] buffer : `The buffer to print to`
|
||||
@param [in] format : `The printf-style format string`
|
||||
@return `a slice formed from the "buffer" with the resulting length.`
|
||||
*>
|
||||
fn char[]! bprintf(char[] buffer, String format, args...) @maydiscard
|
||||
|
||||
@@ -92,10 +92,10 @@ enum MkdirPermissions
|
||||
<*
|
||||
Create a directory on a given path, optionally recursive.
|
||||
|
||||
@param path `The path to create`
|
||||
@param path : `The path to create`
|
||||
@require @is_pathlike(path) : "Expected a Path or String to chdir"
|
||||
@param recursive `If directories in between should be created if they're missing, defaults to false`
|
||||
@param permissions `The permissions to set on the directory`
|
||||
@param recursive : `If directories in between should be created if they're missing, defaults to false`
|
||||
@param permissions : `The permissions to set on the directory`
|
||||
*>
|
||||
macro bool! mkdir(Path path, bool recursive = false, MkdirPermissions permissions = NORMAL)
|
||||
{
|
||||
@@ -110,10 +110,10 @@ macro bool! mkdir(Path path, bool recursive = false, MkdirPermissions permission
|
||||
<*
|
||||
Tries to delete directory, which must be empty.
|
||||
|
||||
@param path `The path to delete`
|
||||
@param path : `The path to delete`
|
||||
@require @is_pathlike(path) : "Expected a Path or String to chdir"
|
||||
@return `true if there was a directory to delete, false otherwise`
|
||||
@return! PathResult.INVALID_PATH `if the path was invalid`
|
||||
@return! PathResult.INVALID_PATH : `if the path was invalid`
|
||||
*>
|
||||
macro bool! rmdir(path)
|
||||
{
|
||||
@@ -140,7 +140,7 @@ fn void! rmtree(Path path)
|
||||
<*
|
||||
Creates a new path.
|
||||
|
||||
@return! PathResult.INVALID_PATH `if the path was invalid`
|
||||
@return! PathResult.INVALID_PATH : `if the path was invalid`
|
||||
*>
|
||||
fn Path! new(Allocator allocator, String path, PathEnv path_env = DEFAULT_ENV)
|
||||
{
|
||||
@@ -150,7 +150,7 @@ fn Path! new(Allocator allocator, String path, PathEnv path_env = DEFAULT_ENV)
|
||||
<*
|
||||
Creates a new path using the temp allocator.
|
||||
|
||||
@return! PathResult.INVALID_PATH `if the path was invalid`
|
||||
@return! PathResult.INVALID_PATH : `if the path was invalid`
|
||||
*>
|
||||
fn Path! temp(String path, PathEnv path_env = DEFAULT_ENV)
|
||||
{
|
||||
@@ -316,7 +316,7 @@ fn String Path.dirname(self)
|
||||
Test if the path has the given extension, so given the path /foo/bar.c3
|
||||
this would be true matching the extension "c3"
|
||||
|
||||
@param [in] extension `The extension name (not including the leading '.')`
|
||||
@param [in] extension : `The extension name (not including the leading '.')`
|
||||
@require extension.len > 0 : `The extension cannot be empty`
|
||||
@return `true if the extension matches`
|
||||
*>
|
||||
@@ -396,7 +396,7 @@ fn usz! volume_name_len(String path, PathEnv path_env) @local
|
||||
of the path itself.
|
||||
|
||||
@return `The parent of the path as a non-allocated path`
|
||||
@return! PathResult.NO_PARENT `if this path does not have a parent`
|
||||
@return! PathResult.NO_PARENT : `if this path does not have a parent`
|
||||
*>
|
||||
fn Path! Path.parent(self)
|
||||
{
|
||||
|
||||
@@ -57,7 +57,7 @@ macro usz! read_any(stream, any ref)
|
||||
}
|
||||
|
||||
<*
|
||||
@param [&in] ref "the object to write."
|
||||
@param [&in] ref : "the object to write."
|
||||
@require @is_outstream(stream)
|
||||
@ensure return == ref.type.sizeof
|
||||
*>
|
||||
@@ -393,7 +393,7 @@ macro void! write_be_int128(stream, uint128 s)
|
||||
|
||||
<*
|
||||
@require @is_outstream(stream)
|
||||
@require data.len < 256 "Data exceeded 255"
|
||||
@require data.len < 256 : "Data exceeded 255"
|
||||
*>
|
||||
macro usz! write_tiny_bytearray(stream, char[] data)
|
||||
{
|
||||
@@ -415,7 +415,7 @@ macro char[]! read_tiny_bytearray(stream, Allocator allocator)
|
||||
|
||||
<*
|
||||
@require @is_outstream(stream)
|
||||
@require data.len < 0x1000 "Data exceeded 65535"
|
||||
@require data.len < 0x1000 : "Data exceeded 65535"
|
||||
*>
|
||||
macro usz! write_short_bytearray(stream, char[] data)
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ struct ReadBuffer (InStream)
|
||||
Buffer reads from a stream.
|
||||
@param [inout] self
|
||||
@require bytes.len > 0
|
||||
@require self.bytes.len == 0 "Init may not run on already initialized data"
|
||||
@require self.bytes.len == 0 : "Init may not run on already initialized data"
|
||||
*>
|
||||
fn ReadBuffer* ReadBuffer.init(&self, InStream wrapped_stream, char[] bytes)
|
||||
{
|
||||
@@ -71,8 +71,8 @@ struct WriteBuffer (OutStream)
|
||||
<*
|
||||
Buffer writes to a stream. Call `flush` when done writing to the buffer.
|
||||
@param [inout] self
|
||||
@require bytes.len > 0 "Non-empty buffer required"
|
||||
@require self.bytes.len == 0 "Init may not run on already initialized data"
|
||||
@require bytes.len > 0 : "Non-empty buffer required"
|
||||
@require self.bytes.len == 0 : "Init may not run on already initialized data"
|
||||
*>
|
||||
fn WriteBuffer* WriteBuffer.init(&self, OutStream wrapped_stream, char[] bytes)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ struct ByteBuffer (InStream, OutStream)
|
||||
<*
|
||||
ByteBuffer provides a streamable read/write buffer.
|
||||
max_read defines how many bytes might be kept before its internal buffer is shrinked.
|
||||
@require self.bytes.len == 0 "Buffer already initialized."
|
||||
@require self.bytes.len == 0 : "Buffer already initialized."
|
||||
*>
|
||||
fn ByteBuffer* ByteBuffer.init(&self, Allocator allocator, usz max_read, usz initial_capacity = 16)
|
||||
{
|
||||
@@ -31,7 +31,7 @@ fn ByteBuffer* ByteBuffer.tinit(&self, usz max_read, usz initial_capacity = 16)
|
||||
|
||||
<*
|
||||
@require buf.len > 0
|
||||
@require self.bytes.len == 0 "Buffer already initialized."
|
||||
@require self.bytes.len == 0 : "Buffer already initialized."
|
||||
*>
|
||||
fn ByteBuffer* ByteBuffer.init_with_buffer(&self, char[] buf)
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ struct ByteWriter (OutStream)
|
||||
<*
|
||||
@param [&inout] self
|
||||
@param [&inout] allocator
|
||||
@require self.bytes.len == 0 "Init may not run on already initialized data"
|
||||
@require self.bytes.len == 0 : "Init may not run on already initialized data"
|
||||
@ensure (bool)allocator, self.index == 0
|
||||
*>
|
||||
fn ByteWriter* ByteWriter.init(&self, Allocator allocator)
|
||||
@@ -22,7 +22,7 @@ fn ByteWriter* ByteWriter.init(&self, Allocator allocator)
|
||||
|
||||
<*
|
||||
@param [&inout] self
|
||||
@require self.bytes.len == 0 "Init may not run on already initialized data"
|
||||
@require self.bytes.len == 0 : "Init may not run on already initialized data"
|
||||
@ensure self.index == 0
|
||||
*>
|
||||
fn ByteWriter* ByteWriter.tinit(&self)
|
||||
|
||||
@@ -7,8 +7,8 @@ struct LimitReader (InStream)
|
||||
}
|
||||
|
||||
<*
|
||||
@param [&inout] wrapped_stream "The stream to read from"
|
||||
@param limit "The max limit to read"
|
||||
@param [&inout] wrapped_stream : "The stream to read from"
|
||||
@param limit : "The max limit to read"
|
||||
*>
|
||||
fn LimitReader* LimitReader.init(&self, InStream wrapped_stream, usz limit)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ struct MultiReader (InStream)
|
||||
<*
|
||||
@param [&inout] self
|
||||
@param [&inout] allocator
|
||||
@require self.readers.len == 0 "Init may not run on already initialized data"
|
||||
@require self.readers.len == 0 : "Init may not run on already initialized data"
|
||||
@ensure self.index == 0
|
||||
*>
|
||||
fn MultiReader* MultiReader.init(&self, Allocator allocator, InStream... readers)
|
||||
@@ -28,7 +28,7 @@ fn MultiReader* MultiReader.init(&self, Allocator allocator, InStream... readers
|
||||
|
||||
<*
|
||||
@param [&inout] self
|
||||
@require self.readers.len == 0 "Init may not run on already initialized data"
|
||||
@require self.readers.len == 0 : "Init may not run on already initialized data"
|
||||
@ensure self.index == 0
|
||||
*>
|
||||
fn MultiReader* MultiReader.tinit(&self, InStream... readers)
|
||||
|
||||
@@ -13,7 +13,7 @@ struct MultiWriter (OutStream)
|
||||
@param [&inout] self
|
||||
@param [&inout] allocator
|
||||
@require writers.len > 0
|
||||
@require self.writers.len == 0 "Init may not run on already initialized data"
|
||||
@require self.writers.len == 0 : "Init may not run on already initialized data"
|
||||
*>
|
||||
fn MultiWriter* MultiWriter.init(&self, Allocator allocator, OutStream... writers)
|
||||
{
|
||||
@@ -26,7 +26,7 @@ fn MultiWriter* MultiWriter.init(&self, Allocator allocator, OutStream... writer
|
||||
<*
|
||||
@param [&inout] self
|
||||
@require writers.len > 0
|
||||
@require self.writers.len == 0 "Init may not run on already initialized data"
|
||||
@require self.writers.len == 0 : "Init may not run on already initialized data"
|
||||
*>
|
||||
fn MultiWriter* MultiWriter.tinit(&self, OutStream... writers)
|
||||
{
|
||||
|
||||
@@ -13,8 +13,8 @@ struct Scanner (InStream)
|
||||
The supplied buffer must be at least as large as the expected data length
|
||||
including its pattern.
|
||||
|
||||
@param [&in] stream "The stream to read data from."
|
||||
@require buffer.len > 0 "Non-empty buffer required."
|
||||
@param [&in] stream : "The stream to read data from."
|
||||
@require buffer.len > 0 : "Non-empty buffer required."
|
||||
*>
|
||||
fn void Scanner.init(&self, InStream stream, char[] buffer)
|
||||
{
|
||||
@@ -42,8 +42,8 @@ fn void! Scanner.close(&self) @dynamic
|
||||
|
||||
<*
|
||||
Scan the stream for the next split character and return data up to the match.
|
||||
@require pattern.len > 0 "Non-empty pattern required."
|
||||
@require self.buf.len > pattern.len "Pattern too large."
|
||||
@require pattern.len > 0 : "Non-empty pattern required."
|
||||
@require self.buf.len > pattern.len : "Pattern too large."
|
||||
*>
|
||||
fn char[]! Scanner.scan(&self, String pattern = "\n")
|
||||
{
|
||||
|
||||
@@ -9,15 +9,15 @@ struct TeeReader (InStream)
|
||||
<* Returns a reader that implements InStream and that will write any data read
|
||||
from the wrapped reader r to the writer w. There is no internal buffering.
|
||||
|
||||
@param [&inout] r "Stream r to read from."
|
||||
@param [&inout] w "Stream w to write to what it reads from r."
|
||||
@param [&inout] r : "Stream r to read from."
|
||||
@param [&inout] w : "Stream w to write to what it reads from r."
|
||||
*>
|
||||
macro TeeReader tee_reader(InStream r, OutStream w) => { r, w };
|
||||
|
||||
<*
|
||||
@param [&inout] self
|
||||
@param [&inout] r "Stream r to read from."
|
||||
@param [&inout] w "Stream w to write to what it reads from r."
|
||||
@param [&inout] r : "Stream r to read from."
|
||||
@param [&inout] w : "Stream w to write to what it reads from r."
|
||||
*>
|
||||
fn TeeReader* TeeReader.init(&self, InStream r, OutStream w)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user