Need Help Figuring Out Some clang-format Options - llvm-clang

While using clang-format (8.0.0) I am encountering weird formatting issues that I feel may be bugs. I don't want to jump the gun and report them as bugs without knowing if I'm doing something incorrectly or missed a configuration setting though. I have a few examples of where I feel my settings are not being adhered to and instead the formatter is going 'rogue' in a sense.
Here is my .clang-format settings file:
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: true
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: true
BreakStringLiterals: true
ColumnLimit: 0
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: false
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
...
Example 1 - Single line assignments with multiple parentheses:
Before formatting:
extern "C"
{
HBITMAP (WINAPI *Real_LoadBitmapW)(HINSTANCE, LPCWSTR) = LoadBitmapW;
HANDLE (WINAPI *Real_OpenMutexA)(DWORD, BOOL, LPCSTR) = OpenMutexA;
}
After formatting:
HBITMAP(WINAPI* Real_LoadBitmapW)
(HINSTANCE, LPCWSTR) = LoadBitmapW;
HANDLE(WINAPI* Real_OpenMutexA)
(DWORD, BOOL, LPCSTR) = OpenMutexA;
Expected results:
HBITMAP (WINAPI* Real_LoadBitmapW)(HINSTANCE, LPCWSTR) = LoadBitmapW;
HANDLE (WINAPI* Real_OpenMutexA)(DWORD, BOOL, LPCSTR) = OpenMutexA;
Here, the formatter is randomly breaking my assignments into new lines as it sees fit. The ColumnWidth setting here appears to not be honored. If I set the ColumnWidth to an actual number, say 200, then the lines to not break, but the formatting is still incorrect as now space is placed after the return type. But using ColumnWidth breaks other formatting. I want to have ColumnWidth be set to 0 overall. I'm not sure what rule is forcing this to a new line and removing spaces after the return type.
Example 2 - Not Honoring C-Style Casting Space Setting:
Before formatting:
auto prodVer = (LPVOID)nullptr;
auto prodVerSize = (UINT)0;
After formatting:
auto prodVer = (LPVOID) nullptr;
auto prodVerSize = (UINT)0;
Expected results:
auto prodVer = (LPVOID)nullptr;
auto prodVerSize = (UINT)0;
Here, a space is being added before the nullptr. This seems to only happen when using nullptr as the value being casted. If switched to a number or variable, it works fine. Also if switching the LPVOID to say, void*, it also fixes the issue. Also, with this issue, changing the 'Standard' setting from Cpp11 to Cpp03 fixes it as well but then introduces other formatting I do not want because of the standard changes. My code uses C++11,14,17,20 so using the Cpp11 Standard setting is needed here.
I just started using clang-format last night so I'm very new to this and trying to understand how the rules affect each other. I've read the docs page covering each rule and what it does, it just seems at certain times they are ignored like above.
I have other cases/issues, but I feel they may play into the above two. If I get these fixed first, the others may be fixed already as well so I can create another question later if more problems persist.

Related

MarkLogic - false is true

let $d := doc('/test/a-false.json')
return ($d, if ($d/a) then 'false is true' else 'false is false')
The result:
{"a":false}
false is true
Really?
StackOverflow's robot was not contented with the above, so I will add some meaningless text that you don't have to read, even though I think the above is more than adequate at describing the problem. Long live our mechanical overlords.
In your example $d/a is a boolean node, a MarkLogic extension, part of the set of node types added to represent JSON in XDM.
The EBV of such a node is true if it exists. Which might be surprising for a boolean node with the value false. What you see here is the answer to the question: "Does such a node exists?" For the question "Is its value false?," use fn:data().
Relevant expressions:
let $d := fn:doc('/test/a-false.json')
return (
$d,
$d/a,
fn:data($d/a),
if ( $d/a ) then 'false exists' else 'false does not exist',
if ( fn:data($d/a) ) then 'false is true' else 'false is not true'
)
Result:
{"a":false}
fn:doc("/test/a-false.json")/boolean-node("a")
false
false exists
false is not true

How to find the min/max value between sequential rows in a dataframe with for loop?

i am currently trying to find whether the high price(column 'high') is the highest among 1 and -1 periods away, if so then it would return True in my new added column called 'high_peak'. This is what i've managed but the output returns everything False. Can someone help me out please? im a new learner which just started to learn python, so if there could be some elaboration along the lines would be much appreciated :D
Here's what i did:
SPX = pd.read_csv(r'D:\Users\jimmyli\Downloads\SP_SPX, 1D.csv', index_col = 'time')
def peak(x):
for i in range(len(x)):
if x[i] > x[i+1] and x[i] > x[i-1]:
return True
else:
return False
SPX['high_peak'] = peak(SPX['high'])
print(SPX)
And here's what came out:
open high low high_peak
time
2009/9/14 1040.15 1049.74 1035.00 False
2009/9/15 1049.03 1056.04 1043.42 False
2009/9/16 1053.99 1068.76 1052.87 False
2009/9/17 1067.87 1074.77 1061.20 False
2009/9/18 1066.60 1071.52 1064.27 False
... ... ... ...
2022/2/14 4412.61 4426.22 4364.84 False
2022/2/15 4429.28 4472.77 4429.28 False
2022/2/16 4455.75 4489.55 4429.68 False
2022/2/17 4456.06 4456.06 4373.81 False
2022/2/18 4384.57 4394.60 4327.22 False
[3132 rows x 4 columns]
As you can see, there's an error at the operation because the high price #2009/9/17 should have returned True at 'high_peak' column

Substring question on mips assembly language

