summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/renderer.nim13
-rw-r--r--nimdoc/testproject/expected/testproject.html47
-rw-r--r--nimdoc/testproject/expected/theindex.html16
-rw-r--r--nimdoc/testproject/testproject.nim7
4 files changed, 77 insertions, 6 deletions
diff --git a/compiler/renderer.nim b/compiler/renderer.nim
index a92ce999f..54090d844 100644
--- a/compiler/renderer.nim
+++ b/compiler/renderer.nim
@@ -314,6 +314,7 @@ proc litAux(g: TSrcGen; n: PNode, x: BiggestInt, size: int): string =
     while result != nil and result.kind in {tyGenericInst, tyRange, tyVar, tyLent, tyDistinct,
                           tyOrdinal, tyAlias, tySink}:
       result = lastSon(result)
+
   let typ = n.typ.skip
   if typ != nil and typ.kind in {tyBool, tyEnum}:
     if sfPure in typ.sym.flags:
@@ -324,11 +325,13 @@ proc litAux(g: TSrcGen; n: PNode, x: BiggestInt, size: int): string =
       if e.sym.position == x:
         result &= e.sym.name.s
         return
-
-  let y = x and ((1 shl (size*8)) - 1)
-  if nfBase2 in n.flags: result = "0b" & toBin(y, size * 8)
-  elif nfBase8 in n.flags: result = "0o" & toOct(y, size * 3)
-  elif nfBase16 in n.flags: result = "0x" & toHex(y, size * 2)
+  
+  if nfBase2 in n.flags: result = "0b" & toBin(x, size * 8)
+  elif nfBase8 in n.flags:
+    var y = if size < sizeof(BiggestInt): x and ((1 shl (size*8)) - 1)
+            else: x
+    result = "0o" & toOct(y, size * 3)
+  elif nfBase16 in n.flags: result = "0x" & toHex(x, size * 2)
   else: result = $x
 
 proc ulitAux(g: TSrcGen; n: PNode, x: BiggestInt, size: int): string =
