From 4a7179ff9183cd27d036043c0bbcb01d1604d824 Mon Sep 17 00:00:00 2001 From: Samuel Reed Date: Wed, 20 Jan 2016 11:03:41 -0600 Subject: Simplify by skipping extra tree walk. --- lib/scope.js | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/lib/scope.js b/lib/scope.js index 144ae48e..794254d4 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -94,6 +94,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ var scope = self.parent_scope = null; var labels = new Dictionary(); var defun = null; + var last_var_had_const_pragma = false; var nesting = 0; var tw = new TreeWalker(function(node, descend){ if (options.screw_ie8 && node instanceof AST_Catch) { @@ -151,10 +152,13 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ // later. (node.scope = defun.parent_scope).def_function(node); } + else if (node instanceof AST_Var) { + last_var_had_const_pragma = node.has_const_pragma(); + } else if (node instanceof AST_SymbolVar || node instanceof AST_SymbolConst) { var def = defun.def_variable(node); - def.constant = node instanceof AST_SymbolConst || node.has_const_pragma(); + def.constant = node instanceof AST_SymbolConst || last_var_had_const_pragma; def.init = tw.parent().value; } else if (node instanceof AST_SymbolCatch) { @@ -357,33 +361,11 @@ AST_Symbol.DEFMETHOD("global", function(){ return this.definition().global; }); -AST_Symbol.DEFMETHOD("has_const_pragma", function() { - var symbol = this; - var symbol_has_pragma = false; - var pragma_found = false; - var found_symbol = false; - // Walk the current scope, looking for a comment with the @const pragma. - // If it exists, mark a bool that will remain true only for the next iteration. - // If the next iteration is this symbol, then we return true. - // Otherwise we stop descending and get out of here. - var tw = new TreeWalker(function(node, descend){ - // This is our symbol. Was the pragma before this? - if (node.name === symbol) { - found_symbol = true; - symbol_has_pragma = pragma_found; - } - - // Look for the /** @const */ pragma - var comments_before = node.start && node.start.comments_before; - var lastComment = comments_before && comments_before[comments_before.length - 1]; - pragma_found = lastComment && /@const/.test(lastComment.value); - - // no need to descend after finding our node - return found_symbol; - }); - this.scope.walk(tw); - return symbol_has_pragma; -}) +AST_Var.DEFMETHOD("has_const_pragma", function() { + var comments_before = this.start && this.start.comments_before; + var lastComment = comments_before && comments_before[comments_before.length - 1]; + return lastComment && /@const/.test(lastComment.value); +}); AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options){ return defaults(options, { -- cgit v1.2.3 ases' syntax. * gnu/packages/algebra.scm (arb)[arguments]: Likewise. * gnu/packages/apr.scm (apr-util)[arguments]: Likewise. * gnu/packages/audio.scm (clalsadrv, fluidsynth, faad2, lv2-mda-piano, lv2-mda-epiano, timidity++, vamp, soundtouch, portaudio, rsound, zita-convolver, zita-alsa-pcmi)[arguments]: Likewise. * gnu/packages/backup.scm (rdup, btar)[arguments]: Likewise. * gnu/packages/bioinformatics.scm (bedops, bwa, crossmap, express, flexbar, grit, hisat, ngs-sdk, subread)[arguments]: Likewise. * gnu/packages/bittorrent.scm (transmission)[arguments]: Likewise. * gnu/packages/cdrom.scm (cd-discid)[arguments]: Likewise. * gnu/packages/compression.scm (sharutils)[arguments]: Likewise. * gnu/packages/conky.scm (conky)[arguments]: Likewise. * gnu/packages/databases.scm (bdb, bdb-5.3)[arguments]: Likewise. * gnu/packages/debug.scm (delta, c-reduce)[arguments]: Likewise. * gnu/packages/display-managers.scm (slim)[arguments]: Likewise. * gnu/packages/dns.scm (dnsmasq)[arguments]: Likewise. * gnu/packages/emacs.scm (geiser, emacs-wget, bbdb)[arguments]: Likewise. * gnu/packages/engineering.scm (pcb)[arguments]: Likewise. * gnu/packages/firmware.scm (ath9k-htc-firmware)[arguments]: Likewise. * gnu/packages/flashing-tools.scm (flashrom)[arguments]: Likewise. * gnu/packages/fltk.scm (fltk)[arguments]: Likewise. * gnu/packages/freedesktop.scm (python-pyxdg)[arguments]: Likewise. * gnu/packages/gd.scm (perl-gd)[arguments]: Likewise. * gnu/packages/gkrellm.scm (gkrellm)[arguments]: Likewise. * gnu/packages/glib.scm (glibmm)[arguments]: Likewise. * gnu/packages/gl.scm (glew)[arguments]: Likewise. * gnu/packages/gnome.scm (icon-naming-utils, orbit2, libbonobo, gnome-vfs, libgnome, libbonoboui, goffice-0.8, dconf)[arguments]: Likewise. * gnu/packages/gprolog.scm (gprolog)[arguments]: Likewise. * gnu/packages/gps.scm (gpscorrelate)[arguments]: Likewise. * gnu/packages/graphics.scm (agg)[arguments]: Likewise. * gnu/packages/gtk.scm (ganv, girara, gtksourceview-2, guile-present, python2-pycairo)[arguments]: Likewise. * gnu/packages/guile.scm (guile-1.8)[arguments]: Likewise. * gnu/packages/guile-wm.scm (guile-wm)[arguments]: Likewise. * gnu/packages/hugs.scm (hugs)[arguments]: Likewise. * gnu/packages/hurd.scm (gnumach-headers, hurd-headers, hurd-minimal) [arguments]: Likewise. * gnu/packages/image-viewers.scm (feh, sxiv)[arguments]: Likewise. * gnu/packages/libcanberra.scm (libcanberra)[arguments]: Likewise. * gnu/packages/linux.scm (bridge-utils, iw, fuse, unionfs-fuse/static, lm-sensors, i2c-tools, xsensors, perf, mdadm, libaio, module-init-tools) [arguments]: Likewise. * gnu/packages/lisp.scm (ccl)[arguments]: Likewise. * gnu/packages/lout.scm (lout)[arguments]: Likewise. * gnu/packages/lua.scm (luajit)[arguments]: Likewise. * gnu/packages/machine-learning.scm (shogun)[arguments]: Likewise. * gnu/packages/mail.scm (exim)[arguments]: Likewise. * gnu/packages/man.scm (man-pages, txt2man)[arguments]: Likewise. * gnu/packages/maths.scm (lapack, superlu-dist, openlibm, openspecfun) [arguments]: Likewise. * gnu/packages/messaging.scm (bitlbee)[arguments]: Likewise. * gnu/packages/mp3.scm (libmad, id3lib, mp3info)[arguments]: Likewise. * gnu/packages/music.scm (solfege)[arguments]: Likewise. * gnu/packages/noweb.scm (noweb)[arguments]: Likewise. * gnu/packages/patchutils.scm (patchutils, quilt, colordiff)[arguments]: Likewise. * gnu/packages/pdf.scm (xpdf, zathura-cb, zathura-ps, zathura-djvu, zathura-pdf-poppler, zathura, podofo, fbida)[arguments]: Likewise. * gnu/packages/perl.scm (perl-file-list, perl-test-harness)[arguments]: Likewise. * gnu/packages/photo.scm (gphoto2)[arguments]: Likewise. * gnu/packages/popt.scm (popt)[arguments]: Likewise. * gnu/packages/pretty-print.scm (source-highlight, astyle)[arguments]: Likewise. * gnu/packages/pumpio.scm (pumpa)[arguments]: Likewise. * gnu/packages/python.scm (python-passlib, python-pycrypto, python2-empy, python-sqlalchemy, python-docopt)[arguments]: Likewise. * gnu/packages/rdf.scm (lrdf)[arguments]: Likewise. * gnu/packages/regex.scm (tre)[arguments]: Likewise. * gnu/packages/rrdtool.scm (rrdtool)[arguments]: Likewise. * gnu/packages/ruby.scm (ruby-2.1, ruby-1.8)[arguments]: Likewise. * gnu/packages/sawfish.scm (sawfish)[arguments]: Likewise. * gnu/packages/scheme.scm (racket)[arguments]: Likewise. * gnu/packages/sdl.scm (guile-sdl)[arguments]: Likewise. * gnu/packages/serveez.scm (serveez)[arguments]: Likewise. * gnu/packages/skribilo.scm (skribilo)[arguments]: Likewise. * gnu/packages/smalltalk.scm (smalltalk)[arguments]: Likewise. * gnu/packages/suckless.scm (dmenu, slock)[arguments]: Likewise. * gnu/packages/tcl.scm (expect)[arguments]: Likewise. * gnu/packages/telephony.scm (commoncpp)[arguments]: Likewise. * gnu/packages/textutils.scm (recode, libgtextutils)[arguments]: Likewise. * gnu/packages/time.scm (time)[arguments]: Likewise. * gnu/packages/tor.scm (privoxy)[arguments]: Likewise. * gnu/packages/uucp.scm (uucp)[arguments]: Likewise. * gnu/packages/video.scm (libdvdnav-4)[arguments]: Likewise. * gnu/packages/web-browsers.scm (lynx)[arguments]: Likewise. * gnu/packages/web.scm (tinyproxy)[arguments]: Likewise. * gnu/packages/wicd.scm (wicd)[arguments]: Likewise. * gnu/packages/wm.scm (bspwm)[arguments]: Likewise. * gnu/packages/xdisorg.scm (sxhkd, xcape)[arguments]: Likewise. * gnu/packages/xfce.scm (xfconf)[arguments]: Likewise. * gnu/packages/xfig.scm (transfig)[arguments]: Likewise. * gnu/packages/xorg.scm (imake)[arguments]: Likewise. Kei Kebreau 2017-09-04gnu: Put autoconf-related phases immediately after the 'unpack phase....* gnu/packages/audio.scm (audacity, rtmidi)[arguments]: Correct phases accordingly. * gnu/packages/bioinformatics.scm (mash, seek, vsearch, emboss, htslib-for-sambamba)[arguments]: Likewise. * gnu/packages/ci.scm (cuirass)[arguments]: Likewise. * gnu/packages/compression.scm (minizip, xdelta)[arguments]: Likewise. * gnu/packages/cpp.scm (libzen)[arguments]: Likewise. * gnu/packages/crypto.scm (opendht)[arguments]: Likewise. * gnu/packages/databases.scm (4store, mdbtools)[arguments]: Likewise. * gnu/packages/debug.scm (stress-make)[arguments]: Likewise. * gnu/packages/dns.scm (dnscrypt-proxy, dnscrypt-wrapper)[arguments]: Likewise. * gnu/packages/emacs.scm (emacs-pdf-tools)[arguments]: Likewise. * gnu/packages/embedded.scm (libjaylink, openocd)[arguments]: Likewise. * gnu/packages/engineering.scm (gerbv)[arguments]: Likewise. * gnu/packages/erlang.scm (erlang)[arguments]: Likewise. * gnu/packages/ftp.scm (weex)[arguments]: Likewise. * gnu/packages/gnome.scm (dia)[arguments]: Likewise. * gnu/packages/gnunet.scm (gnurl, guile-gnunet)[arguments]: Likewise. * gnu/packages/gtk.scm (guile-rsvg, graphene)[arguments]: Likewise. * gnu/packages/guile.scm (guildhall, guile-ics, guile-sqlite3)[arguments]: Likewise. * gnu/packages/ibus.scm (ibus-libpinyin)[arguments]: Likewise. * gnu/packages/irc.scm (weechat)[arguments]: Likewise. * gnu/packages/java.scm (classpath-devel)[arguments]: Likewise. * gnu/packages/libreoffice.scm (libetonyek)[arguments]: Likewise. * gnu/packages/libusb.scm (hidapi)[arguments]: Likewise. * gnu/packages/linux.scm (gpm)[arguments]: Likewise. * gnu/packages/logging.scm (glog)[arguments]: Likewise. * gnu/packages/machine-learning.scm (ghmm)[arguments]: Likewise. * gnu/packages/mail.scm (dovecot-trees, dovecot-libsodium-plugin, esmtp) [arguments]: Likewise. * gnu/packages/messaging.scm (freetalk, libmesode, libstrophe)[arguments]: Likewise. * gnu/packages/microcom.scm (microcom)[arguments]: Likewise. * gnu/packages/ocaml.scm (ocaml-ssl)[arguments]: Likewise. * gnu/packages/parallel.scm (slurm)[arguments]: Likewise. * gnu/packages/pdf.scm (libharu)[arguments]: Likewise. * gnu/packages/samba.scm (cifs-utils)[arguments]: Likewise. * gnu/packages/serialization.scm (msgpack)[arguments]: Likewise. * gnu/packages/shells.scm (scsh)[arguments]: Likewise. * gnu/packages/telephony.scm (libiax2)[arguments]: Likewise. * gnu/packages/textutils.scm (dotconf)[arguments]: Likewise. * gnu/packages/version-control.scm (findnewest)[arguments]: Likewise. * gnu/packages/video.scm (libmediainfo, mediainfo)[arguments]: Likewise. Kei Kebreau 2017-08-17gnu: american-fuzzy-lop: Update to 2.49b....* gnu/packages/debug.scm (american-fuzzy-lop): Update to 2.49b. Efraim Flashner 2017-08-17gnu: american-fuzzy-lop: Add support for non-Intel architectures....* gnu/packages/debug.scm (americal-fuzzy-lop): Add qemu target for non-Intel targets. [arguments]: On non-Intel systems, add phase to disable non-Intel architecture warning and remove incompatible binaries. Efraim Flashner 2017-08-09gnu: stress-make: Patch default shell....* gnu/packages/debug.scm (stress-make)[arguments]: Add 'set-default-shell phase. Eric Bavier 2017-07-15gnu: Rename (gnu packages qemu) to (gnu packages virtualization)....* gnu/packages/qemu.scm: Rename this ... * gnu/packages/virtualization.scm: ... to this. * gnu/local.mk (GNU_SYSTEM_MODULES), gnu/packages/bootloaders.scm, gnu/packages/debug.scm, gnu/packages/gnome.scm, gnu/system/vm.scm, gnu/tests/install.scm: Adjust accordingly. 宋文武 2017-03-15gnu: Use INSTALL-FILE where appropriate....* gnu/packages/admin.scm (wpa-supplicant-minimal): Substitute the simpler INSTALL-FILE for COPY-FILE when invoked with redundant arguments. * gnu/packages/bioinformatics.scm (couger, aragorn, express-beta-diversity, edirect, fasttree, rsem, samtools-0.1): Likewise. * gnu/packages/code.scm (withershins): Likewise. * gnu/packages/conky.scm (conky): Likewise. * gnu/packages/debug.scm (delta, american-fuzzy-lop): Likewise. * gnu/packages/emacs.scm (emacs-mit-scheme-doc): Likewise. * gnu/packages/engineering.scm (librecad): Likewise. Tobias Geerinckx-Rice 2017-03-15gnu: stress-make: Fix description....* gnu/packages/debug.scm (stress-make)[description]: Fix typo. Avoid ambiguous use of ‘in order’. Tobias Geerinckx-Rice 2016-11-29gnu: Add zzuf...* gnu/packages/debug.scm (zzuf): New variable. John Darrington 2016-09-09gnu: c-reduce: Upgrade to 2.5.0....* gnu/packages/debug.scm (c-reduce): Upgrade to 2.5.0. [inputs]: Remove delta and perl-benchmark-timer. Add perl-term-readkey. [arguments]: Adjust wrapper libraries. Eric Bavier 2016-09-06gnu: Fix pre-2.7.0 qemu builds....This is a follow-up to 43bec6d0. * gnu/packages/debug.scm (qemu-2.3.0), gnu/packages/grub.scm (qemu-for-tests)[arguments]: Remove the 'disable-test-qga phase. Efraim Flashner 2016-08-13gnu: Add stress-make....* gnu/packages/debug.scm (stress-make): New variable. Eric Bavier 2016-07-20Revert "gnu: julia: Build with zlib."...This reverts commit 95bf72eeb0b99d6b26c3515fa78a587207c6f779. Efraim Flashner 2016-07-20gnu: julia: Build with zlib....* gnu/packages/julia.scm (julia)[inputs]: Add zlib. Efraim Flashner 2016-06-21gnu: Update american-fuzzy-lop to 2.15b....* gnu/packages/debug.scm (american-fuzzy-lop): Update to 2.15b. Eric Bavier