fmt: insert newline after last HashStmt (#8482)
parent
53a5aad855
commit
d660f2cc6f
|
@ -1752,7 +1752,7 @@ Global variables are not allowed, so this can be really useful.
|
||||||
When naming constants, `snake_case` must be used. In order to distinguish consts
|
When naming constants, `snake_case` must be used. In order to distinguish consts
|
||||||
from local variables, the full path to consts must be specified. For example,
|
from local variables, the full path to consts must be specified. For example,
|
||||||
to access the PI const, full `math.pi` name must be used both outside the `math`
|
to access the PI const, full `math.pi` name must be used both outside the `math`
|
||||||
module, and inside it. That restriction is relaxed only for the `main` module
|
module, and inside it. That restriction is relaxed only for the `main` module
|
||||||
(the one containing your `fn main()`, where you can use the shorter name of the
|
(the one containing your `fn main()`, where you can use the shorter name of the
|
||||||
constants too, i.e. just `println(numbers)`, not `println(main.numbers)` .
|
constants too, i.e. just `println(numbers)`, not `println(main.numbers)` .
|
||||||
|
|
||||||
|
@ -3413,7 +3413,7 @@ single block. `customflag` should be a snake_case identifier, it can not
|
||||||
contain arbitrary characters (only lower case latin letters + numbers + `_`).
|
contain arbitrary characters (only lower case latin letters + numbers + `_`).
|
||||||
NB: a combinatorial `_d_customflag_linux.c.v` postfix will not work.
|
NB: a combinatorial `_d_customflag_linux.c.v` postfix will not work.
|
||||||
If you do need a custom flag file, that has platform dependent code, use the
|
If you do need a custom flag file, that has platform dependent code, use the
|
||||||
postfix `_d_customflag.v`, and then use plaftorm dependent compile time
|
postfix `_d_customflag.v`, and then use plaftorm dependent compile time
|
||||||
conditional blocks inside it, i.e. `$if linux {}` etc.
|
conditional blocks inside it, i.e. `$if linux {}` etc.
|
||||||
|
|
||||||
## Compile time pseudo variables
|
## Compile time pseudo variables
|
||||||
|
|
|
@ -4,6 +4,7 @@ module big
|
||||||
#flag -I @VROOT/thirdparty/bignum
|
#flag -I @VROOT/thirdparty/bignum
|
||||||
#flag @VROOT/thirdparty/bignum/bn.o
|
#flag @VROOT/thirdparty/bignum/bn.o
|
||||||
#include "bn.h"
|
#include "bn.h"
|
||||||
|
|
||||||
struct C.bn {
|
struct C.bn {
|
||||||
mut:
|
mut:
|
||||||
array [32]u32
|
array [32]u32
|
||||||
|
|
|
@ -2,6 +2,7 @@ module os
|
||||||
|
|
||||||
#include <sys/stat.h> // #include <signal.h>
|
#include <sys/stat.h> // #include <signal.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
struct C.dirent {
|
struct C.dirent {
|
||||||
d_name [256]char
|
d_name [256]char
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
module os
|
module os
|
||||||
|
|
||||||
#include "@VROOT/vlib/os/os_darwin.m"
|
#include "@VROOT/vlib/os/os_darwin.m"
|
||||||
|
|
||||||
pub const (
|
pub const (
|
||||||
sys_write = 4
|
sys_write = 4
|
||||||
sys_open = 5
|
sys_open = 5
|
||||||
|
|
|
@ -6,6 +6,7 @@ import strings
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
pub const (
|
pub const (
|
||||||
path_separator = '/'
|
path_separator = '/'
|
||||||
path_delimiter = ':'
|
path_delimiter = ':'
|
||||||
|
|
|
@ -3,6 +3,7 @@ module os
|
||||||
import strings
|
import strings
|
||||||
|
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
|
|
||||||
pub const (
|
pub const (
|
||||||
path_separator = '\\'
|
path_separator = '\\'
|
||||||
path_delimiter = ';'
|
path_delimiter = ';'
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
module time
|
module time
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
const (
|
const (
|
||||||
days_string = 'MonTueWedThuFriSatSun'
|
days_string = 'MonTueWedThuFriSatSun'
|
||||||
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
module time
|
module time
|
||||||
|
|
||||||
#include <mach/mach_time.h>
|
#include <mach/mach_time.h>
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// start_time is needed on Darwin and Windows because of potential overflows
|
// start_time is needed on Darwin and Windows because of potential overflows
|
||||||
start_time = C.mach_absolute_time()
|
start_time = C.mach_absolute_time()
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
module time
|
module time
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
struct C.tm {
|
struct C.tm {
|
||||||
tm_sec int
|
tm_sec int
|
||||||
tm_min int
|
tm_min int
|
||||||
|
|
|
@ -5,6 +5,7 @@ module time
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
// #include <sysinfoapi.h>
|
// #include <sysinfoapi.h>
|
||||||
|
|
||||||
struct C.tm {
|
struct C.tm {
|
||||||
tm_year int
|
tm_year int
|
||||||
tm_mon int
|
tm_mon int
|
||||||
|
|
|
@ -7,6 +7,7 @@ import v.cflag
|
||||||
#flag windows -l shell32
|
#flag windows -l shell32
|
||||||
#flag windows -l dbghelp
|
#flag windows -l dbghelp
|
||||||
#flag windows -l advapi32
|
#flag windows -l advapi32
|
||||||
|
|
||||||
struct MsvcResult {
|
struct MsvcResult {
|
||||||
full_cl_exe_path string
|
full_cl_exe_path string
|
||||||
exe_path string
|
exe_path string
|
||||||
|
|
|
@ -295,6 +295,9 @@ pub fn (f Fmt) imp_stmt_str(imp ast.Import) string {
|
||||||
|
|
||||||
fn (mut f Fmt) should_insert_newline_before_stmt(stmt ast.Stmt, prev_stmt ast.Stmt) bool {
|
fn (mut f Fmt) should_insert_newline_before_stmt(stmt ast.Stmt, prev_stmt ast.Stmt) bool {
|
||||||
prev_line_nr := prev_stmt.position().last_line
|
prev_line_nr := prev_stmt.position().last_line
|
||||||
|
if prev_stmt is ast.HashStmt && stmt !is ast.HashStmt && stmt !is ast.ExprStmt {
|
||||||
|
return true
|
||||||
|
}
|
||||||
// The stmt either has or shouldn't have a newline before
|
// The stmt either has or shouldn't have a newline before
|
||||||
if stmt.position().line_nr - prev_line_nr <= 1 || f.out.last_n(2) == '\n\n' {
|
if stmt.position().line_nr - prev_line_nr <= 1 || f.out.last_n(2) == '\n\n' {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
struct Foo {}
|
|
@ -0,0 +1,2 @@
|
||||||
|
#include "header.h"
|
||||||
|
struct Foo {}
|
|
@ -0,0 +1,12 @@
|
||||||
|
// comment above HashStmt
|
||||||
|
#flag -I @VROOT/c
|
||||||
|
#flag @VROOT/c/implementation.o
|
||||||
|
|
||||||
|
#include "@VROOT/c/implementation.h"
|
||||||
|
|
||||||
|
// comment between with newlines around
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
// comment between without newlines
|
||||||
|
#include "sqlite3.h"
|
||||||
|
// comment directly after the HsahStmt
|
|
@ -1,8 +0,0 @@
|
||||||
// comment above HashStmts
|
|
||||||
#flag linux -lsdl2
|
|
||||||
#include "stdio.h"
|
|
||||||
|
|
||||||
// comment between with newlines around
|
|
||||||
|
|
||||||
#include "header.h"
|
|
||||||
#include "sqlite3.h"
|
|
|
@ -1,3 +0,0 @@
|
||||||
#flag -I @VROOT/c
|
|
||||||
#flag @VROOT/c/implementation.o
|
|
||||||
#include "@VROOT/c/implementation.h"
|
|
Loading…
Reference in New Issue