Skip to content

Commit

Permalink
style: Set DerivePointerAlignment: false in .clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas89901 committed Jan 28, 2024
1 parent 6417937 commit b577414
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
BasedOnStyle: Google
DerivePointerAlignment: false
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
Expand Down
10 changes: 5 additions & 5 deletions projects/06/assembler/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CInstruction : public Instruction {
assembly.push_back('=');
}

for (const auto &pair : kComputationCodes) {
for (const auto& pair : kComputationCodes) {
if (pair.second == computation_) {
absl::StrAppend(&assembly, pair.first);
break;
Expand All @@ -75,7 +75,7 @@ class CInstruction : public Instruction {
}

bool SetComputation(std::string_view computation_str) {
for (const auto &pair : kComputationCodes) {
for (const auto& pair : kComputationCodes) {
if (pair.first == computation_str) {
computation_ = pair.second;
return true;
Expand Down Expand Up @@ -143,7 +143,7 @@ bool IsNumber(std::string_view str) {
return true;
}

int main(int argc, char *argv[]) {
int main(int argc, char* argv[]) {
QCHECK_GE(argc, 2) << "Usage: " << argv[0] << " SOURCE";
std::ifstream asm_file(argv[1]);
QCHECK(asm_file.is_open()) << "Failed to open input file '" << argv[1] << "'";
Expand Down Expand Up @@ -175,7 +175,7 @@ int main(int argc, char *argv[]) {
{"R15", 15}, {"SCREEN", 16384}, {"KBD", 24576}, {"SP", 0}, {"LCL", 1},
{"ARG", 2}, {"THIS", 3}, {"THAT", 4}};
uint16_t instruction_counter = 0;
for (const std::string &line : trimmed_lines) {
for (const std::string& line : trimmed_lines) {
if (line.front() == '(' && line.back() == ')') { // Is label.
symbol_table[line.substr(1, line.size() - 2)] = instruction_counter;
} else {
Expand All @@ -191,7 +191,7 @@ int main(int argc, char *argv[]) {
LOG(INFO) << "Output: " << hack_path.string();

uint16_t variable_address = 16;
for (const std::string &line : trimmed_lines) {
for (const std::string& line : trimmed_lines) {
if (line.front() == '(' && line.back() == ')') { // Label
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions projects/08/vmtranslator/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "addressing.h"

std::ostream &operator<<(std::ostream &os, const Command &command) {
std::ostream& operator<<(std::ostream& os, const Command& command) {
return os << command.ToAssembly();
}

Expand Down Expand Up @@ -105,7 +105,7 @@ PopCommand::PopCommand(std::unique_ptr<Address> address)
: address_(std::move(address)) {}

std::string PopCommand::ToAssembly() const {
if (dynamic_cast<PointerAddressedAddress *>(address_.get())) {
if (dynamic_cast<PointerAddressedAddress*>(address_.get())) {
return absl::StrFormat(
"%s"
"@R15\n"
Expand Down
2 changes: 1 addition & 1 deletion projects/08/vmtranslator/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Command {
public:
virtual std::string ToAssembly() const = 0;
};
std::ostream &operator<<(std::ostream &os, const Command &command);
std::ostream& operator<<(std::ostream& os, const Command& command);

class BinaryArithmeticCommand : public Command {
public:
Expand Down
8 changes: 4 additions & 4 deletions projects/08/vmtranslator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ABSL_FLAG(bool, v, false, "verbose output, print assembly output to console");
ABSL_FLAG(bool, d, false,
"debug mode, write VM source lines as comments in assembly output");

void Translate(VmFile &vm_file, AssemblyFile &asm_file) {
void Translate(VmFile& vm_file, AssemblyFile& asm_file) {
LOG(INFO) << "Processing VM file: " << vm_file.path();
while (vm_file.command()) {
if (absl::GetFlag(FLAGS_v)) {
Expand All @@ -31,10 +31,10 @@ void Translate(VmFile &vm_file, AssemblyFile &asm_file) {
}
}

int main(int argc, char *argv[]) {
int main(int argc, char* argv[]) {
absl::SetProgramUsageMessage(
absl::StrFormat("Usage: %s [-d] [-v] SOURCE", argv[0]));
std::vector<char *> positional_args = absl::ParseCommandLine(argc, argv);
std::vector<char*> positional_args = absl::ParseCommandLine(argc, argv);
QCHECK_EQ(positional_args.size(), 2) << absl::ProgramUsageMessage();

std::filesystem::directory_entry source(positional_args[1]);
Expand Down Expand Up @@ -63,7 +63,7 @@ int main(int argc, char *argv[]) {
AssemblyFile asm_file(asm_path.string(), source.is_directory());
if (source.is_directory()) {
LOG(INFO) << "Multi-file source mode";
for (const std::filesystem::directory_entry &entry :
for (const std::filesystem::directory_entry& entry :
std::filesystem::directory_iterator(source)) {
if (entry.path().extension() == ".vm") {
VmFile vm_file(entry.path().string());
Expand Down
2 changes: 1 addition & 1 deletion projects/08/vmtranslator/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AssemblyFile {
~AssemblyFile();

template <class T>
AssemblyFile &operator<<(const T &value) {
AssemblyFile& operator<<(const T& value) {
file_ << value;
return *this;
}
Expand Down
2 changes: 1 addition & 1 deletion projects/08/vmtranslator/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ void VmFile::Advance() {
std::string VmFile::path() { return path_; }
std::string VmFile::line() { return line_; }
size_t VmFile::line_number() { return line_number_; }
Command *VmFile::command() { return command_; }
Command* VmFile::command() { return command_; }
4 changes: 2 additions & 2 deletions projects/08/vmtranslator/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class VmFile {
std::string path();
std::string line();
size_t line_number();
Command *command();
Command* command();

private:
std::unique_ptr<Address> ParseAddress(std::string_view segment,
Expand All @@ -29,7 +29,7 @@ class VmFile {
std::string line_;
size_t line_number_ = 0;
std::string function_;
Command *command_ = nullptr;
Command* command_ = nullptr;
};

#endif // NAND2TETRIS_VMTRANSLATOR_PARSER_H_

0 comments on commit b577414

Please sign in to comment.