diff --git a/nimdoc/testproject/expected/testproject.html b/nimdoc/testproject/expected/testproject.html
index 273defbbf..8c9082d7a 100644
--- a/nimdoc/testproject/expected/testproject.html
+++ b/nimdoc/testproject/expected/testproject.html
@@ -850,6 +850,20 @@ function main() {
   </ul>
 </li>
 <li>
+  <a class="reference reference-toplevel" href="#10" id="60">Consts</a>
+  <ul class="simple simple-toc-section">
+      <li><a class="reference" href="#C_A"
+    title="C_A = 0x7FF0000000000000&apos;f64"><wbr />C_<wbr />A<span class="attachedType"></span></a></li>
+  <li><a class="reference" href="#C_B"
+    title="C_B = 0o377&apos;i8"><wbr />C_<wbr />B<span class="attachedType"></span></a></li>
+  <li><a class="reference" href="#C_C"
+    title="C_C = 0o277&apos;i8"><wbr />C_<wbr />C<span class="attachedType"></span></a></li>
+  <li><a class="reference" href="#C_D"
+    title="C_D = 0o177777&apos;i16"><wbr />C_<wbr />D<span class="attachedType"></span></a></li>
+
+  </ul>
+</li>
+<li>
   <a class="reference reference-toplevel" href="#12" id="62">Procs</a>
   <ul class="simple simple-toc-section">
       <li><a class="reference" href="#bar%2CT%2CT"
@@ -941,6 +955,39 @@ The enum B.
 </dd>
 
 </dl></div>
+<div class="section" id="10">
+<h1><a class="toc-backref" href="#10">Consts</a></h1>
+<dl class="item">
+<a id="C_A"></a>
+<dt><pre><a href="testproject.html#C_A"><span class="Identifier">C_A</span></a> <span class="Other">=</span> <span class="FloatNumber">0x7FF0000000000000'f64</span></pre></dt>
+<dd>
+
+
+
+</dd>
+<a id="C_B"></a>
+<dt><pre><a href="testproject.html#C_B"><span class="Identifier">C_B</span></a> <span class="Other">=</span> <span class="DecNumber">0o377'i8</span></pre></dt>
+<dd>
+
+
+
+</dd>
+<a id="C_C"></a>
+<dt><pre><a href="testproject.html#C_C"><span class="Identifier">C_C</span></a> <span class="Other">=</span> <span class="DecNumber">0o277'i8</span></pre></dt>
+<dd>
+
+
+
+</dd>
+<a id="C_D"></a>
+<dt><pre><a href="testproject.html#C_D"><span class="Identifier">C_D</span></a> <span class="Other">=</span> <span class="DecNumber">0o177777'i16</span></pre></dt>
+<dd>
+
+
+
+</dd>
+
+</dl></div>
 <div class="section" id="12">
 <h1><a class="toc-backref" href="#12">Procs</a></h1>
 <dl class="item">
diff --git a/nimdoc/testproject/expected/theindex.html b/nimdoc/testproject/expected/theindex.html
index f97ea54b9..5b7cefced 100644
--- a/nimdoc/testproject/expected/theindex.html
+++ b/nimdoc/testproject/expected/theindex.html
@@ -840,6 +840,22 @@ function main() {
 <li><a class="reference external"
           data-doc-search-tag="testproject: buzz[T](a, b: T): T" href="testproject.html#buzz%2CT%2CT">testproject: buzz[T](a, b: T): T</a></li>
           </ul></dd>
+<dt><a name="C_A" href="#C_A"><span>C_A:</span></a></dt><dd><ul class="simple">
+<li><a class="reference external"
+          data-doc-search-tag="testproject: C_A" href="testproject.html#C_A">testproject: C_A</a></li>
+          </ul></dd>
+<dt><a name="C_B" href="#C_B"><span>C_B:</span></a></dt><dd><ul class="simple">
+<li><a class="reference external"
+          data-doc-search-tag="testproject: C_B" href="testproject.html#C_B">testproject: C_B</a></li>
+          </ul></dd>
+<dt><a name="C_C" href="#C_C"><span>C_C:</span></a></dt><dd><ul class="simple">
+<li><a class="reference external"
+          data-doc-search-tag="testproject: C_C" href="testproject.html#C_C">testproject: C_C</a></li>
+          </ul></dd>
+<dt><a name="C_D" href="#C_D"><span>C_D:</span></a></dt><dd><ul class="simple">
+<li><a class="reference external"
+          data-doc-search-tag="testproject: C_D" href="testproject.html#C_D">testproject: C_D</a></li>
+          </ul></dd>
 <dt><a name="enumValueA" href="#enumValueA"><span>enumValueA:</span></a></dt><dd><ul class="simple">
 <li><a class="reference external"
           data-doc-search-tag="SomeType.enumValueA" href="subdir/subdir_b/utils.html#enumValueA">SomeType.enumValueA</a></li>
diff --git a/nimdoc/testproject/testproject.nim b/nimdoc/testproject/testproject.nim
index c3ab6a153..d1fcf58cd 100644
--- a/nimdoc/testproject/testproject.nim
+++ b/nimdoc/testproject/testproject.nim
@@ -9,6 +9,11 @@ runnableExamples:
   # bug #11078
   for x in "xx": discard
 
+const
+  C_A* = 0x7FF0000000000000'f64
+  C_B* = 0o377'i8
+  C_C* = 0o277'i8
+  C_D* = 0o177777'i16
 
 template foo*(a, b: SomeType) =
   ## This does nothing
@@ -31,7 +36,7 @@ import std/macros
 macro bar*(): untyped =
   result = newStmtList()
 
-var aVariable*: array[1,int]
+var aVariable*: array[1, int]
 
 aEnum()
 bEnum()
id='n248' href='#n248'>248 249 250


          
                                                            

































































                                                                                







                                               
                                                                            

                                                                                                      


                                                             

                                                                       














































































































































                                                                               
                                                       



















                                                             
/*
 * c_api.c
 *
 * Copyright (C) 2012 - 2016 James Booth <boothj5@gmail.com>
 *
 * This file is part of Profanity.
 *
 * Profanity is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Profanity is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Profanity.  If not, see <http://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give permission to
 * link the code of portions of this program with the OpenSSL library under
 * certain conditions as described in each individual source file, and
 * distribute linked combinations including the two.
 *
 * You must obey the GNU General Public License in all respects for all of the
 * code used other than OpenSSL. If you modify file(s) with this exception, you
 * may extend this exception to your version of the file(s), but you are not
 * obligated to do so. If you do not wish to do so, delete this exception
 * statement from your version. If you delete this exception statement from all
 * source files in the program, then also delete it here.
 *
 */

#include <stdlib.h>
#include <glib.h>

#include "log.h"
#include "plugins/api.h"
#include "plugins/c_api.h"
#include "plugins/callbacks.h"
#include "plugins/profapi.h"

typedef struct command_wrapper_t {
    void(*func)(char **args);
} CommandWrapper;

typedef struct timed_wrapper_t {
    void(*func)(void);
} TimedWrapper;

typedef struct window_wrapper_t {
    void(*func)(char *tag, char *line);
} WindowWrapper;

static void
c_api_cons_alert(void)
{
    api_cons_alert();
}

static void
c_api_cons_show(const char * const message)
{
    if (message) {
        api_cons_show(message);
    }
}

static void
c_api_cons_bad_cmd_usage(const char *const cmd)
{
    if (cmd) {
        api_cons_bad_cmd_usage(cmd);
    }
}

static void
c_api_register_command(const char *command_name, int min_args, int max_args,
    const char **synopsis, const char *description, const char *arguments[][2], const char **examples,
    void(*callback)(char **args))
{
    CommandWrapper *wrapper = malloc(sizeof(CommandWrapper));
    wrapper->func = callback;
    api_register_command(command_name, min_args, max_args, synopsis,
        description, arguments, examples, wrapper, c_command_callback);
}

static void
c_api_register_timed(void(*callback)(void), int interval_seconds)
{
    TimedWrapper *wrapper = malloc(sizeof(TimedWrapper));
    wrapper->func = callback;
    api_register_timed(wrapper, interval_seconds, c_timed_callback);
}

static void
c_api_register_ac(const char *key, char **items)
{
    api_register_ac(key, items);
}

static void
c_api_notify(const char *message, int timeout_ms, const char *category)
{
    api_notify(message, category, timeout_ms);
}

static void
c_api_send_line(char *line)
{
    api_send_line(line);
}

static char *
c_api_get_current_recipient(void)
{
    return api_get_current_recipient();
}

static char *
c_api_get_current_muc(void)
{
    return api_get_current_muc();
}

static void
c_api_log_debug(const char *message)
{
    api_log_debug(message);
}

static void
c_api_log_info(const char *message)
{
    api_log_info(message);
}

static void
c_api_log_warning(const char *message)
{
    api_log_warning(message);
}

static void
c_api_log_error(const char *message)
{
    api_log_error(message);
}

int
c_api_win_exists(char *tag)
{
    return api_win_exists(tag);
}

void
c_api_win_create(char *tag, void(*callback)(char *tag, char *line))
{
    WindowWrapper *wrapper = malloc(sizeof(WindowWrapper));
    wrapper->func = callback;
    api_win_create(tag, wrapper, c_window_callback);
}

void
c_api_win_focus(char *tag)
{
    api_win_focus(tag);
}

void
c_api_win_show(char *tag, char *line)
{
    api_win_show(tag, line);
}

void
c_api_win_show_green(char *tag, char *line)
{
    api_win_show_green(tag, line);
}

void
c_api_win_show_red(char *tag, char *line)
{
    api_win_show_red(tag, line);
}

void
c_api_win_show_cyan(char *tag, char *line)
{
    api_win_show_cyan(tag, line);
}

void
c_api_win_show_yellow(char *tag, char *line)
{
    api_win_show_yellow(tag, line);
}

void
c_command_callback(PluginCommand *command, gchar **args)
{
    CommandWrapper *wrapper = command->callback;
    void(*f)(gchar **args) = wrapper->func;
    f(args);
}

void
c_timed_callback(PluginTimedFunction *timed_function)
{
    TimedWrapper *wrapper = timed_function->callback;
    void(*f)(void) = wrapper->func;
    f();
}

void
c_window_callback(PluginWindowCallback *window_callback, char *tag, char *line)
{
    WindowWrapper *wrapper = window_callback->callback;
    void(*f)(char *tag, char *line) = wrapper->func;
    f(tag, line);
}

void
c_api_init(void)
{
    prof_cons_alert = c_api_cons_alert;
    prof_cons_show = c_api_cons_show;
    prof_cons_bad_cmd_usage = c_api_cons_bad_cmd_usage;
    prof_register_command = c_api_register_command;
    prof_register_timed = c_api_register_timed;
    prof_register_ac = c_api_register_ac;
    prof_notify = c_api_notify;
    prof_send_line = c_api_send_line;
    prof_get_current_recipient = c_api_get_current_recipient;
    prof_get_current_muc = c_api_get_current_muc;
    prof_log_debug = c_api_log_debug;
    prof_log_info = c_api_log_info;
    prof_log_warning = c_api_log_warning;
    prof_log_error = c_api_log_error;
    prof_win_exists = c_api_win_exists;
    prof_win_create = c_api_win_create;
    prof_win_focus = c_api_win_focus;
    prof_win_show = c_api_win_show;
    prof_win_show_green = c_api_win_show_green;
    prof_win_show_red = c_api_win_show_red;
    prof_win_show_cyan = c_api_win_show_cyan;
    prof_win_show_yellow = c_api_win_show_yellow;
}