瀏覽代碼

HackStudio: Mark compilation-unit-only functions as static

This also resolves some typing issues that only 'accidentally' worked, like declaring
a function to return type A, and the definition actually returning type B (which works
if type B is a subtype of type A). I like to call these "ninja imports".

To prevent problems like this in the future, I put all globals in a HackStudio.h.
I'm not sure about the name, but main.h and common.h felt wrong.
Ben Wiederhake 4 年之前
父節點
當前提交
7893871d5a

+ 1 - 1
DevTools/HackStudio/Debugger/VariablesModel.cpp

@@ -68,7 +68,7 @@ int VariablesModel::row_count(const GUI::ModelIndex& index) const
     return node->members.size();
 }
 
-String variable_value_as_string(const DebugInfo::VariableInfo& variable)
+static String variable_value_as_string(const DebugInfo::VariableInfo& variable)
 {
     if (variable.location_type != DebugInfo::VariableInfo::LocationType::Address)
         return "N/A";

+ 2 - 4
DevTools/HackStudio/EditorWrapper.cpp

@@ -26,15 +26,13 @@
 
 #include "EditorWrapper.h"
 #include "Editor.h"
+#include "HackStudio.h"
 #include <LibGUI/Action.h>
 #include <LibGUI/BoxLayout.h>
 #include <LibGUI/InputBox.h>
 #include <LibGUI/Label.h>
 #include <LibGfx/Font.h>
 
-extern RefPtr<EditorWrapper> g_current_editor_wrapper;
-extern Function<void(String)> g_open_file;
-
 EditorWrapper::EditorWrapper(BreakpointChangeCallback breakpoint_change_callback)
 {
     set_layout<GUI::VerticalBoxLayout>();
@@ -69,7 +67,7 @@ EditorWrapper::EditorWrapper(BreakpointChangeCallback breakpoint_change_callback
         g_current_editor_wrapper = this;
     };
 
-    m_editor->on_open = [this](String path) {
+    m_editor->on_open = [](String path) {
         g_open_file(path);
     };
 

+ 1 - 4
DevTools/HackStudio/FindInFilesWidget.cpp

@@ -25,6 +25,7 @@
  */
 
 #include "FindInFilesWidget.h"
+#include "HackStudio.h"
 #include "Project.h"
 #include <AK/StringBuilder.h>
 #include <LibGUI/BoxLayout.h>
@@ -32,10 +33,6 @@
 #include <LibGUI/TableView.h>
 #include <LibGUI/TextBox.h>
 
-extern GUI::TextEditor& current_editor();
-extern void open_file(const String&);
-extern OwnPtr<Project> g_project;
-
 struct Match {
     String filename;
     GUI::TextRange range;

+ 40 - 0
DevTools/HackStudio/HackStudio.h

@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2020, the SerenityOS developers.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ *    list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "EditorWrapper.h"
+#include "Project.h"
+#include <AK/String.h>
+#include <LibGUI/TextEditor.h>
+
+GUI::TextEditor& current_editor();
+void open_file(const String&);
+
+extern RefPtr<EditorWrapper> g_current_editor_wrapper;
+extern Function<void(String)> g_open_file;
+extern OwnPtr<Project> g_project;
+extern String g_currently_open_file;

+ 1 - 2
DevTools/HackStudio/Locator.cpp

@@ -25,14 +25,13 @@
  */
 
 #include "Locator.h"
+#include "HackStudio.h"
 #include "Project.h"
 #include <LibGUI/BoxLayout.h>
 #include <LibGUI/TableView.h>
 #include <LibGUI/TextBox.h>
 #include <LibGUI/Window.h>
 
-extern RefPtr<Project> g_project;
-extern void open_file(const String&);
 static RefPtr<Gfx::Bitmap> s_file_icon;
 static RefPtr<Gfx::Bitmap> s_cplusplus_icon;
 static RefPtr<Gfx::Bitmap> s_header_icon;

+ 1 - 1
DevTools/HackStudio/Project.cpp

@@ -25,6 +25,7 @@
  */
 
 #include "Project.h"
+#include "HackStudio.h"
 #include <AK/LexicalPath.h>
 #include <AK/QuickSort.h>
 #include <AK/StringBuilder.h>
@@ -117,7 +118,6 @@ public:
             return m_project.m_file_icon;
         }
         if (role == Role::Font) {
-            extern String g_currently_open_file;
             if (node->name == g_currently_open_file)
                 return Gfx::Font::default_bold_font();
             return {};

+ 7 - 6
DevTools/HackStudio/main.cpp

@@ -32,6 +32,7 @@
 #include "FindInFilesWidget.h"
 #include "FormEditorWidget.h"
 #include "FormWidget.h"
+#include "HackStudio.h"
 #include "Locator.h"
 #include "Project.h"
 #include "TerminalWrapper.h"
@@ -91,7 +92,7 @@ RefPtr<FormEditorWidget> g_form_editor_widget;
 
 static RefPtr<GUI::TabWidget> s_action_tab_widget;
 
-void add_new_editor(GUI::Widget& parent)
+static void add_new_editor(GUI::Widget& parent)
 {
     auto wrapper = EditorWrapper::construct(Debugger::on_breakpoint_change);
     if (s_action_tab_widget) {
@@ -109,7 +110,7 @@ enum class EditMode {
     Form,
 };
 
-void set_edit_mode(EditMode mode)
+static void set_edit_mode(EditMode mode)
 {
     if (mode == EditMode::Text) {
         g_right_hand_stack->set_active_widget(g_text_inner_splitter);
@@ -118,18 +119,18 @@ void set_edit_mode(EditMode mode)
     }
 }
 
-EditorWrapper& current_editor_wrapper()
+static EditorWrapper& current_editor_wrapper()
 {
     ASSERT(g_current_editor_wrapper);
     return *g_current_editor_wrapper;
 }
 
-Editor& current_editor()
+GUI::TextEditor& current_editor()
 {
     return current_editor_wrapper().editor();
 }
 
-NonnullRefPtr<EditorWrapper> get_editor_of_file(const String& file)
+static NonnullRefPtr<EditorWrapper> get_editor_of_file(const String& file)
 {
     for (auto& wrapper : g_all_editor_wrappers) {
         String wrapper_file = wrapper.filename_label().text();
@@ -140,7 +141,7 @@ NonnullRefPtr<EditorWrapper> get_editor_of_file(const String& file)
     ASSERT_NOT_REACHED();
 }
 
-String get_project_executable_path()
+static String get_project_executable_path()
 {
     // e.g /my/project.hackstudio => /my/project
     // TODO: Perhaps a Makefile rule for getting the value of $(PROGRAM) would be better?