Please help as soon as possible...
Write a MIPS assembly language program that prompts the user to input two strings (each should be no longer than 50 characters including the null terminator). Your program should determine whether the second string is a substring of the first. If it is, then your program should print out the first index in which the second string appears in the first. For example, if the first string is “Hello World” and the second string is “lo”, then the program should print out 3, i.e. the starting index of “lo” in “Hello World.” If the second string is not contained in the first string, then your program should print out -1.
To be able to understand what you have to implement at assembly level, the first thing you should do, is understanding the high-level algorithm. Why?
It's easier for you to see all the cases and edge-cases in time!
To look back at what have I been trying to do again? in the middle of programming the Assembly version.
To quickly see which variables you (certainly) need.
I wrote following program (forgive me, python has been a while for me):
def is_in_string_1(string, substring):
"""
aaba: a, b, ab, ba, aba (last one will fail)
"""
length = len(string)
sublength = len(substring)
if (sublength == 0):
return True
j = 0
for i in range(0, length):
if string[i] != substring[j]:
j = 0
else:
j += 1
if j == sublength:
return True
return False
def is_in_string_2(string, substring):
"""
aaba: a, b, ab, ba, aba
"""
length = len(string)
sublength = len(substring)
for i in range(0, length + 1 - sublength): # string: aabc; substring: c; length: 4; sublength: 1; indexes: 0,1,2,3;
is_substring = True
for j in range(0, sublength): # for the sake of the algorithm, no slicing here
if string[i+j] != substring[j]:
is_substring = False
break
if is_substring:
return True
return False
stringTuples = [
("aaa", "aa"),
("aaa", "aaa"),
("aaa", "aab"),
("abc", "bc"),
("abc", "a"),
("abc", "abc"),
("aaa", ""),
("aaa", "b")
]
for stringTuple in stringTuples:
print(
stringTuple[0],
stringTuple[1],
':',
is_in_string_1(stringTuple[0], stringTuple[1]),
is_in_string_2(stringTuple[0], stringTuple[1]),
sep='\t'
)
I first thought I could optimize the standard solution (is_in_string_2), leaving out the second for-loop (is_in_string_1), but after some thinking I already found out it would fail (the edge-case wasn't even in any of my test-data!) - so I left it as an example for how important it is that you use a correct algorithm.
The program produces the following output:
aaa aa : True True
aaa aaa : True True
aaa aab : False False
abc bc : True True
abc a : True True
abc abc : True True
aaa : True True
aaa b : False False
aaba aba : False True
Notice how all output was correct, except for the last line, where the first algorithm is wrong.
Before you continue:
You have to make your own len() function in MIPS; note that all string are (if I remember correctly) null terminated, so you'll have to count all non-null characters of a string, or in other words, count how many characters precede the null-terminator.
You should use j, $ra and jr calls to go to a "function" or subroutines. (Search)
While in one, you can call other functions using the stack. (Search)

Creating Html table using perl

I have a hash in perl whose keys are domain names and value is reference to array of blacklisted zones in which the domain is blacklisted.Currently I am checking the domain against 4 zones.If the domain is blacklisted in the particular zone the I push the zone names in the array.
domain1=>(zone1,zone2)
domain2=>(zone1)
domain3=>(zone3,zone4)
domain4=>(zone1,zone2,zone3,zone4)
I want to create a HTML table from these values in CGI like
domain-names zone1 zone2 zone3 zone4
domain1 true true false false
domain2 true false false false
domain3 false false true true
domain4 true true true true
I tried it using map in CGI like
print $q->tbody($q->Tr([
$q->td([
map {
map{
$_
}'$_',#{$result{$_}}
}keys %result
])
)
I am unable to the desired output.I am not sure of using if-else in map.
If I manually generate the td's Then I need to write a separate td's for each condition like
If(zone1&&zone2&&!zone3&&!zone4){
print "<td>true</td><td>true</td><td><false/td><td>false</td>";
}
......
It is very tedious.How can I get that output?
Convert your Hash of Arrays to a Hash of Hashes. This makes it easier to test for existence of a particular zone.
The following demonstrates and then displays the data in a simple text table:
use strict;
use warnings;
# Your Hash of Arrays
my %HoA = (
domain1 => [qw(zone1 zone2)],
domain2 => [qw(zone1)],
domain3 => [qw(zone3 zone4)],
domain4 => [qw(zone1 zone2 zone3 zone4)],
);
# Convert to a Hash of hashes - for easier testing of existance
my %HoH;
$HoH{$_} = { map { $_ => 1 } #{ $HoA{$_} } } for keys %HoA;
# Format and Zone List
my $fmt = "%-15s %-8s %-8s %-8s %-8s\n";
my #zones = qw(zone1 zone2 zone3 zone4);
printf $fmt, 'domain-names', #zones; # Header
for my $domain ( sort keys %HoH ) {
printf $fmt, $domain, map { $HoH{$domain}{$_} ? 'true' : 'false' } #zones;
}
Outputs:
domain-names zone1 zone2 zone3 zone4
domain1 true true false false
domain2 true false false false
domain3 false false true true
domain4 true true true true

JSON RFC 4627: whats the meaning of "false = %x66.61.6c.73.65 ; false"

I'm reading RFC 4627 (http://www.ietf.org/rfc/rfc4627.txt). In para 2.1, It talks about three literal names true, false, null.
false = %x66.61.6c.73.65 ; false
null = %x6e.75.6c.6c ; null
true = %x74.72.75.65 ; true
I am totally lost here. Does anyone know what %x66.61.6c.73.65 mean?
Thanks.
They're the bytes used for those words. In short, the text is to be encoded in ASCII (or the equivalent) and no other encoding.
>>> print '\x66\x61\x6c\x73\x65'
false
at first sight these seem to be the ascii codes for the letters :
false = "f"+"a"+"l"+"s"+"e" eg : char(0x65)+char(0x61)+char(0x6c)+char(0x73)+char(0x65)