*** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style. This kind of mass change has
*** two obvious implications:
Firstly, merging this particular commit into a downstream fork may be a huge
effort. Alternatively, it may be worth merging all changes up to this commit,
performing the same reformatting operation locally, and then discarding the
merge for this particular commit. The commands used to accomplish this
reformatting were as follows (with current working directory as the root of
the repository):
find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} +
find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ;
The version of clang-format used was 3.9.0, and autopep8 was 1.2.4.
Secondly, “blame” style tools will generally point to this commit instead of
a meaningful prior commit. There are alternatives available that will attempt
to look through this change and find the appropriate prior commit. YMMV.
llvm-svn: 280751
diff --git a/lldb/examples/scripting/dictionary.c b/lldb/examples/scripting/dictionary.c
index a7e1390..260eab4 100644
--- a/lldb/examples/scripting/dictionary.c
+++ b/lldb/examples/scripting/dictionary.c
@@ -6,13 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===---------------------------------------------------------------------===//
-#include <stdlib.h>
-#include <stdio.h>
#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-typedef struct tree_node
-{
+typedef struct tree_node {
const char *word;
struct tree_node *left;
struct tree_node *right;
@@ -22,22 +21,20 @@
alphabet character and ends at the last alphabet character, i.e. it
strips off beginning or ending quotes, punctuation, etc. */
-char *
-strip (char **word)
-{
+char *strip(char **word) {
char *start = *word;
- int len = strlen (start);
+ int len = strlen(start);
char *end = start + len - 1;
- while ((start < end) && (!isalpha (start[0])))
+ while ((start < end) && (!isalpha(start[0])))
start++;
- while ((end > start) && (!isalpha (end[0])))
+ while ((end > start) && (!isalpha(end[0])))
end--;
if (start > end)
return NULL;
-
+
end[1] = '\0';
*word = start;
@@ -48,116 +45,95 @@
each node), and a new word, inserts the word at the appropriate
place in the tree. */
-void
-insert (tree_node *root, char *word)
-{
+void insert(tree_node *root, char *word) {
if (root == NULL)
return;
- int compare_value = strcmp (word, root->word);
+ int compare_value = strcmp(word, root->word);
if (compare_value == 0)
return;
- if (compare_value < 0)
- {
- if (root->left != NULL)
- insert (root->left, word);
- else
- {
- tree_node *new_node = (tree_node *) malloc (sizeof (tree_node));
- new_node->word = strdup (word);
- new_node->left = NULL;
- new_node->right = NULL;
- root->left = new_node;
- }
+ if (compare_value < 0) {
+ if (root->left != NULL)
+ insert(root->left, word);
+ else {
+ tree_node *new_node = (tree_node *)malloc(sizeof(tree_node));
+ new_node->word = strdup(word);
+ new_node->left = NULL;
+ new_node->right = NULL;
+ root->left = new_node;
}
- else
- {
- if (root->right != NULL)
- insert (root->right, word);
- else
- {
- tree_node *new_node = (tree_node *) malloc (sizeof (tree_node));
- new_node->word = strdup (word);
- new_node->left = NULL;
- new_node->right = NULL;
- root->right = new_node;
- }
+ } else {
+ if (root->right != NULL)
+ insert(root->right, word);
+ else {
+ tree_node *new_node = (tree_node *)malloc(sizeof(tree_node));
+ new_node->word = strdup(word);
+ new_node->left = NULL;
+ new_node->right = NULL;
+ root->right = new_node;
}
+ }
}
/* Read in a text file and storea all the words from the file in a
binary search tree. */
-void
-populate_dictionary (tree_node **dictionary, char *filename)
-{
+void populate_dictionary(tree_node **dictionary, char *filename) {
FILE *in_file;
char word[1024];
- in_file = fopen (filename, "r");
- if (in_file)
- {
- while (fscanf (in_file, "%s", word) == 1)
- {
- char *new_word = (strdup (word));
- new_word = strip (&new_word);
- if (*dictionary == NULL)
- {
- tree_node *new_node = (tree_node *) malloc (sizeof (tree_node));
- new_node->word = new_word;
- new_node->left = NULL;
- new_node->right = NULL;
- *dictionary = new_node;
- }
- else
- insert (*dictionary, new_word);
- }
+ in_file = fopen(filename, "r");
+ if (in_file) {
+ while (fscanf(in_file, "%s", word) == 1) {
+ char *new_word = (strdup(word));
+ new_word = strip(&new_word);
+ if (*dictionary == NULL) {
+ tree_node *new_node = (tree_node *)malloc(sizeof(tree_node));
+ new_node->word = new_word;
+ new_node->left = NULL;
+ new_node->right = NULL;
+ *dictionary = new_node;
+ } else
+ insert(*dictionary, new_word);
}
+ }
}
/* Given a binary search tree and a word, search for the word
in the binary search tree. */
-int
-find_word (tree_node *dictionary, char *word)
-{
+int find_word(tree_node *dictionary, char *word) {
if (!word || !dictionary)
return 0;
- int compare_value = strcmp (word, dictionary->word);
+ int compare_value = strcmp(word, dictionary->word);
if (compare_value == 0)
return 1;
else if (compare_value < 0)
- return find_word (dictionary->left, word);
+ return find_word(dictionary->left, word);
else
- return find_word (dictionary->right, word);
+ return find_word(dictionary->right, word);
}
/* Print out the words in the binary search tree, in sorted order. */
-void
-print_tree (tree_node *dictionary)
-{
+void print_tree(tree_node *dictionary) {
if (!dictionary)
return;
if (dictionary->left)
- print_tree (dictionary->left);
+ print_tree(dictionary->left);
- printf ("%s\n", dictionary->word);
-
+ printf("%s\n", dictionary->word);
if (dictionary->right)
- print_tree (dictionary->right);
+ print_tree(dictionary->right);
}
-
-int
-main (int argc, char **argv)
-{
+int main(int argc, char **argv) {
tree_node *dictionary = NULL;
char buffer[1024];
char *filename;
@@ -169,32 +145,29 @@
if (!filename)
return -1;
- populate_dictionary (&dictionary, filename);
- fprintf (stdout, "Dictionary loaded.\nEnter search word: ");
- while (!done && fgets (buffer, sizeof(buffer), stdin))
- {
- char *word = buffer;
- int len = strlen (word);
- int i;
+ populate_dictionary(&dictionary, filename);
+ fprintf(stdout, "Dictionary loaded.\nEnter search word: ");
+ while (!done && fgets(buffer, sizeof(buffer), stdin)) {
+ char *word = buffer;
+ int len = strlen(word);
+ int i;
- for (i = 0; i < len; ++i)
- word[i] = tolower (word[i]);
+ for (i = 0; i < len; ++i)
+ word[i] = tolower(word[i]);
- if ((len > 0) && (word[len-1] == '\n'))
- {
- word[len-1] = '\0';
- len = len - 1;
- }
-
- if (find_word (dictionary, word))
- fprintf (stdout, "Yes!\n");
- else
- fprintf (stdout, "No!\n");
-
- fprintf (stdout, "Enter search word: ");
+ if ((len > 0) && (word[len - 1] == '\n')) {
+ word[len - 1] = '\0';
+ len = len - 1;
}
-
- fprintf (stdout, "\n");
+
+ if (find_word(dictionary, word))
+ fprintf(stdout, "Yes!\n");
+ else
+ fprintf(stdout, "No!\n");
+
+ fprintf(stdout, "Enter search word: ");
+ }
+
+ fprintf(stdout, "\n");
return 0;
}
-
diff --git a/lldb/examples/scripting/tree_utils.py b/lldb/examples/scripting/tree_utils.py
index e83f516..a4d1645 100755
--- a/lldb/examples/scripting/tree_utils.py
+++ b/lldb/examples/scripting/tree_utils.py
@@ -1,4 +1,4 @@
-"""
+"""
# ===-- tree_utils.py ---------------------------------------*- Python -*-===//
#
# The LLVM Compiler Infrastructure
@@ -9,7 +9,7 @@
# ===---------------------------------------------------------------------===//
tree_utils.py - A set of functions for examining binary
-search trees, based on the example search tree defined in
+search trees, based on the example search tree defined in
dictionary.c. These functions contain calls to LLDB API
functions, and assume that the LLDB Python module has been
imported.
@@ -20,7 +20,7 @@
"""
-def DFS (root, word, cur_path):
+def DFS(root, word, cur_path):
"""
Recursively traverse a binary search tree containing
words sorted alphabetically, searching for a particular
@@ -33,21 +33,21 @@
the one defined in dictionary.c It uses LLDB API
functions to examine and traverse the tree nodes.
"""
-
+
# Get pointer field values out of node 'root'
- root_word_ptr = root.GetChildMemberWithName ("word")
- left_child_ptr = root.GetChildMemberWithName ("left")
- right_child_ptr = root.GetChildMemberWithName ("right")
+ root_word_ptr = root.GetChildMemberWithName("word")
+ left_child_ptr = root.GetChildMemberWithName("left")
+ right_child_ptr = root.GetChildMemberWithName("right")
- # Get the word out of the word pointer and strip off
+ # Get the word out of the word pointer and strip off
# surrounding quotes (added by call to GetSummary).
root_word = root_word_ptr.GetSummary()
- end = len (root_word) - 1
+ end = len(root_word) - 1
if root_word[0] == '"' and root_word[end] == '"':
root_word = root_word[1:end]
- end = len (root_word) - 1
+ end = len(root_word) - 1
if root_word[0] == '\'' and root_word[end] == '\'':
root_word = root_word[1:end]
@@ -59,23 +59,23 @@
# Check to see if left child is NULL
- if left_child_ptr.GetValue() == None:
+ if left_child_ptr.GetValue() is None:
return ""
else:
cur_path = cur_path + "L"
- return DFS (left_child_ptr, word, cur_path)
+ return DFS(left_child_ptr, word, cur_path)
else:
# Check to see if right child is NULL
- if right_child_ptr.GetValue() == None:
+ if right_child_ptr.GetValue() is None:
return ""
else:
cur_path = cur_path + "R"
- return DFS (right_child_ptr, word, cur_path)
-
+ return DFS(right_child_ptr, word, cur_path)
-def tree_size (root):
+
+def tree_size(root):
"""
Recursively traverse a binary search tree, counting
the nodes in the tree. Returns the final count.
@@ -84,20 +84,20 @@
the one defined in dictionary.c It uses LLDB API
functions to examine and traverse the tree nodes.
"""
- if (root.GetValue == None):
+ if (root.GetValue is None):
return 0
- if (int (root.GetValue(), 16) == 0):
+ if (int(root.GetValue(), 16) == 0):
return 0
- left_size = tree_size (root.GetChildAtIndex(1));
- right_size = tree_size (root.GetChildAtIndex(2));
+ left_size = tree_size(root.GetChildAtIndex(1))
+ right_size = tree_size(root.GetChildAtIndex(2))
total_size = left_size + right_size + 1
return total_size
-
-def print_tree (root):
+
+def print_tree(root):
"""
Recursively traverse a binary search tree, printing out
the words at the nodes in alphabetical order (the
@@ -107,12 +107,12 @@
the one defined in dictionary.c It uses LLDB API
functions to examine and traverse the tree nodes.
"""
- if (root.GetChildAtIndex(1).GetValue() != None) and (int (root.GetChildAtIndex(1).GetValue(), 16) != 0):
- print_tree (root.GetChildAtIndex(1))
+ if (root.GetChildAtIndex(1).GetValue() is not None) and (
+ int(root.GetChildAtIndex(1).GetValue(), 16) != 0):
+ print_tree(root.GetChildAtIndex(1))
print root.GetChildAtIndex(0).GetSummary()
- if (root.GetChildAtIndex(2).GetValue() != None) and (int (root.GetChildAtIndex(2).GetValue(), 16) != 0):
- print_tree (root.GetChildAtIndex(2))
-
-
+ if (root.GetChildAtIndex(2).GetValue() is not None) and (
+ int(root.GetChildAtIndex(2).GetValue(), 16) != 0):
+ print_tree(root.GetChildAtIndex(2))