Changeset cd7ef0b


Ignore:
Timestamp:
Aug 10, 2017, 3:39:11 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
38d70ab
Parents:
275f4b4 (diff), e1780a2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Files:
8 added
1 deleted
65 edited
1 moved

Legend:

Unmodified
Added
Removed
  • .gitignore

    r275f4b4 rcd7ef0b  
    2424lib
    2525include
     26share
    2627
    2728# src executables, for lib and bin
  • Makefile.am

    r275f4b4 rcd7ef0b  
    2121
    2222MAINTAINERCLEANFILES = lib/* bin/* src/examples/.deps/* src/tests/.deps/* src/tests/.out/*
     23
     24man1_MANS = doc/man/cfa.1
  • Makefile.in

    r275f4b4 rcd7ef0b  
    131131    *) (install-info --version) >/dev/null 2>&1;; \
    132132  esac
     133am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
     134am__vpath_adj = case $$p in \
     135    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
     136    *) f=$$p;; \
     137  esac;
     138am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
     139am__install_max = 40
     140am__nobase_strip_setup = \
     141  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
     142am__nobase_strip = \
     143  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
     144am__nobase_list = $(am__nobase_strip_setup); \
     145  for p in $$list; do echo "$$p $$p"; done | \
     146  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
     147  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
     148    if (++n[$$2] == $(am__install_max)) \
     149      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
     150    END { for (dir in files) print dir, files[dir] }'
     151am__base_list = \
     152  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
     153  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
     154am__uninstall_files_from_dir = { \
     155  test -z "$$files" \
     156    || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
     157    || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
     158         $(am__cd) "$$dir" && rm -f $$files; }; \
     159  }
     160man1dir = $(mandir)/man1
     161am__installdirs = "$(DESTDIR)$(man1dir)"
     162NROFF = nroff
     163MANS = $(man1_MANS)
    133164RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \
    134165  distclean-recursive maintainer-clean-recursive
     
    167198        $(top_srcdir)/automake/install-sh \
    168199        $(top_srcdir)/automake/missing INSTALL README automake/compile \
    169         automake/config.guess automake/config.sub automake/depcomp \
    170         automake/install-sh automake/missing automake/ylwrap
     200        automake/config.guess automake/config.sub automake/install-sh \
     201        automake/missing
    171202DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
    172203distdir = $(PACKAGE)-$(VERSION)
     
    335366EXTRA_DIST = Docs                       # non-source files
    336367MAINTAINERCLEANFILES = lib/* bin/* src/examples/.deps/* src/tests/.deps/* src/tests/.out/*
     368man1_MANS = doc/man/cfa.1
    337369all: config.h
    338370        $(MAKE) $(AM_MAKEFLAGS) all-recursive
     
    387419distclean-hdr:
    388420        -rm -f config.h stamp-h1
     421install-man1: $(man1_MANS)
     422        @$(NORMAL_INSTALL)
     423        @list1='$(man1_MANS)'; \
     424        list2=''; \
     425        test -n "$(man1dir)" \
     426          && test -n "`echo $$list1$$list2`" \
     427          || exit 0; \
     428        echo " $(MKDIR_P) '$(DESTDIR)$(man1dir)'"; \
     429        $(MKDIR_P) "$(DESTDIR)$(man1dir)" || exit 1; \
     430        { for i in $$list1; do echo "$$i"; done;  \
     431        if test -n "$$list2"; then \
     432          for i in $$list2; do echo "$$i"; done \
     433            | sed -n '/\.1[a-z]*$$/p'; \
     434        fi; \
     435        } | while read p; do \
     436          if test -f $$p; then d=; else d="$(srcdir)/"; fi; \
     437          echo "$$d$$p"; echo "$$p"; \
     438        done | \
     439        sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^1][0-9a-z]*$$,1,;x' \
     440              -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \
     441        sed 'N;N;s,\n, ,g' | { \
     442        list=; while read file base inst; do \
     443          if test "$$base" = "$$inst"; then list="$$list $$file"; else \
     444            echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man1dir)/$$inst'"; \
     445            $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man1dir)/$$inst" || exit $$?; \
     446          fi; \
     447        done; \
     448        for i in $$list; do echo "$$i"; done | $(am__base_list) | \
     449        while read files; do \
     450          test -z "$$files" || { \
     451            echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man1dir)'"; \
     452            $(INSTALL_DATA) $$files "$(DESTDIR)$(man1dir)" || exit $$?; }; \
     453        done; }
     454
     455uninstall-man1:
     456        @$(NORMAL_UNINSTALL)
     457        @list='$(man1_MANS)'; test -n "$(man1dir)" || exit 0; \
     458        files=`{ for i in $$list; do echo "$$i"; done; \
     459        } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^1][0-9a-z]*$$,1,;x' \
     460              -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \
     461        dir='$(DESTDIR)$(man1dir)'; $(am__uninstall_files_from_dir)
    389462
    390463# This directory's subdirectories are mostly independent; you can cd
     
    684757check-am: all-am
    685758check: check-recursive
    686 all-am: Makefile config.h
     759all-am: Makefile $(MANS) config.h
    687760installdirs: installdirs-recursive
    688761installdirs-am:
     762        for dir in "$(DESTDIR)$(man1dir)"; do \
     763          test -z "$$dir" || $(MKDIR_P) "$$dir"; \
     764        done
    689765install: install-recursive
    690766install-exec: install-exec-recursive
     
    739815info-am:
    740816
    741 install-data-am:
     817install-data-am: install-man
    742818
    743819install-dvi: install-dvi-recursive
     
    755831install-info-am:
    756832
    757 install-man:
     833install-man: install-man1
    758834
    759835install-pdf: install-pdf-recursive
     
    785861ps-am:
    786862
    787 uninstall-am:
     863uninstall-am: uninstall-man
     864
     865uninstall-man: uninstall-man1
    788866
    789867.MAKE: $(am__recursive_targets) all install-am install-strip
     
    798876        install-data install-data-am install-dvi install-dvi-am \
    799877        install-exec install-exec-am install-html install-html-am \
    800         install-info install-info-am install-man install-pdf \
    801         install-pdf-am install-ps install-ps-am install-strip \
    802         installcheck installcheck-am installdirs installdirs-am \
    803         maintainer-clean maintainer-clean-generic mostlyclean \
    804         mostlyclean-generic pdf pdf-am ps ps-am tags tags-am uninstall \
    805         uninstall-am
     878        install-info install-info-am install-man install-man1 \
     879        install-pdf install-pdf-am install-ps install-ps-am \
     880        install-strip installcheck installcheck-am installdirs \
     881        installdirs-am maintainer-clean maintainer-clean-generic \
     882        mostlyclean mostlyclean-generic pdf pdf-am ps ps-am tags \
     883        tags-am uninstall uninstall-am uninstall-man uninstall-man1
    806884
    807885.PRECIOUS: Makefile
  • automake/compile

    r275f4b4 rcd7ef0b  
    22# Wrapper for compilers which do not understand '-c -o'.
    33
    4 scriptversion=2012-01-04.17; # UTC
    5 
    6 # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010, 2012 Free
    7 # Software Foundation, Inc.
     4scriptversion=2012-10-14.11; # UTC
     5
     6# Copyright (C) 1999-2014 Free Software Foundation, Inc.
    87# Written by Tom Tromey <tromey@cygnus.com>.
    98#
     
    7877      ;;
    7978  esac
     79}
     80
     81# func_cl_dashL linkdir
     82# Make cl look for libraries in LINKDIR
     83func_cl_dashL ()
     84{
     85  func_file_conv "$1"
     86  if test -z "$lib_path"; then
     87    lib_path=$file
     88  else
     89    lib_path="$lib_path;$file"
     90  fi
     91  linker_opts="$linker_opts -LIBPATH:$file"
     92}
     93
     94# func_cl_dashl library
     95# Do a library search-path lookup for cl
     96func_cl_dashl ()
     97{
     98  lib=$1
     99  found=no
     100  save_IFS=$IFS
     101  IFS=';'
     102  for dir in $lib_path $LIB
     103  do
     104    IFS=$save_IFS
     105    if $shared && test -f "$dir/$lib.dll.lib"; then
     106      found=yes
     107      lib=$dir/$lib.dll.lib
     108      break
     109    fi
     110    if test -f "$dir/$lib.lib"; then
     111      found=yes
     112      lib=$dir/$lib.lib
     113      break
     114    fi
     115    if test -f "$dir/lib$lib.a"; then
     116      found=yes
     117      lib=$dir/lib$lib.a
     118      break
     119    fi
     120  done
     121  IFS=$save_IFS
     122
     123  if test "$found" != yes; then
     124    lib=$lib.lib
     125  fi
    80126}
    81127
     
    110156          esac
    111157          ;;
     158        -I)
     159          eat=1
     160          func_file_conv "$2" mingw
     161          set x "$@" -I"$file"
     162          shift
     163          ;;
    112164        -I*)
    113165          func_file_conv "${1#-I}" mingw
     
    115167          shift
    116168          ;;
     169        -l)
     170          eat=1
     171          func_cl_dashl "$2"
     172          set x "$@" "$lib"
     173          shift
     174          ;;
    117175        -l*)
    118           lib=${1#-l}
    119           found=no
    120           save_IFS=$IFS
    121           IFS=';'
    122           for dir in $lib_path $LIB
    123           do
    124             IFS=$save_IFS
    125             if $shared && test -f "$dir/$lib.dll.lib"; then
    126               found=yes
    127               set x "$@" "$dir/$lib.dll.lib"
    128               break
    129             fi
    130             if test -f "$dir/$lib.lib"; then
    131               found=yes
    132               set x "$@" "$dir/$lib.lib"
    133               break
    134             fi
    135           done
    136           IFS=$save_IFS
    137 
    138           test "$found" != yes && set x "$@" "$lib.lib"
    139           shift
     176          func_cl_dashl "${1#-l}"
     177          set x "$@" "$lib"
     178          shift
     179          ;;
     180        -L)
     181          eat=1
     182          func_cl_dashL "$2"
    140183          ;;
    141184        -L*)
    142           func_file_conv "${1#-L}"
    143           if test -z "$lib_path"; then
    144             lib_path=$file
    145           else
    146             lib_path="$lib_path;$file"
    147           fi
    148           linker_opts="$linker_opts -LIBPATH:$file"
     185          func_cl_dashL "${1#-L}"
    149186          ;;
    150187        -static)
  • automake/config.guess

    • Property mode changed from 120000 to 100755
    r275f4b4 rcd7ef0b  
    1 /usr/share/automake-1.15/config.guess
     1#! /bin/sh
     2# Attempt to guess a canonical system name.
     3#   Copyright 1992-2015 Free Software Foundation, Inc.
     4
     5timestamp='2015-08-20'
     6
     7# This file is free software; you can redistribute it and/or modify it
     8# under the terms of the GNU General Public License as published by
     9# the Free Software Foundation; either version 3 of the License, or
     10# (at your option) any later version.
     11#
     12# This program is distributed in the hope that it will be useful, but
     13# WITHOUT ANY WARRANTY; without even the implied warranty of
     14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15# General Public License for more details.
     16#
     17# You should have received a copy of the GNU General Public License
     18# along with this program; if not, see <http://www.gnu.org/licenses/>.
     19#
     20# As a special exception to the GNU General Public License, if you
     21# distribute this file as part of a program that contains a
     22# configuration script generated by Autoconf, you may include it under
     23# the same distribution terms that you use for the rest of that
     24# program.  This Exception is an additional permission under section 7
     25# of the GNU General Public License, version 3 ("GPLv3").
     26#
     27# Originally written by Per Bothner; maintained since 2000 by Ben Elliston.
     28#
     29# You can get the latest version of this script from:
     30# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
     31#
     32# Please send patches to <config-patches@gnu.org>.
     33
     34
     35me=`echo "$0" | sed -e 's,.*/,,'`
     36
     37usage="\
     38Usage: $0 [OPTION]
     39
     40Output the configuration name of the system \`$me' is run on.
     41
     42Operation modes:
     43  -h, --help         print this help, then exit
     44  -t, --time-stamp   print date of last modification, then exit
     45  -v, --version      print version number, then exit
     46
     47Report bugs and patches to <config-patches@gnu.org>."
     48
     49version="\
     50GNU config.guess ($timestamp)
     51
     52Originally written by Per Bothner.
     53Copyright 1992-2015 Free Software Foundation, Inc.
     54
     55This is free software; see the source for copying conditions.  There is NO
     56warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
     57
     58help="
     59Try \`$me --help' for more information."
     60
     61# Parse command line
     62while test $# -gt 0 ; do
     63  case $1 in
     64    --time-stamp | --time* | -t )
     65       echo "$timestamp" ; exit ;;
     66    --version | -v )
     67       echo "$version" ; exit ;;
     68    --help | --h* | -h )
     69       echo "$usage"; exit ;;
     70    -- )     # Stop option processing
     71       shift; break ;;
     72    - ) # Use stdin as input.
     73       break ;;
     74    -* )
     75       echo "$me: invalid option $1$help" >&2
     76       exit 1 ;;
     77    * )
     78       break ;;
     79  esac
     80done
     81
     82if test $# != 0; then
     83  echo "$me: too many arguments$help" >&2
     84  exit 1
     85fi
     86
     87trap 'exit 1' 1 2 15
     88
     89# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
     90# compiler to aid in system detection is discouraged as it requires
     91# temporary files to be created and, as you can see below, it is a
     92# headache to deal with in a portable fashion.
     93
     94# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
     95# use `HOST_CC' if defined, but it is deprecated.
     96
     97# Portable tmp directory creation inspired by the Autoconf team.
     98
     99set_cc_for_build='
     100trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
     101trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
     102: ${TMPDIR=/tmp} ;
     103 { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
     104 { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
     105 { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
     106 { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
     107dummy=$tmp/dummy ;
     108tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
     109case $CC_FOR_BUILD,$HOST_CC,$CC in
     110 ,,)    echo "int x;" > $dummy.c ;
     111        for c in cc gcc c89 c99 ; do
     112          if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
     113             CC_FOR_BUILD="$c"; break ;
     114          fi ;
     115        done ;
     116        if test x"$CC_FOR_BUILD" = x ; then
     117          CC_FOR_BUILD=no_compiler_found ;
     118        fi
     119        ;;
     120 ,,*)   CC_FOR_BUILD=$CC ;;
     121 ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
     122esac ; set_cc_for_build= ;'
     123
     124# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
     125# (ghazi@noc.rutgers.edu 1994-08-24)
     126if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
     127        PATH=$PATH:/.attbin ; export PATH
     128fi
     129
     130UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
     131UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
     132UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
     133UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
     134
     135case "${UNAME_SYSTEM}" in
     136Linux|GNU|GNU/*)
     137        # If the system lacks a compiler, then just pick glibc.
     138        # We could probably try harder.
     139        LIBC=gnu
     140
     141        eval $set_cc_for_build
     142        cat <<-EOF > $dummy.c
     143        #include <features.h>
     144        #if defined(__UCLIBC__)
     145        LIBC=uclibc
     146        #elif defined(__dietlibc__)
     147        LIBC=dietlibc
     148        #else
     149        LIBC=gnu
     150        #endif
     151        EOF
     152        eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`
     153        ;;
     154esac
     155
     156# Note: order is significant - the case branches are not exclusive.
     157
     158case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
     159    *:NetBSD:*:*)
     160        # NetBSD (nbsd) targets should (where applicable) match one or
     161        # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*,
     162        # *-*-netbsdecoff* and *-*-netbsd*.  For targets that recently
     163        # switched to ELF, *-*-netbsd* would select the old
     164        # object file format.  This provides both forward
     165        # compatibility and a consistent mechanism for selecting the
     166        # object file format.
     167        #
     168        # Note: NetBSD doesn't particularly care about the vendor
     169        # portion of the name.  We always set it to "unknown".
     170        sysctl="sysctl -n hw.machine_arch"
     171        UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \
     172            /sbin/$sysctl 2>/dev/null || \
     173            /usr/sbin/$sysctl 2>/dev/null || \
     174            echo unknown)`
     175        case "${UNAME_MACHINE_ARCH}" in
     176            armeb) machine=armeb-unknown ;;
     177            arm*) machine=arm-unknown ;;
     178            sh3el) machine=shl-unknown ;;
     179            sh3eb) machine=sh-unknown ;;
     180            sh5el) machine=sh5le-unknown ;;
     181            earmv*)
     182                arch=`echo ${UNAME_MACHINE_ARCH} | sed -e 's,^e\(armv[0-9]\).*$,\1,'`
     183                endian=`echo ${UNAME_MACHINE_ARCH} | sed -ne 's,^.*\(eb\)$,\1,p'`
     184                machine=${arch}${endian}-unknown
     185                ;;
     186            *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
     187        esac
     188        # The Operating System including object format, if it has switched
     189        # to ELF recently, or will in the future.
     190        case "${UNAME_MACHINE_ARCH}" in
     191            arm*|earm*|i386|m68k|ns32k|sh3*|sparc|vax)
     192                eval $set_cc_for_build
     193                if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
     194                        | grep -q __ELF__
     195                then
     196                    # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
     197                    # Return netbsd for either.  FIX?
     198                    os=netbsd
     199                else
     200                    os=netbsdelf
     201                fi
     202                ;;
     203            *)
     204                os=netbsd
     205                ;;
     206        esac
     207        # Determine ABI tags.
     208        case "${UNAME_MACHINE_ARCH}" in
     209            earm*)
     210                expr='s/^earmv[0-9]/-eabi/;s/eb$//'
     211                abi=`echo ${UNAME_MACHINE_ARCH} | sed -e "$expr"`
     212                ;;
     213        esac
     214        # The OS release
     215        # Debian GNU/NetBSD machines have a different userland, and
     216        # thus, need a distinct triplet. However, they do not need
     217        # kernel version information, so it can be replaced with a
     218        # suitable tag, in the style of linux-gnu.
     219        case "${UNAME_VERSION}" in
     220            Debian*)
     221                release='-gnu'
     222                ;;
     223            *)
     224                release=`echo ${UNAME_RELEASE} | sed -e 's/[-_].*//' | cut -d. -f1,2`
     225                ;;
     226        esac
     227        # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
     228        # contains redundant information, the shorter form:
     229        # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
     230        echo "${machine}-${os}${release}${abi}"
     231        exit ;;
     232    *:Bitrig:*:*)
     233        UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`
     234        echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE}
     235        exit ;;
     236    *:OpenBSD:*:*)
     237        UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
     238        echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
     239        exit ;;
     240    *:ekkoBSD:*:*)
     241        echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
     242        exit ;;
     243    *:SolidBSD:*:*)
     244        echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
     245        exit ;;
     246    macppc:MirBSD:*:*)
     247        echo powerpc-unknown-mirbsd${UNAME_RELEASE}
     248        exit ;;
     249    *:MirBSD:*:*)
     250        echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
     251        exit ;;
     252    *:Sortix:*:*)
     253        echo ${UNAME_MACHINE}-unknown-sortix
     254        exit ;;
     255    alpha:OSF1:*:*)
     256        case $UNAME_RELEASE in
     257        *4.0)
     258                UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
     259                ;;
     260        *5.*)
     261                UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
     262                ;;
     263        esac
     264        # According to Compaq, /usr/sbin/psrinfo has been available on
     265        # OSF/1 and Tru64 systems produced since 1995.  I hope that
     266        # covers most systems running today.  This code pipes the CPU
     267        # types through head -n 1, so we only detect the type of CPU 0.
     268        ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^  The alpha \(.*\) processor.*$/\1/p' | head -n 1`
     269        case "$ALPHA_CPU_TYPE" in
     270            "EV4 (21064)")
     271                UNAME_MACHINE="alpha" ;;
     272            "EV4.5 (21064)")
     273                UNAME_MACHINE="alpha" ;;
     274            "LCA4 (21066/21068)")
     275                UNAME_MACHINE="alpha" ;;
     276            "EV5 (21164)")
     277                UNAME_MACHINE="alphaev5" ;;
     278            "EV5.6 (21164A)")
     279                UNAME_MACHINE="alphaev56" ;;
     280            "EV5.6 (21164PC)")
     281                UNAME_MACHINE="alphapca56" ;;
     282            "EV5.7 (21164PC)")
     283                UNAME_MACHINE="alphapca57" ;;
     284            "EV6 (21264)")
     285                UNAME_MACHINE="alphaev6" ;;
     286            "EV6.7 (21264A)")
     287                UNAME_MACHINE="alphaev67" ;;
     288            "EV6.8CB (21264C)")
     289                UNAME_MACHINE="alphaev68" ;;
     290            "EV6.8AL (21264B)")
     291                UNAME_MACHINE="alphaev68" ;;
     292            "EV6.8CX (21264D)")
     293                UNAME_MACHINE="alphaev68" ;;
     294            "EV6.9A (21264/EV69A)")
     295                UNAME_MACHINE="alphaev69" ;;
     296            "EV7 (21364)")
     297                UNAME_MACHINE="alphaev7" ;;
     298            "EV7.9 (21364A)")
     299                UNAME_MACHINE="alphaev79" ;;
     300        esac
     301        # A Pn.n version is a patched version.
     302        # A Vn.n version is a released version.
     303        # A Tn.n version is a released field test version.
     304        # A Xn.n version is an unreleased experimental baselevel.
     305        # 1.2 uses "1.2" for uname -r.
     306        echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
     307        # Reset EXIT trap before exiting to avoid spurious non-zero exit code.
     308        exitcode=$?
     309        trap '' 0
     310        exit $exitcode ;;
     311    Alpha\ *:Windows_NT*:*)
     312        # How do we know it's Interix rather than the generic POSIX subsystem?
     313        # Should we change UNAME_MACHINE based on the output of uname instead
     314        # of the specific Alpha model?
     315        echo alpha-pc-interix
     316        exit ;;
     317    21064:Windows_NT:50:3)
     318        echo alpha-dec-winnt3.5
     319        exit ;;
     320    Amiga*:UNIX_System_V:4.0:*)
     321        echo m68k-unknown-sysv4
     322        exit ;;
     323    *:[Aa]miga[Oo][Ss]:*:*)
     324        echo ${UNAME_MACHINE}-unknown-amigaos
     325        exit ;;
     326    *:[Mm]orph[Oo][Ss]:*:*)
     327        echo ${UNAME_MACHINE}-unknown-morphos
     328        exit ;;
     329    *:OS/390:*:*)
     330        echo i370-ibm-openedition
     331        exit ;;
     332    *:z/VM:*:*)
     333        echo s390-ibm-zvmoe
     334        exit ;;
     335    *:OS400:*:*)
     336        echo powerpc-ibm-os400
     337        exit ;;
     338    arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
     339        echo arm-acorn-riscix${UNAME_RELEASE}
     340        exit ;;
     341    arm*:riscos:*:*|arm*:RISCOS:*:*)
     342        echo arm-unknown-riscos
     343        exit ;;
     344    SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
     345        echo hppa1.1-hitachi-hiuxmpp
     346        exit ;;
     347    Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
     348        # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
     349        if test "`(/bin/universe) 2>/dev/null`" = att ; then
     350                echo pyramid-pyramid-sysv3
     351        else
     352                echo pyramid-pyramid-bsd
     353        fi
     354        exit ;;
     355    NILE*:*:*:dcosx)
     356        echo pyramid-pyramid-svr4
     357        exit ;;
     358    DRS?6000:unix:4.0:6*)
     359        echo sparc-icl-nx6
     360        exit ;;
     361    DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
     362        case `/usr/bin/uname -p` in
     363            sparc) echo sparc-icl-nx7; exit ;;
     364        esac ;;
     365    s390x:SunOS:*:*)
     366        echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
     367        exit ;;
     368    sun4H:SunOS:5.*:*)
     369        echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
     370        exit ;;
     371    sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
     372        echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
     373        exit ;;
     374    i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
     375        echo i386-pc-auroraux${UNAME_RELEASE}
     376        exit ;;
     377    i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
     378        eval $set_cc_for_build
     379        SUN_ARCH="i386"
     380        # If there is a compiler, see if it is configured for 64-bit objects.
     381        # Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
     382        # This test works for both compilers.
     383        if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
     384            if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
     385                (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
     386                grep IS_64BIT_ARCH >/dev/null
     387            then
     388                SUN_ARCH="x86_64"
     389            fi
     390        fi
     391        echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
     392        exit ;;
     393    sun4*:SunOS:6*:*)
     394        # According to config.sub, this is the proper way to canonicalize
     395        # SunOS6.  Hard to guess exactly what SunOS6 will be like, but
     396        # it's likely to be more like Solaris than SunOS4.
     397        echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
     398        exit ;;
     399    sun4*:SunOS:*:*)
     400        case "`/usr/bin/arch -k`" in
     401            Series*|S4*)
     402                UNAME_RELEASE=`uname -v`
     403                ;;
     404        esac
     405        # Japanese Language versions have a version number like `4.1.3-JL'.
     406        echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
     407        exit ;;
     408    sun3*:SunOS:*:*)
     409        echo m68k-sun-sunos${UNAME_RELEASE}
     410        exit ;;
     411    sun*:*:4.2BSD:*)
     412        UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
     413        test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
     414        case "`/bin/arch`" in
     415            sun3)
     416                echo m68k-sun-sunos${UNAME_RELEASE}
     417                ;;
     418            sun4)
     419                echo sparc-sun-sunos${UNAME_RELEASE}
     420                ;;
     421        esac
     422        exit ;;
     423    aushp:SunOS:*:*)
     424        echo sparc-auspex-sunos${UNAME_RELEASE}
     425        exit ;;
     426    # The situation for MiNT is a little confusing.  The machine name
     427    # can be virtually everything (everything which is not
     428    # "atarist" or "atariste" at least should have a processor
     429    # > m68000).  The system name ranges from "MiNT" over "FreeMiNT"
     430    # to the lowercase version "mint" (or "freemint").  Finally
     431    # the system name "TOS" denotes a system which is actually not
     432    # MiNT.  But MiNT is downward compatible to TOS, so this should
     433    # be no problem.
     434    atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
     435        echo m68k-atari-mint${UNAME_RELEASE}
     436        exit ;;
     437    atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
     438        echo m68k-atari-mint${UNAME_RELEASE}
     439        exit ;;
     440    *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
     441        echo m68k-atari-mint${UNAME_RELEASE}
     442        exit ;;
     443    milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
     444        echo m68k-milan-mint${UNAME_RELEASE}
     445        exit ;;
     446    hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
     447        echo m68k-hades-mint${UNAME_RELEASE}
     448        exit ;;
     449    *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
     450        echo m68k-unknown-mint${UNAME_RELEASE}
     451        exit ;;
     452    m68k:machten:*:*)
     453        echo m68k-apple-machten${UNAME_RELEASE}
     454        exit ;;
     455    powerpc:machten:*:*)
     456        echo powerpc-apple-machten${UNAME_RELEASE}
     457        exit ;;
     458    RISC*:Mach:*:*)
     459        echo mips-dec-mach_bsd4.3
     460        exit ;;
     461    RISC*:ULTRIX:*:*)
     462        echo mips-dec-ultrix${UNAME_RELEASE}
     463        exit ;;
     464    VAX*:ULTRIX*:*:*)
     465        echo vax-dec-ultrix${UNAME_RELEASE}
     466        exit ;;
     467    2020:CLIX:*:* | 2430:CLIX:*:*)
     468        echo clipper-intergraph-clix${UNAME_RELEASE}
     469        exit ;;
     470    mips:*:*:UMIPS | mips:*:*:RISCos)
     471        eval $set_cc_for_build
     472        sed 's/^        //' << EOF >$dummy.c
     473#ifdef __cplusplus
     474#include <stdio.h>  /* for printf() prototype */
     475        int main (int argc, char *argv[]) {
     476#else
     477        int main (argc, argv) int argc; char *argv[]; {
     478#endif
     479        #if defined (host_mips) && defined (MIPSEB)
     480        #if defined (SYSTYPE_SYSV)
     481          printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
     482        #endif
     483        #if defined (SYSTYPE_SVR4)
     484          printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
     485        #endif
     486        #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
     487          printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
     488        #endif
     489        #endif
     490          exit (-1);
     491        }
     492EOF
     493        $CC_FOR_BUILD -o $dummy $dummy.c &&
     494          dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` &&
     495          SYSTEM_NAME=`$dummy $dummyarg` &&
     496            { echo "$SYSTEM_NAME"; exit; }
     497        echo mips-mips-riscos${UNAME_RELEASE}
     498        exit ;;
     499    Motorola:PowerMAX_OS:*:*)
     500        echo powerpc-motorola-powermax
     501        exit ;;
     502    Motorola:*:4.3:PL8-*)
     503        echo powerpc-harris-powermax
     504        exit ;;
     505    Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
     506        echo powerpc-harris-powermax
     507        exit ;;
     508    Night_Hawk:Power_UNIX:*:*)
     509        echo powerpc-harris-powerunix
     510        exit ;;
     511    m88k:CX/UX:7*:*)
     512        echo m88k-harris-cxux7
     513        exit ;;
     514    m88k:*:4*:R4*)
     515        echo m88k-motorola-sysv4
     516        exit ;;
     517    m88k:*:3*:R3*)
     518        echo m88k-motorola-sysv3
     519        exit ;;
     520    AViiON:dgux:*:*)
     521        # DG/UX returns AViiON for all architectures
     522        UNAME_PROCESSOR=`/usr/bin/uname -p`
     523        if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
     524        then
     525            if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
     526               [ ${TARGET_BINARY_INTERFACE}x = x ]
     527            then
     528                echo m88k-dg-dgux${UNAME_RELEASE}
     529            else
     530                echo m88k-dg-dguxbcs${UNAME_RELEASE}
     531            fi
     532        else
     533            echo i586-dg-dgux${UNAME_RELEASE}
     534        fi
     535        exit ;;
     536    M88*:DolphinOS:*:*) # DolphinOS (SVR3)
     537        echo m88k-dolphin-sysv3
     538        exit ;;
     539    M88*:*:R3*:*)
     540        # Delta 88k system running SVR3
     541        echo m88k-motorola-sysv3
     542        exit ;;
     543    XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
     544        echo m88k-tektronix-sysv3
     545        exit ;;
     546    Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
     547        echo m68k-tektronix-bsd
     548        exit ;;
     549    *:IRIX*:*:*)
     550        echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
     551        exit ;;
     552    ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
     553        echo romp-ibm-aix     # uname -m gives an 8 hex-code CPU id
     554        exit ;;               # Note that: echo "'`uname -s`'" gives 'AIX '
     555    i*86:AIX:*:*)
     556        echo i386-ibm-aix
     557        exit ;;
     558    ia64:AIX:*:*)
     559        if [ -x /usr/bin/oslevel ] ; then
     560                IBM_REV=`/usr/bin/oslevel`
     561        else
     562                IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
     563        fi
     564        echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
     565        exit ;;
     566    *:AIX:2:3)
     567        if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
     568                eval $set_cc_for_build
     569                sed 's/^                //' << EOF >$dummy.c
     570                #include <sys/systemcfg.h>
     571
     572                main()
     573                        {
     574                        if (!__power_pc())
     575                                exit(1);
     576                        puts("powerpc-ibm-aix3.2.5");
     577                        exit(0);
     578                        }
     579EOF
     580                if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`
     581                then
     582                        echo "$SYSTEM_NAME"
     583                else
     584                        echo rs6000-ibm-aix3.2.5
     585                fi
     586        elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
     587                echo rs6000-ibm-aix3.2.4
     588        else
     589                echo rs6000-ibm-aix3.2
     590        fi
     591        exit ;;
     592    *:AIX:*:[4567])
     593        IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
     594        if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
     595                IBM_ARCH=rs6000
     596        else
     597                IBM_ARCH=powerpc
     598        fi
     599        if [ -x /usr/bin/lslpp ] ; then
     600                IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc |
     601                           awk -F: '{ print $3 }' | sed s/[0-9]*$/0/`
     602        else
     603                IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
     604        fi
     605        echo ${IBM_ARCH}-ibm-aix${IBM_REV}
     606        exit ;;
     607    *:AIX:*:*)
     608        echo rs6000-ibm-aix
     609        exit ;;
     610    ibmrt:4.4BSD:*|romp-ibm:BSD:*)
     611        echo romp-ibm-bsd4.4
     612        exit ;;
     613    ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and
     614        echo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to
     615        exit ;;                             # report: romp-ibm BSD 4.3
     616    *:BOSX:*:*)
     617        echo rs6000-bull-bosx
     618        exit ;;
     619    DPX/2?00:B.O.S.:*:*)
     620        echo m68k-bull-sysv3
     621        exit ;;
     622    9000/[34]??:4.3bsd:1.*:*)
     623        echo m68k-hp-bsd
     624        exit ;;
     625    hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
     626        echo m68k-hp-bsd4.4
     627        exit ;;
     628    9000/[34678]??:HP-UX:*:*)
     629        HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
     630        case "${UNAME_MACHINE}" in
     631            9000/31? )            HP_ARCH=m68000 ;;
     632            9000/[34]?? )         HP_ARCH=m68k ;;
     633            9000/[678][0-9][0-9])
     634                if [ -x /usr/bin/getconf ]; then
     635                    sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
     636                    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
     637                    case "${sc_cpu_version}" in
     638                      523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
     639                      528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
     640                      532)                      # CPU_PA_RISC2_0
     641                        case "${sc_kernel_bits}" in
     642                          32) HP_ARCH="hppa2.0n" ;;
     643                          64) HP_ARCH="hppa2.0w" ;;
     644                          '') HP_ARCH="hppa2.0" ;;   # HP-UX 10.20
     645                        esac ;;
     646                    esac
     647                fi
     648                if [ "${HP_ARCH}" = "" ]; then
     649                    eval $set_cc_for_build
     650                    sed 's/^            //' << EOF >$dummy.c
     651
     652                #define _HPUX_SOURCE
     653                #include <stdlib.h>
     654                #include <unistd.h>
     655
     656                int main ()
     657                {
     658                #if defined(_SC_KERNEL_BITS)
     659                    long bits = sysconf(_SC_KERNEL_BITS);
     660                #endif
     661                    long cpu  = sysconf (_SC_CPU_VERSION);
     662
     663                    switch (cpu)
     664                        {
     665                        case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
     666                        case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
     667                        case CPU_PA_RISC2_0:
     668                #if defined(_SC_KERNEL_BITS)
     669                            switch (bits)
     670                                {
     671                                case 64: puts ("hppa2.0w"); break;
     672                                case 32: puts ("hppa2.0n"); break;
     673                                default: puts ("hppa2.0"); break;
     674                                } break;
     675                #else  /* !defined(_SC_KERNEL_BITS) */
     676                            puts ("hppa2.0"); break;
     677                #endif
     678                        default: puts ("hppa1.0"); break;
     679                        }
     680                    exit (0);
     681                }
     682EOF
     683                    (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
     684                    test -z "$HP_ARCH" && HP_ARCH=hppa
     685                fi ;;
     686        esac
     687        if [ ${HP_ARCH} = "hppa2.0w" ]
     688        then
     689            eval $set_cc_for_build
     690
     691            # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
     692            # 32-bit code.  hppa64-hp-hpux* has the same kernel and a compiler
     693            # generating 64-bit code.  GNU and HP use different nomenclature:
     694            #
     695            # $ CC_FOR_BUILD=cc ./config.guess
     696            # => hppa2.0w-hp-hpux11.23
     697            # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
     698            # => hppa64-hp-hpux11.23
     699
     700            if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
     701                grep -q __LP64__
     702            then
     703                HP_ARCH="hppa2.0w"
     704            else
     705                HP_ARCH="hppa64"
     706            fi
     707        fi
     708        echo ${HP_ARCH}-hp-hpux${HPUX_REV}
     709        exit ;;
     710    ia64:HP-UX:*:*)
     711        HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
     712        echo ia64-hp-hpux${HPUX_REV}
     713        exit ;;
     714    3050*:HI-UX:*:*)
     715        eval $set_cc_for_build
     716        sed 's/^        //' << EOF >$dummy.c
     717        #include <unistd.h>
     718        int
     719        main ()
     720        {
     721          long cpu = sysconf (_SC_CPU_VERSION);
     722          /* The order matters, because CPU_IS_HP_MC68K erroneously returns
     723             true for CPU_PA_RISC1_0.  CPU_IS_PA_RISC returns correct
     724             results, however.  */
     725          if (CPU_IS_PA_RISC (cpu))
     726            {
     727              switch (cpu)
     728                {
     729                  case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
     730                  case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
     731                  case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
     732                  default: puts ("hppa-hitachi-hiuxwe2"); break;
     733                }
     734            }
     735          else if (CPU_IS_HP_MC68K (cpu))
     736            puts ("m68k-hitachi-hiuxwe2");
     737          else puts ("unknown-hitachi-hiuxwe2");
     738          exit (0);
     739        }
     740EOF
     741        $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&
     742                { echo "$SYSTEM_NAME"; exit; }
     743        echo unknown-hitachi-hiuxwe2
     744        exit ;;
     745    9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
     746        echo hppa1.1-hp-bsd
     747        exit ;;
     748    9000/8??:4.3bsd:*:*)
     749        echo hppa1.0-hp-bsd
     750        exit ;;
     751    *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
     752        echo hppa1.0-hp-mpeix
     753        exit ;;
     754    hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
     755        echo hppa1.1-hp-osf
     756        exit ;;
     757    hp8??:OSF1:*:*)
     758        echo hppa1.0-hp-osf
     759        exit ;;
     760    i*86:OSF1:*:*)
     761        if [ -x /usr/sbin/sysversion ] ; then
     762            echo ${UNAME_MACHINE}-unknown-osf1mk
     763        else
     764            echo ${UNAME_MACHINE}-unknown-osf1
     765        fi
     766        exit ;;
     767    parisc*:Lites*:*:*)
     768        echo hppa1.1-hp-lites
     769        exit ;;
     770    C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
     771        echo c1-convex-bsd
     772        exit ;;
     773    C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
     774        if getsysinfo -f scalar_acc
     775        then echo c32-convex-bsd
     776        else echo c2-convex-bsd
     777        fi
     778        exit ;;
     779    C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
     780        echo c34-convex-bsd
     781        exit ;;
     782    C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
     783        echo c38-convex-bsd
     784        exit ;;
     785    C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
     786        echo c4-convex-bsd
     787        exit ;;
     788    CRAY*Y-MP:*:*:*)
     789        echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
     790        exit ;;
     791    CRAY*[A-Z]90:*:*:*)
     792        echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
     793        | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
     794              -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
     795              -e 's/\.[^.]*$/.X/'
     796        exit ;;
     797    CRAY*TS:*:*:*)
     798        echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
     799        exit ;;
     800    CRAY*T3E:*:*:*)
     801        echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
     802        exit ;;
     803    CRAY*SV1:*:*:*)
     804        echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
     805        exit ;;
     806    *:UNICOS/mp:*:*)
     807        echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
     808        exit ;;
     809    F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
     810        FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
     811        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
     812        FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
     813        echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
     814        exit ;;
     815    5000:UNIX_System_V:4.*:*)
     816        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
     817        FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
     818        echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
     819        exit ;;
     820    i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
     821        echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
     822        exit ;;
     823    sparc*:BSD/OS:*:*)
     824        echo sparc-unknown-bsdi${UNAME_RELEASE}
     825        exit ;;
     826    *:BSD/OS:*:*)
     827        echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
     828        exit ;;
     829    *:FreeBSD:*:*)
     830        UNAME_PROCESSOR=`/usr/bin/uname -p`
     831        case ${UNAME_PROCESSOR} in
     832            amd64)
     833                echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
     834            *)
     835                echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
     836        esac
     837        exit ;;
     838    i*:CYGWIN*:*)
     839        echo ${UNAME_MACHINE}-pc-cygwin
     840        exit ;;
     841    *:MINGW64*:*)
     842        echo ${UNAME_MACHINE}-pc-mingw64
     843        exit ;;
     844    *:MINGW*:*)
     845        echo ${UNAME_MACHINE}-pc-mingw32
     846        exit ;;
     847    *:MSYS*:*)
     848        echo ${UNAME_MACHINE}-pc-msys
     849        exit ;;
     850    i*:windows32*:*)
     851        # uname -m includes "-pc" on this system.
     852        echo ${UNAME_MACHINE}-mingw32
     853        exit ;;
     854    i*:PW*:*)
     855        echo ${UNAME_MACHINE}-pc-pw32
     856        exit ;;
     857    *:Interix*:*)
     858        case ${UNAME_MACHINE} in
     859            x86)
     860                echo i586-pc-interix${UNAME_RELEASE}
     861                exit ;;
     862            authenticamd | genuineintel | EM64T)
     863                echo x86_64-unknown-interix${UNAME_RELEASE}
     864                exit ;;
     865            IA64)
     866                echo ia64-unknown-interix${UNAME_RELEASE}
     867                exit ;;
     868        esac ;;
     869    [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
     870        echo i${UNAME_MACHINE}-pc-mks
     871        exit ;;
     872    8664:Windows_NT:*)
     873        echo x86_64-pc-mks
     874        exit ;;
     875    i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
     876        # How do we know it's Interix rather than the generic POSIX subsystem?
     877        # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
     878        # UNAME_MACHINE based on the output of uname instead of i386?
     879        echo i586-pc-interix
     880        exit ;;
     881    i*:UWIN*:*)
     882        echo ${UNAME_MACHINE}-pc-uwin
     883        exit ;;
     884    amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
     885        echo x86_64-unknown-cygwin
     886        exit ;;
     887    p*:CYGWIN*:*)
     888        echo powerpcle-unknown-cygwin
     889        exit ;;
     890    prep*:SunOS:5.*:*)
     891        echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
     892        exit ;;
     893    *:GNU:*:*)
     894        # the GNU system
     895        echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
     896        exit ;;
     897    *:GNU/*:*:*)
     898        # other systems with GNU libc and userland
     899        echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC}
     900        exit ;;
     901    i*86:Minix:*:*)
     902        echo ${UNAME_MACHINE}-pc-minix
     903        exit ;;
     904    aarch64:Linux:*:*)
     905        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     906        exit ;;
     907    aarch64_be:Linux:*:*)
     908        UNAME_MACHINE=aarch64_be
     909        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     910        exit ;;
     911    alpha:Linux:*:*)
     912        case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
     913          EV5)   UNAME_MACHINE=alphaev5 ;;
     914          EV56)  UNAME_MACHINE=alphaev56 ;;
     915          PCA56) UNAME_MACHINE=alphapca56 ;;
     916          PCA57) UNAME_MACHINE=alphapca56 ;;
     917          EV6)   UNAME_MACHINE=alphaev6 ;;
     918          EV67)  UNAME_MACHINE=alphaev67 ;;
     919          EV68*) UNAME_MACHINE=alphaev68 ;;
     920        esac
     921        objdump --private-headers /bin/sh | grep -q ld.so.1
     922        if test "$?" = 0 ; then LIBC="gnulibc1" ; fi
     923        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     924        exit ;;
     925    arc:Linux:*:* | arceb:Linux:*:*)
     926        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     927        exit ;;
     928    arm*:Linux:*:*)
     929        eval $set_cc_for_build
     930        if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
     931            | grep -q __ARM_EABI__
     932        then
     933            echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     934        else
     935            if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
     936                | grep -q __ARM_PCS_VFP
     937            then
     938                echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi
     939            else
     940                echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf
     941            fi
     942        fi
     943        exit ;;
     944    avr32*:Linux:*:*)
     945        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     946        exit ;;
     947    cris:Linux:*:*)
     948        echo ${UNAME_MACHINE}-axis-linux-${LIBC}
     949        exit ;;
     950    crisv32:Linux:*:*)
     951        echo ${UNAME_MACHINE}-axis-linux-${LIBC}
     952        exit ;;
     953    e2k:Linux:*:*)
     954        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     955        exit ;;
     956    frv:Linux:*:*)
     957        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     958        exit ;;
     959    hexagon:Linux:*:*)
     960        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     961        exit ;;
     962    i*86:Linux:*:*)
     963        echo ${UNAME_MACHINE}-pc-linux-${LIBC}
     964        exit ;;
     965    ia64:Linux:*:*)
     966        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     967        exit ;;
     968    m32r*:Linux:*:*)
     969        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     970        exit ;;
     971    m68*:Linux:*:*)
     972        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     973        exit ;;
     974    mips:Linux:*:* | mips64:Linux:*:*)
     975        eval $set_cc_for_build
     976        sed 's/^        //' << EOF >$dummy.c
     977        #undef CPU
     978        #undef ${UNAME_MACHINE}
     979        #undef ${UNAME_MACHINE}el
     980        #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
     981        CPU=${UNAME_MACHINE}el
     982        #else
     983        #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
     984        CPU=${UNAME_MACHINE}
     985        #else
     986        CPU=
     987        #endif
     988        #endif
     989EOF
     990        eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
     991        test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; }
     992        ;;
     993    openrisc*:Linux:*:*)
     994        echo or1k-unknown-linux-${LIBC}
     995        exit ;;
     996    or32:Linux:*:* | or1k*:Linux:*:*)
     997        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     998        exit ;;
     999    padre:Linux:*:*)
     1000        echo sparc-unknown-linux-${LIBC}
     1001        exit ;;
     1002    parisc64:Linux:*:* | hppa64:Linux:*:*)
     1003        echo hppa64-unknown-linux-${LIBC}
     1004        exit ;;
     1005    parisc:Linux:*:* | hppa:Linux:*:*)
     1006        # Look for CPU level
     1007        case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
     1008          PA7*) echo hppa1.1-unknown-linux-${LIBC} ;;
     1009          PA8*) echo hppa2.0-unknown-linux-${LIBC} ;;
     1010          *)    echo hppa-unknown-linux-${LIBC} ;;
     1011        esac
     1012        exit ;;
     1013    ppc64:Linux:*:*)
     1014        echo powerpc64-unknown-linux-${LIBC}
     1015        exit ;;
     1016    ppc:Linux:*:*)
     1017        echo powerpc-unknown-linux-${LIBC}
     1018        exit ;;
     1019    ppc64le:Linux:*:*)
     1020        echo powerpc64le-unknown-linux-${LIBC}
     1021        exit ;;
     1022    ppcle:Linux:*:*)
     1023        echo powerpcle-unknown-linux-${LIBC}
     1024        exit ;;
     1025    s390:Linux:*:* | s390x:Linux:*:*)
     1026        echo ${UNAME_MACHINE}-ibm-linux-${LIBC}
     1027        exit ;;
     1028    sh64*:Linux:*:*)
     1029        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     1030        exit ;;
     1031    sh*:Linux:*:*)
     1032        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     1033        exit ;;
     1034    sparc:Linux:*:* | sparc64:Linux:*:*)
     1035        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     1036        exit ;;
     1037    tile*:Linux:*:*)
     1038        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     1039        exit ;;
     1040    vax:Linux:*:*)
     1041        echo ${UNAME_MACHINE}-dec-linux-${LIBC}
     1042        exit ;;
     1043    x86_64:Linux:*:*)
     1044        echo ${UNAME_MACHINE}-pc-linux-${LIBC}
     1045        exit ;;
     1046    xtensa*:Linux:*:*)
     1047        echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
     1048        exit ;;
     1049    i*86:DYNIX/ptx:4*:*)
     1050        # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
     1051        # earlier versions are messed up and put the nodename in both
     1052        # sysname and nodename.
     1053        echo i386-sequent-sysv4
     1054        exit ;;
     1055    i*86:UNIX_SV:4.2MP:2.*)
     1056        # Unixware is an offshoot of SVR4, but it has its own version
     1057        # number series starting with 2...
     1058        # I am not positive that other SVR4 systems won't match this,
     1059        # I just have to hope.  -- rms.
     1060        # Use sysv4.2uw... so that sysv4* matches it.
     1061        echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
     1062        exit ;;
     1063    i*86:OS/2:*:*)
     1064        # If we were able to find `uname', then EMX Unix compatibility
     1065        # is probably installed.
     1066        echo ${UNAME_MACHINE}-pc-os2-emx
     1067        exit ;;
     1068    i*86:XTS-300:*:STOP)
     1069        echo ${UNAME_MACHINE}-unknown-stop
     1070        exit ;;
     1071    i*86:atheos:*:*)
     1072        echo ${UNAME_MACHINE}-unknown-atheos
     1073        exit ;;
     1074    i*86:syllable:*:*)
     1075        echo ${UNAME_MACHINE}-pc-syllable
     1076        exit ;;
     1077    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)
     1078        echo i386-unknown-lynxos${UNAME_RELEASE}
     1079        exit ;;
     1080    i*86:*DOS:*:*)
     1081        echo ${UNAME_MACHINE}-pc-msdosdjgpp
     1082        exit ;;
     1083    i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
     1084        UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
     1085        if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
     1086                echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
     1087        else
     1088                echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
     1089        fi
     1090        exit ;;
     1091    i*86:*:5:[678]*)
     1092        # UnixWare 7.x, OpenUNIX and OpenServer 6.
     1093        case `/bin/uname -X | grep "^Machine"` in
     1094            *486*)           UNAME_MACHINE=i486 ;;
     1095            *Pentium)        UNAME_MACHINE=i586 ;;
     1096            *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
     1097        esac
     1098        echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
     1099        exit ;;
     1100    i*86:*:3.2:*)
     1101        if test -f /usr/options/cb.name; then
     1102                UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
     1103                echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
     1104        elif /bin/uname -X 2>/dev/null >/dev/null ; then
     1105                UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
     1106                (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
     1107                (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
     1108                        && UNAME_MACHINE=i586
     1109                (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
     1110                        && UNAME_MACHINE=i686
     1111                (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
     1112                        && UNAME_MACHINE=i686
     1113                echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
     1114        else
     1115                echo ${UNAME_MACHINE}-pc-sysv32
     1116        fi
     1117        exit ;;
     1118    pc:*:*:*)
     1119        # Left here for compatibility:
     1120        # uname -m prints for DJGPP always 'pc', but it prints nothing about
     1121        # the processor, so we play safe by assuming i586.
     1122        # Note: whatever this is, it MUST be the same as what config.sub
     1123        # prints for the "djgpp" host, or else GDB configury will decide that
     1124        # this is a cross-build.
     1125        echo i586-pc-msdosdjgpp
     1126        exit ;;
     1127    Intel:Mach:3*:*)
     1128        echo i386-pc-mach3
     1129        exit ;;
     1130    paragon:*:*:*)
     1131        echo i860-intel-osf1
     1132        exit ;;
     1133    i860:*:4.*:*) # i860-SVR4
     1134        if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
     1135          echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
     1136        else # Add other i860-SVR4 vendors below as they are discovered.
     1137          echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4
     1138        fi
     1139        exit ;;
     1140    mini*:CTIX:SYS*5:*)
     1141        # "miniframe"
     1142        echo m68010-convergent-sysv
     1143        exit ;;
     1144    mc68k:UNIX:SYSTEM5:3.51m)
     1145        echo m68k-convergent-sysv
     1146        exit ;;
     1147    M680?0:D-NIX:5.3:*)
     1148        echo m68k-diab-dnix
     1149        exit ;;
     1150    M68*:*:R3V[5678]*:*)
     1151        test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
     1152    3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
     1153        OS_REL=''
     1154        test -r /etc/.relid \
     1155        && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
     1156        /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
     1157          && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
     1158        /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
     1159          && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
     1160    3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
     1161        /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
     1162          && { echo i486-ncr-sysv4; exit; } ;;
     1163    NCR*:*:4.2:* | MPRAS*:*:4.2:*)
     1164        OS_REL='.3'
     1165        test -r /etc/.relid \
     1166            && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
     1167        /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
     1168            && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
     1169        /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
     1170            && { echo i586-ncr-sysv4.3${OS_REL}; exit; }
     1171        /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
     1172            && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
     1173    m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
     1174        echo m68k-unknown-lynxos${UNAME_RELEASE}
     1175        exit ;;
     1176    mc68030:UNIX_System_V:4.*:*)
     1177        echo m68k-atari-sysv4
     1178        exit ;;
     1179    TSUNAMI:LynxOS:2.*:*)
     1180        echo sparc-unknown-lynxos${UNAME_RELEASE}
     1181        exit ;;
     1182    rs6000:LynxOS:2.*:*)
     1183        echo rs6000-unknown-lynxos${UNAME_RELEASE}
     1184        exit ;;
     1185    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)
     1186        echo powerpc-unknown-lynxos${UNAME_RELEASE}
     1187        exit ;;
     1188    SM[BE]S:UNIX_SV:*:*)
     1189        echo mips-dde-sysv${UNAME_RELEASE}
     1190        exit ;;
     1191    RM*:ReliantUNIX-*:*:*)
     1192        echo mips-sni-sysv4
     1193        exit ;;
     1194    RM*:SINIX-*:*:*)
     1195        echo mips-sni-sysv4
     1196        exit ;;
     1197    *:SINIX-*:*:*)
     1198        if uname -p 2>/dev/null >/dev/null ; then
     1199                UNAME_MACHINE=`(uname -p) 2>/dev/null`
     1200                echo ${UNAME_MACHINE}-sni-sysv4
     1201        else
     1202                echo ns32k-sni-sysv
     1203        fi
     1204        exit ;;
     1205    PENTIUM:*:4.0*:*)   # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
     1206                        # says <Richard.M.Bartel@ccMail.Census.GOV>
     1207        echo i586-unisys-sysv4
     1208        exit ;;
     1209    *:UNIX_System_V:4*:FTX*)
     1210        # From Gerald Hewes <hewes@openmarket.com>.
     1211        # How about differentiating between stratus architectures? -djm
     1212        echo hppa1.1-stratus-sysv4
     1213        exit ;;
     1214    *:*:*:FTX*)
     1215        # From seanf@swdc.stratus.com.
     1216        echo i860-stratus-sysv4
     1217        exit ;;
     1218    i*86:VOS:*:*)
     1219        # From Paul.Green@stratus.com.
     1220        echo ${UNAME_MACHINE}-stratus-vos
     1221        exit ;;
     1222    *:VOS:*:*)
     1223        # From Paul.Green@stratus.com.
     1224        echo hppa1.1-stratus-vos
     1225        exit ;;
     1226    mc68*:A/UX:*:*)
     1227        echo m68k-apple-aux${UNAME_RELEASE}
     1228        exit ;;
     1229    news*:NEWS-OS:6*:*)
     1230        echo mips-sony-newsos6
     1231        exit ;;
     1232    R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
     1233        if [ -d /usr/nec ]; then
     1234                echo mips-nec-sysv${UNAME_RELEASE}
     1235        else
     1236                echo mips-unknown-sysv${UNAME_RELEASE}
     1237        fi
     1238        exit ;;
     1239    BeBox:BeOS:*:*)     # BeOS running on hardware made by Be, PPC only.
     1240        echo powerpc-be-beos
     1241        exit ;;
     1242    BeMac:BeOS:*:*)     # BeOS running on Mac or Mac clone, PPC only.
     1243        echo powerpc-apple-beos
     1244        exit ;;
     1245    BePC:BeOS:*:*)      # BeOS running on Intel PC compatible.
     1246        echo i586-pc-beos
     1247        exit ;;
     1248    BePC:Haiku:*:*)     # Haiku running on Intel PC compatible.
     1249        echo i586-pc-haiku
     1250        exit ;;
     1251    x86_64:Haiku:*:*)
     1252        echo x86_64-unknown-haiku
     1253        exit ;;
     1254    SX-4:SUPER-UX:*:*)
     1255        echo sx4-nec-superux${UNAME_RELEASE}
     1256        exit ;;
     1257    SX-5:SUPER-UX:*:*)
     1258        echo sx5-nec-superux${UNAME_RELEASE}
     1259        exit ;;
     1260    SX-6:SUPER-UX:*:*)
     1261        echo sx6-nec-superux${UNAME_RELEASE}
     1262        exit ;;
     1263    SX-7:SUPER-UX:*:*)
     1264        echo sx7-nec-superux${UNAME_RELEASE}
     1265        exit ;;
     1266    SX-8:SUPER-UX:*:*)
     1267        echo sx8-nec-superux${UNAME_RELEASE}
     1268        exit ;;
     1269    SX-8R:SUPER-UX:*:*)
     1270        echo sx8r-nec-superux${UNAME_RELEASE}
     1271        exit ;;
     1272    Power*:Rhapsody:*:*)
     1273        echo powerpc-apple-rhapsody${UNAME_RELEASE}
     1274        exit ;;
     1275    *:Rhapsody:*:*)
     1276        echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
     1277        exit ;;
     1278    *:Darwin:*:*)
     1279        UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
     1280        eval $set_cc_for_build
     1281        if test "$UNAME_PROCESSOR" = unknown ; then
     1282            UNAME_PROCESSOR=powerpc
     1283        fi
     1284        if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then
     1285            if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
     1286                if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
     1287                    (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
     1288                    grep IS_64BIT_ARCH >/dev/null
     1289                then
     1290                    case $UNAME_PROCESSOR in
     1291                        i386) UNAME_PROCESSOR=x86_64 ;;
     1292                        powerpc) UNAME_PROCESSOR=powerpc64 ;;
     1293                    esac
     1294                fi
     1295            fi
     1296        elif test "$UNAME_PROCESSOR" = i386 ; then
     1297            # Avoid executing cc on OS X 10.9, as it ships with a stub
     1298            # that puts up a graphical alert prompting to install
     1299            # developer tools.  Any system running Mac OS X 10.7 or
     1300            # later (Darwin 11 and later) is required to have a 64-bit
     1301            # processor. This is not true of the ARM version of Darwin
     1302            # that Apple uses in portable devices.
     1303            UNAME_PROCESSOR=x86_64
     1304        fi
     1305        echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
     1306        exit ;;
     1307    *:procnto*:*:* | *:QNX:[0123456789]*:*)
     1308        UNAME_PROCESSOR=`uname -p`
     1309        if test "$UNAME_PROCESSOR" = "x86"; then
     1310                UNAME_PROCESSOR=i386
     1311                UNAME_MACHINE=pc
     1312        fi
     1313        echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
     1314        exit ;;
     1315    *:QNX:*:4*)
     1316        echo i386-pc-qnx
     1317        exit ;;
     1318    NEO-?:NONSTOP_KERNEL:*:*)
     1319        echo neo-tandem-nsk${UNAME_RELEASE}
     1320        exit ;;
     1321    NSE-*:NONSTOP_KERNEL:*:*)
     1322        echo nse-tandem-nsk${UNAME_RELEASE}
     1323        exit ;;
     1324    NSR-?:NONSTOP_KERNEL:*:*)
     1325        echo nsr-tandem-nsk${UNAME_RELEASE}
     1326        exit ;;
     1327    *:NonStop-UX:*:*)
     1328        echo mips-compaq-nonstopux
     1329        exit ;;
     1330    BS2000:POSIX*:*:*)
     1331        echo bs2000-siemens-sysv
     1332        exit ;;
     1333    DS/*:UNIX_System_V:*:*)
     1334        echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
     1335        exit ;;
     1336    *:Plan9:*:*)
     1337        # "uname -m" is not consistent, so use $cputype instead. 386
     1338        # is converted to i386 for consistency with other x86
     1339        # operating systems.
     1340        if test "$cputype" = "386"; then
     1341            UNAME_MACHINE=i386
     1342        else
     1343            UNAME_MACHINE="$cputype"
     1344        fi
     1345        echo ${UNAME_MACHINE}-unknown-plan9
     1346        exit ;;
     1347    *:TOPS-10:*:*)
     1348        echo pdp10-unknown-tops10
     1349        exit ;;
     1350    *:TENEX:*:*)
     1351        echo pdp10-unknown-tenex
     1352        exit ;;
     1353    KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
     1354        echo pdp10-dec-tops20
     1355        exit ;;
     1356    XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
     1357        echo pdp10-xkl-tops20
     1358        exit ;;
     1359    *:TOPS-20:*:*)
     1360        echo pdp10-unknown-tops20
     1361        exit ;;
     1362    *:ITS:*:*)
     1363        echo pdp10-unknown-its
     1364        exit ;;
     1365    SEI:*:*:SEIUX)
     1366        echo mips-sei-seiux${UNAME_RELEASE}
     1367        exit ;;
     1368    *:DragonFly:*:*)
     1369        echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
     1370        exit ;;
     1371    *:*VMS:*:*)
     1372        UNAME_MACHINE=`(uname -p) 2>/dev/null`
     1373        case "${UNAME_MACHINE}" in
     1374            A*) echo alpha-dec-vms ; exit ;;
     1375            I*) echo ia64-dec-vms ; exit ;;
     1376            V*) echo vax-dec-vms ; exit ;;
     1377        esac ;;
     1378    *:XENIX:*:SysV)
     1379        echo i386-pc-xenix
     1380        exit ;;
     1381    i*86:skyos:*:*)
     1382        echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
     1383        exit ;;
     1384    i*86:rdos:*:*)
     1385        echo ${UNAME_MACHINE}-pc-rdos
     1386        exit ;;
     1387    i*86:AROS:*:*)
     1388        echo ${UNAME_MACHINE}-pc-aros
     1389        exit ;;
     1390    x86_64:VMkernel:*:*)
     1391        echo ${UNAME_MACHINE}-unknown-esx
     1392        exit ;;
     1393esac
     1394
     1395cat >&2 <<EOF
     1396$0: unable to guess system type
     1397
     1398This script, last modified $timestamp, has failed to recognize
     1399the operating system you are using. It is advised that you
     1400download the most up to date version of the config scripts from
     1401
     1402  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
     1403and
     1404  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
     1405
     1406If the version you run ($0) is already up to date, please
     1407send the following data and any information you think might be
     1408pertinent to <config-patches@gnu.org> in order to provide the needed
     1409information to handle your system.
     1410
     1411config.guess timestamp = $timestamp
     1412
     1413uname -m = `(uname -m) 2>/dev/null || echo unknown`
     1414uname -r = `(uname -r) 2>/dev/null || echo unknown`
     1415uname -s = `(uname -s) 2>/dev/null || echo unknown`
     1416uname -v = `(uname -v) 2>/dev/null || echo unknown`
     1417
     1418/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null`
     1419/bin/uname -X     = `(/bin/uname -X) 2>/dev/null`
     1420
     1421hostinfo               = `(hostinfo) 2>/dev/null`
     1422/bin/universe          = `(/bin/universe) 2>/dev/null`
     1423/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null`
     1424/bin/arch              = `(/bin/arch) 2>/dev/null`
     1425/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null`
     1426/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`
     1427
     1428UNAME_MACHINE = ${UNAME_MACHINE}
     1429UNAME_RELEASE = ${UNAME_RELEASE}
     1430UNAME_SYSTEM  = ${UNAME_SYSTEM}
     1431UNAME_VERSION = ${UNAME_VERSION}
     1432EOF
     1433
     1434exit 1
     1435
     1436# Local variables:
     1437# eval: (add-hook 'write-file-hooks 'time-stamp)
     1438# time-stamp-start: "timestamp='"
     1439# time-stamp-format: "%:y-%02m-%02d"
     1440# time-stamp-end: "'"
     1441# End:
  • automake/config.sub

    • Property mode changed from 120000 to 100755
    r275f4b4 rcd7ef0b  
    1 /usr/share/automake-1.15/config.sub
     1#! /bin/sh
     2# Configuration validation subroutine script.
     3#   Copyright 1992-2015 Free Software Foundation, Inc.
     4
     5timestamp='2015-08-20'
     6
     7# This file is free software; you can redistribute it and/or modify it
     8# under the terms of the GNU General Public License as published by
     9# the Free Software Foundation; either version 3 of the License, or
     10# (at your option) any later version.
     11#
     12# This program is distributed in the hope that it will be useful, but
     13# WITHOUT ANY WARRANTY; without even the implied warranty of
     14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15# General Public License for more details.
     16#
     17# You should have received a copy of the GNU General Public License
     18# along with this program; if not, see <http://www.gnu.org/licenses/>.
     19#
     20# As a special exception to the GNU General Public License, if you
     21# distribute this file as part of a program that contains a
     22# configuration script generated by Autoconf, you may include it under
     23# the same distribution terms that you use for the rest of that
     24# program.  This Exception is an additional permission under section 7
     25# of the GNU General Public License, version 3 ("GPLv3").
     26
     27
     28# Please send patches to <config-patches@gnu.org>.
     29#
     30# Configuration subroutine to validate and canonicalize a configuration type.
     31# Supply the specified configuration type as an argument.
     32# If it is invalid, we print an error message on stderr and exit with code 1.
     33# Otherwise, we print the canonical config type on stdout and succeed.
     34
     35# You can get the latest version of this script from:
     36# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
     37
     38# This file is supposed to be the same for all GNU packages
     39# and recognize all the CPU types, system types and aliases
     40# that are meaningful with *any* GNU software.
     41# Each package is responsible for reporting which valid configurations
     42# it does not support.  The user should be able to distinguish
     43# a failure to support a valid configuration from a meaningless
     44# configuration.
     45
     46# The goal of this file is to map all the various variations of a given
     47# machine specification into a single specification in the form:
     48#       CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
     49# or in some cases, the newer four-part form:
     50#       CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
     51# It is wrong to echo any other type of specification.
     52
     53me=`echo "$0" | sed -e 's,.*/,,'`
     54
     55usage="\
     56Usage: $0 [OPTION] CPU-MFR-OPSYS
     57       $0 [OPTION] ALIAS
     58
     59Canonicalize a configuration name.
     60
     61Operation modes:
     62  -h, --help         print this help, then exit
     63  -t, --time-stamp   print date of last modification, then exit
     64  -v, --version      print version number, then exit
     65
     66Report bugs and patches to <config-patches@gnu.org>."
     67
     68version="\
     69GNU config.sub ($timestamp)
     70
     71Copyright 1992-2015 Free Software Foundation, Inc.
     72
     73This is free software; see the source for copying conditions.  There is NO
     74warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
     75
     76help="
     77Try \`$me --help' for more information."
     78
     79# Parse command line
     80while test $# -gt 0 ; do
     81  case $1 in
     82    --time-stamp | --time* | -t )
     83       echo "$timestamp" ; exit ;;
     84    --version | -v )
     85       echo "$version" ; exit ;;
     86    --help | --h* | -h )
     87       echo "$usage"; exit ;;
     88    -- )     # Stop option processing
     89       shift; break ;;
     90    - ) # Use stdin as input.
     91       break ;;
     92    -* )
     93       echo "$me: invalid option $1$help"
     94       exit 1 ;;
     95
     96    *local*)
     97       # First pass through any local machine types.
     98       echo $1
     99       exit ;;
     100
     101    * )
     102       break ;;
     103  esac
     104done
     105
     106case $# in
     107 0) echo "$me: missing argument$help" >&2
     108    exit 1;;
     109 1) ;;
     110 *) echo "$me: too many arguments$help" >&2
     111    exit 1;;
     112esac
     113
     114# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
     115# Here we must recognize all the valid KERNEL-OS combinations.
     116maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
     117case $maybe_os in
     118  nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
     119  linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
     120  knetbsd*-gnu* | netbsd*-gnu* | netbsd*-eabi* | \
     121  kopensolaris*-gnu* | \
     122  storm-chaos* | os2-emx* | rtmk-nova*)
     123    os=-$maybe_os
     124    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
     125    ;;
     126  android-linux)
     127    os=-linux-android
     128    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown
     129    ;;
     130  *)
     131    basic_machine=`echo $1 | sed 's/-[^-]*$//'`
     132    if [ $basic_machine != $1 ]
     133    then os=`echo $1 | sed 's/.*-/-/'`
     134    else os=; fi
     135    ;;
     136esac
     137
     138### Let's recognize common machines as not being operating systems so
     139### that things like config.sub decstation-3100 work.  We also
     140### recognize some manufacturers as not being operating systems, so we
     141### can provide default operating systems below.
     142case $os in
     143        -sun*os*)
     144                # Prevent following clause from handling this invalid input.
     145                ;;
     146        -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
     147        -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
     148        -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
     149        -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
     150        -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
     151        -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
     152        -apple | -axis | -knuth | -cray | -microblaze*)
     153                os=
     154                basic_machine=$1
     155                ;;
     156        -bluegene*)
     157                os=-cnk
     158                ;;
     159        -sim | -cisco | -oki | -wec | -winbond)
     160                os=
     161                basic_machine=$1
     162                ;;
     163        -scout)
     164                ;;
     165        -wrs)
     166                os=-vxworks
     167                basic_machine=$1
     168                ;;
     169        -chorusos*)
     170                os=-chorusos
     171                basic_machine=$1
     172                ;;
     173        -chorusrdb)
     174                os=-chorusrdb
     175                basic_machine=$1
     176                ;;
     177        -hiux*)
     178                os=-hiuxwe2
     179                ;;
     180        -sco6)
     181                os=-sco5v6
     182                basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
     183                ;;
     184        -sco5)
     185                os=-sco3.2v5
     186                basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
     187                ;;
     188        -sco4)
     189                os=-sco3.2v4
     190                basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
     191                ;;
     192        -sco3.2.[4-9]*)
     193                os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
     194                basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
     195                ;;
     196        -sco3.2v[4-9]*)
     197                # Don't forget version if it is 3.2v4 or newer.
     198                basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
     199                ;;
     200        -sco5v6*)
     201                # Don't forget version if it is 3.2v4 or newer.
     202                basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
     203                ;;
     204        -sco*)
     205                os=-sco3.2v2
     206                basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
     207                ;;
     208        -udk*)
     209                basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
     210                ;;
     211        -isc)
     212                os=-isc2.2
     213                basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
     214                ;;
     215        -clix*)
     216                basic_machine=clipper-intergraph
     217                ;;
     218        -isc*)
     219                basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
     220                ;;
     221        -lynx*178)
     222                os=-lynxos178
     223                ;;
     224        -lynx*5)
     225                os=-lynxos5
     226                ;;
     227        -lynx*)
     228                os=-lynxos
     229                ;;
     230        -ptx*)
     231                basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
     232                ;;
     233        -windowsnt*)
     234                os=`echo $os | sed -e 's/windowsnt/winnt/'`
     235                ;;
     236        -psos*)
     237                os=-psos
     238                ;;
     239        -mint | -mint[0-9]*)
     240                basic_machine=m68k-atari
     241                os=-mint
     242                ;;
     243esac
     244
     245# Decode aliases for certain CPU-COMPANY combinations.
     246case $basic_machine in
     247        # Recognize the basic CPU types without company name.
     248        # Some are omitted here because they have special meanings below.
     249        1750a | 580 \
     250        | a29k \
     251        | aarch64 | aarch64_be \
     252        | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
     253        | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
     254        | am33_2.0 \
     255        | arc | arceb \
     256        | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
     257        | avr | avr32 \
     258        | ba \
     259        | be32 | be64 \
     260        | bfin \
     261        | c4x | c8051 | clipper \
     262        | d10v | d30v | dlx | dsp16xx \
     263        | e2k | epiphany \
     264        | fido | fr30 | frv | ft32 \
     265        | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
     266        | hexagon \
     267        | i370 | i860 | i960 | ia64 \
     268        | ip2k | iq2000 \
     269        | k1om \
     270        | le32 | le64 \
     271        | lm32 \
     272        | m32c | m32r | m32rle | m68000 | m68k | m88k \
     273        | maxq | mb | microblaze | microblazeel | mcore | mep | metag \
     274        | mips | mipsbe | mipseb | mipsel | mipsle \
     275        | mips16 \
     276        | mips64 | mips64el \
     277        | mips64octeon | mips64octeonel \
     278        | mips64orion | mips64orionel \
     279        | mips64r5900 | mips64r5900el \
     280        | mips64vr | mips64vrel \
     281        | mips64vr4100 | mips64vr4100el \
     282        | mips64vr4300 | mips64vr4300el \
     283        | mips64vr5000 | mips64vr5000el \
     284        | mips64vr5900 | mips64vr5900el \
     285        | mipsisa32 | mipsisa32el \
     286        | mipsisa32r2 | mipsisa32r2el \
     287        | mipsisa32r6 | mipsisa32r6el \
     288        | mipsisa64 | mipsisa64el \
     289        | mipsisa64r2 | mipsisa64r2el \
     290        | mipsisa64r6 | mipsisa64r6el \
     291        | mipsisa64sb1 | mipsisa64sb1el \
     292        | mipsisa64sr71k | mipsisa64sr71kel \
     293        | mipsr5900 | mipsr5900el \
     294        | mipstx39 | mipstx39el \
     295        | mn10200 | mn10300 \
     296        | moxie \
     297        | mt \
     298        | msp430 \
     299        | nds32 | nds32le | nds32be \
     300        | nios | nios2 | nios2eb | nios2el \
     301        | ns16k | ns32k \
     302        | open8 | or1k | or1knd | or32 \
     303        | pdp10 | pdp11 | pj | pjl \
     304        | powerpc | powerpc64 | powerpc64le | powerpcle \
     305        | pyramid \
     306        | riscv32 | riscv64 \
     307        | rl78 | rx \
     308        | score \
     309        | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[234]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
     310        | sh64 | sh64le \
     311        | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
     312        | sparcv8 | sparcv9 | sparcv9b | sparcv9v \
     313        | spu \
     314        | tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
     315        | ubicom32 \
     316        | v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
     317        | visium \
     318        | we32k \
     319        | x86 | xc16x | xstormy16 | xtensa \
     320        | z8k | z80)
     321                basic_machine=$basic_machine-unknown
     322                ;;
     323        c54x)
     324                basic_machine=tic54x-unknown
     325                ;;
     326        c55x)
     327                basic_machine=tic55x-unknown
     328                ;;
     329        c6x)
     330                basic_machine=tic6x-unknown
     331                ;;
     332        leon|leon[3-9])
     333                basic_machine=sparc-$basic_machine
     334                ;;
     335        m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip)
     336                basic_machine=$basic_machine-unknown
     337                os=-none
     338                ;;
     339        m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
     340                ;;
     341        ms1)
     342                basic_machine=mt-unknown
     343                ;;
     344
     345        strongarm | thumb | xscale)
     346                basic_machine=arm-unknown
     347                ;;
     348        xgate)
     349                basic_machine=$basic_machine-unknown
     350                os=-none
     351                ;;
     352        xscaleeb)
     353                basic_machine=armeb-unknown
     354                ;;
     355
     356        xscaleel)
     357                basic_machine=armel-unknown
     358                ;;
     359
     360        # We use `pc' rather than `unknown'
     361        # because (1) that's what they normally are, and
     362        # (2) the word "unknown" tends to confuse beginning users.
     363        i*86 | x86_64)
     364          basic_machine=$basic_machine-pc
     365          ;;
     366        # Object if more than one company name word.
     367        *-*-*)
     368                echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
     369                exit 1
     370                ;;
     371        # Recognize the basic CPU types with company name.
     372        580-* \
     373        | a29k-* \
     374        | aarch64-* | aarch64_be-* \
     375        | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
     376        | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
     377        | alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
     378        | arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
     379        | avr-* | avr32-* \
     380        | ba-* \
     381        | be32-* | be64-* \
     382        | bfin-* | bs2000-* \
     383        | c[123]* | c30-* | [cjt]90-* | c4x-* \
     384        | c8051-* | clipper-* | craynv-* | cydra-* \
     385        | d10v-* | d30v-* | dlx-* \
     386        | e2k-* | elxsi-* \
     387        | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
     388        | h8300-* | h8500-* \
     389        | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
     390        | hexagon-* \
     391        | i*86-* | i860-* | i960-* | ia64-* \
     392        | ip2k-* | iq2000-* \
     393        | k1om-* \
     394        | le32-* | le64-* \
     395        | lm32-* \
     396        | m32c-* | m32r-* | m32rle-* \
     397        | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
     398        | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
     399        | microblaze-* | microblazeel-* \
     400        | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
     401        | mips16-* \
     402        | mips64-* | mips64el-* \
     403        | mips64octeon-* | mips64octeonel-* \
     404        | mips64orion-* | mips64orionel-* \
     405        | mips64r5900-* | mips64r5900el-* \
     406        | mips64vr-* | mips64vrel-* \
     407        | mips64vr4100-* | mips64vr4100el-* \
     408        | mips64vr4300-* | mips64vr4300el-* \
     409        | mips64vr5000-* | mips64vr5000el-* \
     410        | mips64vr5900-* | mips64vr5900el-* \
     411        | mipsisa32-* | mipsisa32el-* \
     412        | mipsisa32r2-* | mipsisa32r2el-* \
     413        | mipsisa32r6-* | mipsisa32r6el-* \
     414        | mipsisa64-* | mipsisa64el-* \
     415        | mipsisa64r2-* | mipsisa64r2el-* \
     416        | mipsisa64r6-* | mipsisa64r6el-* \
     417        | mipsisa64sb1-* | mipsisa64sb1el-* \
     418        | mipsisa64sr71k-* | mipsisa64sr71kel-* \
     419        | mipsr5900-* | mipsr5900el-* \
     420        | mipstx39-* | mipstx39el-* \
     421        | mmix-* \
     422        | mt-* \
     423        | msp430-* \
     424        | nds32-* | nds32le-* | nds32be-* \
     425        | nios-* | nios2-* | nios2eb-* | nios2el-* \
     426        | none-* | np1-* | ns16k-* | ns32k-* \
     427        | open8-* \
     428        | or1k*-* \
     429        | orion-* \
     430        | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
     431        | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
     432        | pyramid-* \
     433        | riscv32-* | riscv64-* \
     434        | rl78-* | romp-* | rs6000-* | rx-* \
     435        | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
     436        | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
     437        | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
     438        | sparclite-* \
     439        | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx*-* \
     440        | tahoe-* \
     441        | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
     442        | tile*-* \
     443        | tron-* \
     444        | ubicom32-* \
     445        | v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
     446        | vax-* \
     447        | visium-* \
     448        | we32k-* \
     449        | x86-* | x86_64-* | xc16x-* | xps100-* \
     450        | xstormy16-* | xtensa*-* \
     451        | ymp-* \
     452        | z8k-* | z80-*)
     453                ;;
     454        # Recognize the basic CPU types without company name, with glob match.
     455        xtensa*)
     456                basic_machine=$basic_machine-unknown
     457                ;;
     458        # Recognize the various machine names and aliases which stand
     459        # for a CPU type and a company and sometimes even an OS.
     460        386bsd)
     461                basic_machine=i386-unknown
     462                os=-bsd
     463                ;;
     464        3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
     465                basic_machine=m68000-att
     466                ;;
     467        3b*)
     468                basic_machine=we32k-att
     469                ;;
     470        a29khif)
     471                basic_machine=a29k-amd
     472                os=-udi
     473                ;;
     474        abacus)
     475                basic_machine=abacus-unknown
     476                ;;
     477        adobe68k)
     478                basic_machine=m68010-adobe
     479                os=-scout
     480                ;;
     481        alliant | fx80)
     482                basic_machine=fx80-alliant
     483                ;;
     484        altos | altos3068)
     485                basic_machine=m68k-altos
     486                ;;
     487        am29k)
     488                basic_machine=a29k-none
     489                os=-bsd
     490                ;;
     491        amd64)
     492                basic_machine=x86_64-pc
     493                ;;
     494        amd64-*)
     495                basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
     496                ;;
     497        amdahl)
     498                basic_machine=580-amdahl
     499                os=-sysv
     500                ;;
     501        amiga | amiga-*)
     502                basic_machine=m68k-unknown
     503                ;;
     504        amigaos | amigados)
     505                basic_machine=m68k-unknown
     506                os=-amigaos
     507                ;;
     508        amigaunix | amix)
     509                basic_machine=m68k-unknown
     510                os=-sysv4
     511                ;;
     512        apollo68)
     513                basic_machine=m68k-apollo
     514                os=-sysv
     515                ;;
     516        apollo68bsd)
     517                basic_machine=m68k-apollo
     518                os=-bsd
     519                ;;
     520        aros)
     521                basic_machine=i386-pc
     522                os=-aros
     523                ;;
     524        asmjs)
     525                basic_machine=asmjs-unknown
     526                ;;
     527        aux)
     528                basic_machine=m68k-apple
     529                os=-aux
     530                ;;
     531        balance)
     532                basic_machine=ns32k-sequent
     533                os=-dynix
     534                ;;
     535        blackfin)
     536                basic_machine=bfin-unknown
     537                os=-linux
     538                ;;
     539        blackfin-*)
     540                basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
     541                os=-linux
     542                ;;
     543        bluegene*)
     544                basic_machine=powerpc-ibm
     545                os=-cnk
     546                ;;
     547        c54x-*)
     548                basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'`
     549                ;;
     550        c55x-*)
     551                basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'`
     552                ;;
     553        c6x-*)
     554                basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'`
     555                ;;
     556        c90)
     557                basic_machine=c90-cray
     558                os=-unicos
     559                ;;
     560        cegcc)
     561                basic_machine=arm-unknown
     562                os=-cegcc
     563                ;;
     564        convex-c1)
     565                basic_machine=c1-convex
     566                os=-bsd
     567                ;;
     568        convex-c2)
     569                basic_machine=c2-convex
     570                os=-bsd
     571                ;;
     572        convex-c32)
     573                basic_machine=c32-convex
     574                os=-bsd
     575                ;;
     576        convex-c34)
     577                basic_machine=c34-convex
     578                os=-bsd
     579                ;;
     580        convex-c38)
     581                basic_machine=c38-convex
     582                os=-bsd
     583                ;;
     584        cray | j90)
     585                basic_machine=j90-cray
     586                os=-unicos
     587                ;;
     588        craynv)
     589                basic_machine=craynv-cray
     590                os=-unicosmp
     591                ;;
     592        cr16 | cr16-*)
     593                basic_machine=cr16-unknown
     594                os=-elf
     595                ;;
     596        crds | unos)
     597                basic_machine=m68k-crds
     598                ;;
     599        crisv32 | crisv32-* | etraxfs*)
     600                basic_machine=crisv32-axis
     601                ;;
     602        cris | cris-* | etrax*)
     603                basic_machine=cris-axis
     604                ;;
     605        crx)
     606                basic_machine=crx-unknown
     607                os=-elf
     608                ;;
     609        da30 | da30-*)
     610                basic_machine=m68k-da30
     611                ;;
     612        decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
     613                basic_machine=mips-dec
     614                ;;
     615        decsystem10* | dec10*)
     616                basic_machine=pdp10-dec
     617                os=-tops10
     618                ;;
     619        decsystem20* | dec20*)
     620                basic_machine=pdp10-dec
     621                os=-tops20
     622                ;;
     623        delta | 3300 | motorola-3300 | motorola-delta \
     624              | 3300-motorola | delta-motorola)
     625                basic_machine=m68k-motorola
     626                ;;
     627        delta88)
     628                basic_machine=m88k-motorola
     629                os=-sysv3
     630                ;;
     631        dicos)
     632                basic_machine=i686-pc
     633                os=-dicos
     634                ;;
     635        djgpp)
     636                basic_machine=i586-pc
     637                os=-msdosdjgpp
     638                ;;
     639        dpx20 | dpx20-*)
     640                basic_machine=rs6000-bull
     641                os=-bosx
     642                ;;
     643        dpx2* | dpx2*-bull)
     644                basic_machine=m68k-bull
     645                os=-sysv3
     646                ;;
     647        ebmon29k)
     648                basic_machine=a29k-amd
     649                os=-ebmon
     650                ;;
     651        elxsi)
     652                basic_machine=elxsi-elxsi
     653                os=-bsd
     654                ;;
     655        encore | umax | mmax)
     656                basic_machine=ns32k-encore
     657                ;;
     658        es1800 | OSE68k | ose68k | ose | OSE)
     659                basic_machine=m68k-ericsson
     660                os=-ose
     661                ;;
     662        fx2800)
     663                basic_machine=i860-alliant
     664                ;;
     665        genix)
     666                basic_machine=ns32k-ns
     667                ;;
     668        gmicro)
     669                basic_machine=tron-gmicro
     670                os=-sysv
     671                ;;
     672        go32)
     673                basic_machine=i386-pc
     674                os=-go32
     675                ;;
     676        h3050r* | hiux*)
     677                basic_machine=hppa1.1-hitachi
     678                os=-hiuxwe2
     679                ;;
     680        h8300hms)
     681                basic_machine=h8300-hitachi
     682                os=-hms
     683                ;;
     684        h8300xray)
     685                basic_machine=h8300-hitachi
     686                os=-xray
     687                ;;
     688        h8500hms)
     689                basic_machine=h8500-hitachi
     690                os=-hms
     691                ;;
     692        harris)
     693                basic_machine=m88k-harris
     694                os=-sysv3
     695                ;;
     696        hp300-*)
     697                basic_machine=m68k-hp
     698                ;;
     699        hp300bsd)
     700                basic_machine=m68k-hp
     701                os=-bsd
     702                ;;
     703        hp300hpux)
     704                basic_machine=m68k-hp
     705                os=-hpux
     706                ;;
     707        hp3k9[0-9][0-9] | hp9[0-9][0-9])
     708                basic_machine=hppa1.0-hp
     709                ;;
     710        hp9k2[0-9][0-9] | hp9k31[0-9])
     711                basic_machine=m68000-hp
     712                ;;
     713        hp9k3[2-9][0-9])
     714                basic_machine=m68k-hp
     715                ;;
     716        hp9k6[0-9][0-9] | hp6[0-9][0-9])
     717                basic_machine=hppa1.0-hp
     718                ;;
     719        hp9k7[0-79][0-9] | hp7[0-79][0-9])
     720                basic_machine=hppa1.1-hp
     721                ;;
     722        hp9k78[0-9] | hp78[0-9])
     723                # FIXME: really hppa2.0-hp
     724                basic_machine=hppa1.1-hp
     725                ;;
     726        hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
     727                # FIXME: really hppa2.0-hp
     728                basic_machine=hppa1.1-hp
     729                ;;
     730        hp9k8[0-9][13679] | hp8[0-9][13679])
     731                basic_machine=hppa1.1-hp
     732                ;;
     733        hp9k8[0-9][0-9] | hp8[0-9][0-9])
     734                basic_machine=hppa1.0-hp
     735                ;;
     736        hppa-next)
     737                os=-nextstep3
     738                ;;
     739        hppaosf)
     740                basic_machine=hppa1.1-hp
     741                os=-osf
     742                ;;
     743        hppro)
     744                basic_machine=hppa1.1-hp
     745                os=-proelf
     746                ;;
     747        i370-ibm* | ibm*)
     748                basic_machine=i370-ibm
     749                ;;
     750        i*86v32)
     751                basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
     752                os=-sysv32
     753                ;;
     754        i*86v4*)
     755                basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
     756                os=-sysv4
     757                ;;
     758        i*86v)
     759                basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
     760                os=-sysv
     761                ;;
     762        i*86sol2)
     763                basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
     764                os=-solaris2
     765                ;;
     766        i386mach)
     767                basic_machine=i386-mach
     768                os=-mach
     769                ;;
     770        i386-vsta | vsta)
     771                basic_machine=i386-unknown
     772                os=-vsta
     773                ;;
     774        iris | iris4d)
     775                basic_machine=mips-sgi
     776                case $os in
     777                    -irix*)
     778                        ;;
     779                    *)
     780                        os=-irix4
     781                        ;;
     782                esac
     783                ;;
     784        isi68 | isi)
     785                basic_machine=m68k-isi
     786                os=-sysv
     787                ;;
     788        leon-*|leon[3-9]-*)
     789                basic_machine=sparc-`echo $basic_machine | sed 's/-.*//'`
     790                ;;
     791        m68knommu)
     792                basic_machine=m68k-unknown
     793                os=-linux
     794                ;;
     795        m68knommu-*)
     796                basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`
     797                os=-linux
     798                ;;
     799        m88k-omron*)
     800                basic_machine=m88k-omron
     801                ;;
     802        magnum | m3230)
     803                basic_machine=mips-mips
     804                os=-sysv
     805                ;;
     806        merlin)
     807                basic_machine=ns32k-utek
     808                os=-sysv
     809                ;;
     810        microblaze*)
     811                basic_machine=microblaze-xilinx
     812                ;;
     813        mingw64)
     814                basic_machine=x86_64-pc
     815                os=-mingw64
     816                ;;
     817        mingw32)
     818                basic_machine=i686-pc
     819                os=-mingw32
     820                ;;
     821        mingw32ce)
     822                basic_machine=arm-unknown
     823                os=-mingw32ce
     824                ;;
     825        miniframe)
     826                basic_machine=m68000-convergent
     827                ;;
     828        *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
     829                basic_machine=m68k-atari
     830                os=-mint
     831                ;;
     832        mips3*-*)
     833                basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
     834                ;;
     835        mips3*)
     836                basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
     837                ;;
     838        monitor)
     839                basic_machine=m68k-rom68k
     840                os=-coff
     841                ;;
     842        morphos)
     843                basic_machine=powerpc-unknown
     844                os=-morphos
     845                ;;
     846        moxiebox)
     847                basic_machine=moxie-unknown
     848                os=-moxiebox
     849                ;;
     850        msdos)
     851                basic_machine=i386-pc
     852                os=-msdos
     853                ;;
     854        ms1-*)
     855                basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
     856                ;;
     857        msys)
     858                basic_machine=i686-pc
     859                os=-msys
     860                ;;
     861        mvs)
     862                basic_machine=i370-ibm
     863                os=-mvs
     864                ;;
     865        nacl)
     866                basic_machine=le32-unknown
     867                os=-nacl
     868                ;;
     869        ncr3000)
     870                basic_machine=i486-ncr
     871                os=-sysv4
     872                ;;
     873        netbsd386)
     874                basic_machine=i386-unknown
     875                os=-netbsd
     876                ;;
     877        netwinder)
     878                basic_machine=armv4l-rebel
     879                os=-linux
     880                ;;
     881        news | news700 | news800 | news900)
     882                basic_machine=m68k-sony
     883                os=-newsos
     884                ;;
     885        news1000)
     886                basic_machine=m68030-sony
     887                os=-newsos
     888                ;;
     889        news-3600 | risc-news)
     890                basic_machine=mips-sony
     891                os=-newsos
     892                ;;
     893        necv70)
     894                basic_machine=v70-nec
     895                os=-sysv
     896                ;;
     897        next | m*-next )
     898                basic_machine=m68k-next
     899                case $os in
     900                    -nextstep* )
     901                        ;;
     902                    -ns2*)
     903                      os=-nextstep2
     904                        ;;
     905                    *)
     906                      os=-nextstep3
     907                        ;;
     908                esac
     909                ;;
     910        nh3000)
     911                basic_machine=m68k-harris
     912                os=-cxux
     913                ;;
     914        nh[45]000)
     915                basic_machine=m88k-harris
     916                os=-cxux
     917                ;;
     918        nindy960)
     919                basic_machine=i960-intel
     920                os=-nindy
     921                ;;
     922        mon960)
     923                basic_machine=i960-intel
     924                os=-mon960
     925                ;;
     926        nonstopux)
     927                basic_machine=mips-compaq
     928                os=-nonstopux
     929                ;;
     930        np1)
     931                basic_machine=np1-gould
     932                ;;
     933        neo-tandem)
     934                basic_machine=neo-tandem
     935                ;;
     936        nse-tandem)
     937                basic_machine=nse-tandem
     938                ;;
     939        nsr-tandem)
     940                basic_machine=nsr-tandem
     941                ;;
     942        op50n-* | op60c-*)
     943                basic_machine=hppa1.1-oki
     944                os=-proelf
     945                ;;
     946        openrisc | openrisc-*)
     947                basic_machine=or32-unknown
     948                ;;
     949        os400)
     950                basic_machine=powerpc-ibm
     951                os=-os400
     952                ;;
     953        OSE68000 | ose68000)
     954                basic_machine=m68000-ericsson
     955                os=-ose
     956                ;;
     957        os68k)
     958                basic_machine=m68k-none
     959                os=-os68k
     960                ;;
     961        pa-hitachi)
     962                basic_machine=hppa1.1-hitachi
     963                os=-hiuxwe2
     964                ;;
     965        paragon)
     966                basic_machine=i860-intel
     967                os=-osf
     968                ;;
     969        parisc)
     970                basic_machine=hppa-unknown
     971                os=-linux
     972                ;;
     973        parisc-*)
     974                basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`
     975                os=-linux
     976                ;;
     977        pbd)
     978                basic_machine=sparc-tti
     979                ;;
     980        pbb)
     981                basic_machine=m68k-tti
     982                ;;
     983        pc532 | pc532-*)
     984                basic_machine=ns32k-pc532
     985                ;;
     986        pc98)
     987                basic_machine=i386-pc
     988                ;;
     989        pc98-*)
     990                basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
     991                ;;
     992        pentium | p5 | k5 | k6 | nexgen | viac3)
     993                basic_machine=i586-pc
     994                ;;
     995        pentiumpro | p6 | 6x86 | athlon | athlon_*)
     996                basic_machine=i686-pc
     997                ;;
     998        pentiumii | pentium2 | pentiumiii | pentium3)
     999                basic_machine=i686-pc
     1000                ;;
     1001        pentium4)
     1002                basic_machine=i786-pc
     1003                ;;
     1004        pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
     1005                basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
     1006                ;;
     1007        pentiumpro-* | p6-* | 6x86-* | athlon-*)
     1008                basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
     1009                ;;
     1010        pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
     1011                basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
     1012                ;;
     1013        pentium4-*)
     1014                basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
     1015                ;;
     1016        pn)
     1017                basic_machine=pn-gould
     1018                ;;
     1019        power)  basic_machine=power-ibm
     1020                ;;
     1021        ppc | ppcbe)    basic_machine=powerpc-unknown
     1022                ;;
     1023        ppc-* | ppcbe-*)
     1024                basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
     1025                ;;
     1026        ppcle | powerpclittle | ppc-le | powerpc-little)
     1027                basic_machine=powerpcle-unknown
     1028                ;;
     1029        ppcle-* | powerpclittle-*)
     1030                basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
     1031                ;;
     1032        ppc64)  basic_machine=powerpc64-unknown
     1033                ;;
     1034        ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
     1035                ;;
     1036        ppc64le | powerpc64little | ppc64-le | powerpc64-little)
     1037                basic_machine=powerpc64le-unknown
     1038                ;;
     1039        ppc64le-* | powerpc64little-*)
     1040                basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
     1041                ;;
     1042        ps2)
     1043                basic_machine=i386-ibm
     1044                ;;
     1045        pw32)
     1046                basic_machine=i586-unknown
     1047                os=-pw32
     1048                ;;
     1049        rdos | rdos64)
     1050                basic_machine=x86_64-pc
     1051                os=-rdos
     1052                ;;
     1053        rdos32)
     1054                basic_machine=i386-pc
     1055                os=-rdos
     1056                ;;
     1057        rom68k)
     1058                basic_machine=m68k-rom68k
     1059                os=-coff
     1060                ;;
     1061        rm[46]00)
     1062                basic_machine=mips-siemens
     1063                ;;
     1064        rtpc | rtpc-*)
     1065                basic_machine=romp-ibm
     1066                ;;
     1067        s390 | s390-*)
     1068                basic_machine=s390-ibm
     1069                ;;
     1070        s390x | s390x-*)
     1071                basic_machine=s390x-ibm
     1072                ;;
     1073        sa29200)
     1074                basic_machine=a29k-amd
     1075                os=-udi
     1076                ;;
     1077        sb1)
     1078                basic_machine=mipsisa64sb1-unknown
     1079                ;;
     1080        sb1el)
     1081                basic_machine=mipsisa64sb1el-unknown
     1082                ;;
     1083        sde)
     1084                basic_machine=mipsisa32-sde
     1085                os=-elf
     1086                ;;
     1087        sei)
     1088                basic_machine=mips-sei
     1089                os=-seiux
     1090                ;;
     1091        sequent)
     1092                basic_machine=i386-sequent
     1093                ;;
     1094        sh)
     1095                basic_machine=sh-hitachi
     1096                os=-hms
     1097                ;;
     1098        sh5el)
     1099                basic_machine=sh5le-unknown
     1100                ;;
     1101        sh64)
     1102                basic_machine=sh64-unknown
     1103                ;;
     1104        sparclite-wrs | simso-wrs)
     1105                basic_machine=sparclite-wrs
     1106                os=-vxworks
     1107                ;;
     1108        sps7)
     1109                basic_machine=m68k-bull
     1110                os=-sysv2
     1111                ;;
     1112        spur)
     1113                basic_machine=spur-unknown
     1114                ;;
     1115        st2000)
     1116                basic_machine=m68k-tandem
     1117                ;;
     1118        stratus)
     1119                basic_machine=i860-stratus
     1120                os=-sysv4
     1121                ;;
     1122        strongarm-* | thumb-*)
     1123                basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'`
     1124                ;;
     1125        sun2)
     1126                basic_machine=m68000-sun
     1127                ;;
     1128        sun2os3)
     1129                basic_machine=m68000-sun
     1130                os=-sunos3
     1131                ;;
     1132        sun2os4)
     1133                basic_machine=m68000-sun
     1134                os=-sunos4
     1135                ;;
     1136        sun3os3)
     1137                basic_machine=m68k-sun
     1138                os=-sunos3
     1139                ;;
     1140        sun3os4)
     1141                basic_machine=m68k-sun
     1142                os=-sunos4
     1143                ;;
     1144        sun4os3)
     1145                basic_machine=sparc-sun
     1146                os=-sunos3
     1147                ;;
     1148        sun4os4)
     1149                basic_machine=sparc-sun
     1150                os=-sunos4
     1151                ;;
     1152        sun4sol2)
     1153                basic_machine=sparc-sun
     1154                os=-solaris2
     1155                ;;
     1156        sun3 | sun3-*)
     1157                basic_machine=m68k-sun
     1158                ;;
     1159        sun4)
     1160                basic_machine=sparc-sun
     1161                ;;
     1162        sun386 | sun386i | roadrunner)
     1163                basic_machine=i386-sun
     1164                ;;
     1165        sv1)
     1166                basic_machine=sv1-cray
     1167                os=-unicos
     1168                ;;
     1169        symmetry)
     1170                basic_machine=i386-sequent
     1171                os=-dynix
     1172                ;;
     1173        t3e)
     1174                basic_machine=alphaev5-cray
     1175                os=-unicos
     1176                ;;
     1177        t90)
     1178                basic_machine=t90-cray
     1179                os=-unicos
     1180                ;;
     1181        tile*)
     1182                basic_machine=$basic_machine-unknown
     1183                os=-linux-gnu
     1184                ;;
     1185        tx39)
     1186                basic_machine=mipstx39-unknown
     1187                ;;
     1188        tx39el)
     1189                basic_machine=mipstx39el-unknown
     1190                ;;
     1191        toad1)
     1192                basic_machine=pdp10-xkl
     1193                os=-tops20
     1194                ;;
     1195        tower | tower-32)
     1196                basic_machine=m68k-ncr
     1197                ;;
     1198        tpf)
     1199                basic_machine=s390x-ibm
     1200                os=-tpf
     1201                ;;
     1202        udi29k)
     1203                basic_machine=a29k-amd
     1204                os=-udi
     1205                ;;
     1206        ultra3)
     1207                basic_machine=a29k-nyu
     1208                os=-sym1
     1209                ;;
     1210        v810 | necv810)
     1211                basic_machine=v810-nec
     1212                os=-none
     1213                ;;
     1214        vaxv)
     1215                basic_machine=vax-dec
     1216                os=-sysv
     1217                ;;
     1218        vms)
     1219                basic_machine=vax-dec
     1220                os=-vms
     1221                ;;
     1222        vpp*|vx|vx-*)
     1223                basic_machine=f301-fujitsu
     1224                ;;
     1225        vxworks960)
     1226                basic_machine=i960-wrs
     1227                os=-vxworks
     1228                ;;
     1229        vxworks68)
     1230                basic_machine=m68k-wrs
     1231                os=-vxworks
     1232                ;;
     1233        vxworks29k)
     1234                basic_machine=a29k-wrs
     1235                os=-vxworks
     1236                ;;
     1237        w65*)
     1238                basic_machine=w65-wdc
     1239                os=-none
     1240                ;;
     1241        w89k-*)
     1242                basic_machine=hppa1.1-winbond
     1243                os=-proelf
     1244                ;;
     1245        xbox)
     1246                basic_machine=i686-pc
     1247                os=-mingw32
     1248                ;;
     1249        xps | xps100)
     1250                basic_machine=xps100-honeywell
     1251                ;;
     1252        xscale-* | xscalee[bl]-*)
     1253                basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'`
     1254                ;;
     1255        ymp)
     1256                basic_machine=ymp-cray
     1257                os=-unicos
     1258                ;;
     1259        z8k-*-coff)
     1260                basic_machine=z8k-unknown
     1261                os=-sim
     1262                ;;
     1263        z80-*-coff)
     1264                basic_machine=z80-unknown
     1265                os=-sim
     1266                ;;
     1267        none)
     1268                basic_machine=none-none
     1269                os=-none
     1270                ;;
     1271
     1272# Here we handle the default manufacturer of certain CPU types.  It is in
     1273# some cases the only manufacturer, in others, it is the most popular.
     1274        w89k)
     1275                basic_machine=hppa1.1-winbond
     1276                ;;
     1277        op50n)
     1278                basic_machine=hppa1.1-oki
     1279                ;;
     1280        op60c)
     1281                basic_machine=hppa1.1-oki
     1282                ;;
     1283        romp)
     1284                basic_machine=romp-ibm
     1285                ;;
     1286        mmix)
     1287                basic_machine=mmix-knuth
     1288                ;;
     1289        rs6000)
     1290                basic_machine=rs6000-ibm
     1291                ;;
     1292        vax)
     1293                basic_machine=vax-dec
     1294                ;;
     1295        pdp10)
     1296                # there are many clones, so DEC is not a safe bet
     1297                basic_machine=pdp10-unknown
     1298                ;;
     1299        pdp11)
     1300                basic_machine=pdp11-dec
     1301                ;;
     1302        we32k)
     1303                basic_machine=we32k-att
     1304                ;;
     1305        sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
     1306                basic_machine=sh-unknown
     1307                ;;
     1308        sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
     1309                basic_machine=sparc-sun
     1310                ;;
     1311        cydra)
     1312                basic_machine=cydra-cydrome
     1313                ;;
     1314        orion)
     1315                basic_machine=orion-highlevel
     1316                ;;
     1317        orion105)
     1318                basic_machine=clipper-highlevel
     1319                ;;
     1320        mac | mpw | mac-mpw)
     1321                basic_machine=m68k-apple
     1322                ;;
     1323        pmac | pmac-mpw)
     1324                basic_machine=powerpc-apple
     1325                ;;
     1326        *-unknown)
     1327                # Make sure to match an already-canonicalized machine name.
     1328                ;;
     1329        *)
     1330                echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
     1331                exit 1
     1332                ;;
     1333esac
     1334
     1335# Here we canonicalize certain aliases for manufacturers.
     1336case $basic_machine in
     1337        *-digital*)
     1338                basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
     1339                ;;
     1340        *-commodore*)
     1341                basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
     1342                ;;
     1343        *)
     1344                ;;
     1345esac
     1346
     1347# Decode manufacturer-specific aliases for certain operating systems.
     1348
     1349if [ x"$os" != x"" ]
     1350then
     1351case $os in
     1352        # First match some system type aliases
     1353        # that might get confused with valid system types.
     1354        # -solaris* is a basic system type, with this one exception.
     1355        -auroraux)
     1356                os=-auroraux
     1357                ;;
     1358        -solaris1 | -solaris1.*)
     1359                os=`echo $os | sed -e 's|solaris1|sunos4|'`
     1360                ;;
     1361        -solaris)
     1362                os=-solaris2
     1363                ;;
     1364        -svr4*)
     1365                os=-sysv4
     1366                ;;
     1367        -unixware*)
     1368                os=-sysv4.2uw
     1369                ;;
     1370        -gnu/linux*)
     1371                os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
     1372                ;;
     1373        # First accept the basic system types.
     1374        # The portable systems comes first.
     1375        # Each alternative MUST END IN A *, to match a version number.
     1376        # -sysv* is not here because it comes later, after sysvr4.
     1377        -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
     1378              | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
     1379              | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
     1380              | -sym* | -kopensolaris* | -plan9* \
     1381              | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
     1382              | -aos* | -aros* | -cloudabi* | -sortix* \
     1383              | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
     1384              | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
     1385              | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
     1386              | -bitrig* | -openbsd* | -solidbsd* \
     1387              | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
     1388              | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
     1389              | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
     1390              | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
     1391              | -chorusos* | -chorusrdb* | -cegcc* \
     1392              | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
     1393              | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
     1394              | -linux-newlib* | -linux-musl* | -linux-uclibc* \
     1395              | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \
     1396              | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
     1397              | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
     1398              | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
     1399              | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
     1400              | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
     1401              | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
     1402              | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* | -tirtos*)
     1403        # Remember, each alternative MUST END IN *, to match a version number.
     1404                ;;
     1405        -qnx*)
     1406                case $basic_machine in
     1407                    x86-* | i*86-*)
     1408                        ;;
     1409                    *)
     1410                        os=-nto$os
     1411                        ;;
     1412                esac
     1413                ;;
     1414        -nto-qnx*)
     1415                ;;
     1416        -nto*)
     1417                os=`echo $os | sed -e 's|nto|nto-qnx|'`
     1418                ;;
     1419        -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
     1420              | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
     1421              | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
     1422                ;;
     1423        -mac*)
     1424                os=`echo $os | sed -e 's|mac|macos|'`
     1425                ;;
     1426        -linux-dietlibc)
     1427                os=-linux-dietlibc
     1428                ;;
     1429        -linux*)
     1430                os=`echo $os | sed -e 's|linux|linux-gnu|'`
     1431                ;;
     1432        -sunos5*)
     1433                os=`echo $os | sed -e 's|sunos5|solaris2|'`
     1434                ;;
     1435        -sunos6*)
     1436                os=`echo $os | sed -e 's|sunos6|solaris3|'`
     1437                ;;
     1438        -opened*)
     1439                os=-openedition
     1440                ;;
     1441        -os400*)
     1442                os=-os400
     1443                ;;
     1444        -wince*)
     1445                os=-wince
     1446                ;;
     1447        -osfrose*)
     1448                os=-osfrose
     1449                ;;
     1450        -osf*)
     1451                os=-osf
     1452                ;;
     1453        -utek*)
     1454                os=-bsd
     1455                ;;
     1456        -dynix*)
     1457                os=-bsd
     1458                ;;
     1459        -acis*)
     1460                os=-aos
     1461                ;;
     1462        -atheos*)
     1463                os=-atheos
     1464                ;;
     1465        -syllable*)
     1466                os=-syllable
     1467                ;;
     1468        -386bsd)
     1469                os=-bsd
     1470                ;;
     1471        -ctix* | -uts*)
     1472                os=-sysv
     1473                ;;
     1474        -nova*)
     1475                os=-rtmk-nova
     1476                ;;
     1477        -ns2 )
     1478                os=-nextstep2
     1479                ;;
     1480        -nsk*)
     1481                os=-nsk
     1482                ;;
     1483        # Preserve the version number of sinix5.
     1484        -sinix5.*)
     1485                os=`echo $os | sed -e 's|sinix|sysv|'`
     1486                ;;
     1487        -sinix*)
     1488                os=-sysv4
     1489                ;;
     1490        -tpf*)
     1491                os=-tpf
     1492                ;;
     1493        -triton*)
     1494                os=-sysv3
     1495                ;;
     1496        -oss*)
     1497                os=-sysv3
     1498                ;;
     1499        -svr4)
     1500                os=-sysv4
     1501                ;;
     1502        -svr3)
     1503                os=-sysv3
     1504                ;;
     1505        -sysvr4)
     1506                os=-sysv4
     1507                ;;
     1508        # This must come after -sysvr4.
     1509        -sysv*)
     1510                ;;
     1511        -ose*)
     1512                os=-ose
     1513                ;;
     1514        -es1800*)
     1515                os=-ose
     1516                ;;
     1517        -xenix)
     1518                os=-xenix
     1519                ;;
     1520        -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
     1521                os=-mint
     1522                ;;
     1523        -aros*)
     1524                os=-aros
     1525                ;;
     1526        -zvmoe)
     1527                os=-zvmoe
     1528                ;;
     1529        -dicos*)
     1530                os=-dicos
     1531                ;;
     1532        -nacl*)
     1533                ;;
     1534        -none)
     1535                ;;
     1536        *)
     1537                # Get rid of the `-' at the beginning of $os.
     1538                os=`echo $os | sed 's/[^-]*-//'`
     1539                echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
     1540                exit 1
     1541                ;;
     1542esac
     1543else
     1544
     1545# Here we handle the default operating systems that come with various machines.
     1546# The value should be what the vendor currently ships out the door with their
     1547# machine or put another way, the most popular os provided with the machine.
     1548
     1549# Note that if you're going to try to match "-MANUFACTURER" here (say,
     1550# "-sun"), then you have to tell the case statement up towards the top
     1551# that MANUFACTURER isn't an operating system.  Otherwise, code above
     1552# will signal an error saying that MANUFACTURER isn't an operating
     1553# system, and we'll never get to this point.
     1554
     1555case $basic_machine in
     1556        score-*)
     1557                os=-elf
     1558                ;;
     1559        spu-*)
     1560                os=-elf
     1561                ;;
     1562        *-acorn)
     1563                os=-riscix1.2
     1564                ;;
     1565        arm*-rebel)
     1566                os=-linux
     1567                ;;
     1568        arm*-semi)
     1569                os=-aout
     1570                ;;
     1571        c4x-* | tic4x-*)
     1572                os=-coff
     1573                ;;
     1574        c8051-*)
     1575                os=-elf
     1576                ;;
     1577        hexagon-*)
     1578                os=-elf
     1579                ;;
     1580        tic54x-*)
     1581                os=-coff
     1582                ;;
     1583        tic55x-*)
     1584                os=-coff
     1585                ;;
     1586        tic6x-*)
     1587                os=-coff
     1588                ;;
     1589        # This must come before the *-dec entry.
     1590        pdp10-*)
     1591                os=-tops20
     1592                ;;
     1593        pdp11-*)
     1594                os=-none
     1595                ;;
     1596        *-dec | vax-*)
     1597                os=-ultrix4.2
     1598                ;;
     1599        m68*-apollo)
     1600                os=-domain
     1601                ;;
     1602        i386-sun)
     1603                os=-sunos4.0.2
     1604                ;;
     1605        m68000-sun)
     1606                os=-sunos3
     1607                ;;
     1608        m68*-cisco)
     1609                os=-aout
     1610                ;;
     1611        mep-*)
     1612                os=-elf
     1613                ;;
     1614        mips*-cisco)
     1615                os=-elf
     1616                ;;
     1617        mips*-*)
     1618                os=-elf
     1619                ;;
     1620        or32-*)
     1621                os=-coff
     1622                ;;
     1623        *-tti)  # must be before sparc entry or we get the wrong os.
     1624                os=-sysv3
     1625                ;;
     1626        sparc-* | *-sun)
     1627                os=-sunos4.1.1
     1628                ;;
     1629        *-be)
     1630                os=-beos
     1631                ;;
     1632        *-haiku)
     1633                os=-haiku
     1634                ;;
     1635        *-ibm)
     1636                os=-aix
     1637                ;;
     1638        *-knuth)
     1639                os=-mmixware
     1640                ;;
     1641        *-wec)
     1642                os=-proelf
     1643                ;;
     1644        *-winbond)
     1645                os=-proelf
     1646                ;;
     1647        *-oki)
     1648                os=-proelf
     1649                ;;
     1650        *-hp)
     1651                os=-hpux
     1652                ;;
     1653        *-hitachi)
     1654                os=-hiux
     1655                ;;
     1656        i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
     1657                os=-sysv
     1658                ;;
     1659        *-cbm)
     1660                os=-amigaos
     1661                ;;
     1662        *-dg)
     1663                os=-dgux
     1664                ;;
     1665        *-dolphin)
     1666                os=-sysv3
     1667                ;;
     1668        m68k-ccur)
     1669                os=-rtu
     1670                ;;
     1671        m88k-omron*)
     1672                os=-luna
     1673                ;;
     1674        *-next )
     1675                os=-nextstep
     1676                ;;
     1677        *-sequent)
     1678                os=-ptx
     1679                ;;
     1680        *-crds)
     1681                os=-unos
     1682                ;;
     1683        *-ns)
     1684                os=-genix
     1685                ;;
     1686        i370-*)
     1687                os=-mvs
     1688                ;;
     1689        *-next)
     1690                os=-nextstep3
     1691                ;;
     1692        *-gould)
     1693                os=-sysv
     1694                ;;
     1695        *-highlevel)
     1696                os=-bsd
     1697                ;;
     1698        *-encore)
     1699                os=-bsd
     1700                ;;
     1701        *-sgi)
     1702                os=-irix
     1703                ;;
     1704        *-siemens)
     1705                os=-sysv4
     1706                ;;
     1707        *-masscomp)
     1708                os=-rtu
     1709                ;;
     1710        f30[01]-fujitsu | f700-fujitsu)
     1711                os=-uxpv
     1712                ;;
     1713        *-rom68k)
     1714                os=-coff
     1715                ;;
     1716        *-*bug)
     1717                os=-coff
     1718                ;;
     1719        *-apple)
     1720                os=-macos
     1721                ;;
     1722        *-atari*)
     1723                os=-mint
     1724                ;;
     1725        *)
     1726                os=-none
     1727                ;;
     1728esac
     1729fi
     1730
     1731# Here we handle the case where we know the os, and the CPU type, but not the
     1732# manufacturer.  We pick the logical manufacturer.
     1733vendor=unknown
     1734case $basic_machine in
     1735        *-unknown)
     1736                case $os in
     1737                        -riscix*)
     1738                                vendor=acorn
     1739                                ;;
     1740                        -sunos*)
     1741                                vendor=sun
     1742                                ;;
     1743                        -cnk*|-aix*)
     1744                                vendor=ibm
     1745                                ;;
     1746                        -beos*)
     1747                                vendor=be
     1748                                ;;
     1749                        -hpux*)
     1750                                vendor=hp
     1751                                ;;
     1752                        -mpeix*)
     1753                                vendor=hp
     1754                                ;;
     1755                        -hiux*)
     1756                                vendor=hitachi
     1757                                ;;
     1758                        -unos*)
     1759                                vendor=crds
     1760                                ;;
     1761                        -dgux*)
     1762                                vendor=dg
     1763                                ;;
     1764                        -luna*)
     1765                                vendor=omron
     1766                                ;;
     1767                        -genix*)
     1768                                vendor=ns
     1769                                ;;
     1770                        -mvs* | -opened*)
     1771                                vendor=ibm
     1772                                ;;
     1773                        -os400*)
     1774                                vendor=ibm
     1775                                ;;
     1776                        -ptx*)
     1777                                vendor=sequent
     1778                                ;;
     1779                        -tpf*)
     1780                                vendor=ibm
     1781                                ;;
     1782                        -vxsim* | -vxworks* | -windiss*)
     1783                                vendor=wrs
     1784                                ;;
     1785                        -aux*)
     1786                                vendor=apple
     1787                                ;;
     1788                        -hms*)
     1789                                vendor=hitachi
     1790                                ;;
     1791                        -mpw* | -macos*)
     1792                                vendor=apple
     1793                                ;;
     1794                        -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
     1795                                vendor=atari
     1796                                ;;
     1797                        -vos*)
     1798                                vendor=stratus
     1799                                ;;
     1800                esac
     1801                basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
     1802                ;;
     1803esac
     1804
     1805echo $basic_machine$os
     1806exit
     1807
     1808# Local variables:
     1809# eval: (add-hook 'write-file-hooks 'time-stamp)
     1810# time-stamp-start: "timestamp='"
     1811# time-stamp-format: "%:y-%02m-%02d"
     1812# time-stamp-end: "'"
     1813# End:
  • automake/depcomp

    r275f4b4 rcd7ef0b  
    22# depcomp - compile a program generating dependencies as side-effects
    33
    4 scriptversion=2011-12-04.11; # UTC
    5 
    6 # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010,
    7 # 2011 Free Software Foundation, Inc.
     4scriptversion=2013-05-30.07; # UTC
     5
     6# Copyright (C) 1999-2014 Free Software Foundation, Inc.
    87
    98# This program is free software; you can redistribute it and/or modify
     
    2928case $1 in
    3029  '')
    31      echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
    32      exit 1;
    33      ;;
     30    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
     31    exit 1;
     32    ;;
    3433  -h | --h*)
    3534    cat <<\EOF
     
    4140Environment variables:
    4241  depmode     Dependency tracking mode.
    43   source      Source file read by `PROGRAMS ARGS'.
    44   object      Object file output by `PROGRAMS ARGS'.
     42  source      Source file read by 'PROGRAMS ARGS'.
     43  object      Object file output by 'PROGRAMS ARGS'.
    4544  DEPDIR      directory where to store dependencies.
    4645  depfile     Dependency file to output.
     
    5857esac
    5958
     59# Get the directory component of the given path, and save it in the
     60# global variables '$dir'.  Note that this directory component will
     61# be either empty or ending with a '/' character.  This is deliberate.
     62set_dir_from ()
     63{
     64  case $1 in
     65    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
     66      *) dir=;;
     67  esac
     68}
     69
     70# Get the suffix-stripped basename of the given path, and save it the
     71# global variable '$base'.
     72set_base_from ()
     73{
     74  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
     75}
     76
     77# If no dependency file was actually created by the compiler invocation,
     78# we still have to create a dummy depfile, to avoid errors with the
     79# Makefile "include basename.Plo" scheme.
     80make_dummy_depfile ()
     81{
     82  echo "#dummy" > "$depfile"
     83}
     84
     85# Factor out some common post-processing of the generated depfile.
     86# Requires the auxiliary global variable '$tmpdepfile' to be set.
     87aix_post_process_depfile ()
     88{
     89  # If the compiler actually managed to produce a dependency file,
     90  # post-process it.
     91  if test -f "$tmpdepfile"; then
     92    # Each line is of the form 'foo.o: dependency.h'.
     93    # Do two passes, one to just change these to
     94    #   $object: dependency.h
     95    # and one to simply output
     96    #   dependency.h:
     97    # which is needed to avoid the deleted-header problem.
     98    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
     99      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
     100    } > "$depfile"
     101    rm -f "$tmpdepfile"
     102  else
     103    make_dummy_depfile
     104  fi
     105}
     106
     107# A tabulation character.
     108tab='   '
     109# A newline character.
     110nl='
     111'
     112# Character ranges might be problematic outside the C locale.
     113# These definitions help.
     114upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
     115lower=abcdefghijklmnopqrstuvwxyz
     116digits=0123456789
     117alpha=${upper}${lower}
     118
    60119if test -z "$depmode" || test -z "$source" || test -z "$object"; then
    61120  echo "depcomp: Variables source, object and depmode must be set" 1>&2
     
    69128
    70129rm -f "$tmpdepfile"
     130
     131# Avoid interferences from the environment.
     132gccflag= dashmflag=
    71133
    72134# Some modes work just like other modes, but use different flags.  We
     
    81143
    82144if test "$depmode" = dashXmstdout; then
    83    # This is just like dashmstdout with a different argument.
    84    dashmflag=-xM
    85    depmode=dashmstdout
     145  # This is just like dashmstdout with a different argument.
     146  dashmflag=-xM
     147  depmode=dashmstdout
    86148fi
    87149
    88150cygpath_u="cygpath -u -f -"
    89151if test "$depmode" = msvcmsys; then
    90    # This is just like msvisualcpp but w/o cygpath translation.
    91    # Just convert the backslash-escaped backslashes to single forward
    92    # slashes to satisfy depend.m4
    93    cygpath_u='sed s,\\\\,/,g'
    94    depmode=msvisualcpp
     152  # This is just like msvisualcpp but w/o cygpath translation.
     153  # Just convert the backslash-escaped backslashes to single forward
     154  # slashes to satisfy depend.m4
     155  cygpath_u='sed s,\\\\,/,g'
     156  depmode=msvisualcpp
    95157fi
    96158
    97159if test "$depmode" = msvc7msys; then
    98    # This is just like msvc7 but w/o cygpath translation.
    99    # Just convert the backslash-escaped backslashes to single forward
    100    # slashes to satisfy depend.m4
    101    cygpath_u='sed s,\\\\,/,g'
    102    depmode=msvc7
     160  # This is just like msvc7 but w/o cygpath translation.
     161  # Just convert the backslash-escaped backslashes to single forward
     162  # slashes to satisfy depend.m4
     163  cygpath_u='sed s,\\\\,/,g'
     164  depmode=msvc7
     165fi
     166
     167if test "$depmode" = xlc; then
     168  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
     169  gccflag=-qmakedep=gcc,-MF
     170  depmode=gcc
    103171fi
    104172
     
    123191  "$@"
    124192  stat=$?
    125   if test $stat -eq 0; then :
    126   else
     193  if test $stat -ne 0; then
    127194    rm -f "$tmpdepfile"
    128195    exit $stat
     
    132199
    133200gcc)
     201## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
     202## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
     203## (see the conditional assignment to $gccflag above).
    134204## There are various ways to get dependency output from gcc.  Here's
    135205## why we pick this rather obscure method:
     
    138208##   (We might end up doing this anyway to support other compilers.)
    139209## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
    140 ##   -MM, not -M (despite what the docs say).
     210##   -MM, not -M (despite what the docs say).  Also, it might not be
     211##   supported by the other compilers which use the 'gcc' depmode.
    141212## - Using -M directly means running the compiler twice (even worse
    142213##   than renaming).
     
    146217  "$@" -Wp,"$gccflag$tmpdepfile"
    147218  stat=$?
    148   if test $stat -eq 0; then :
    149   else
     219  if test $stat -ne 0; then
    150220    rm -f "$tmpdepfile"
    151221    exit $stat
     
    153223  rm -f "$depfile"
    154224  echo "$object : \\" > "$depfile"
    155   alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
    156 ## The second -e expression handles DOS-style file names with drive letters.
     225  # The second -e expression handles DOS-style file names with drive
     226  # letters.
    157227  sed -e 's/^[^:]*: / /' \
    158228      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
    159 ## This next piece of magic avoids the `deleted header file' problem.
     229## This next piece of magic avoids the "deleted header file" problem.
    160230## The problem is that when a header file which appears in a .P file
    161231## is deleted, the dependency causes make to die (because there is
     
    163233## dummy dependencies for each header file.  Too bad gcc doesn't do
    164234## this for us directly.
    165   tr ' ' '
    166 ' < "$tmpdepfile" |
    167 ## Some versions of gcc put a space before the `:'.  On the theory
     235## Some versions of gcc put a space before the ':'.  On the theory
    168236## that the space means something, we add a space to the output as
    169237## well.  hp depmode also adds that space, but also prefixes the VPATH
     
    171239## Some versions of the HPUX 10.20 sed can't process this invocation
    172240## correctly.  Breaking it into two sed invocations is a workaround.
    173     sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
    174       | sed -e 's/$/ :/' >> "$depfile"
     241  tr ' ' "$nl" < "$tmpdepfile" \
     242    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
     243    | sed -e 's/$/ :/' >> "$depfile"
    175244  rm -f "$tmpdepfile"
    176245  ;;
     
    190259  fi
    191260  stat=$?
    192   if test $stat -eq 0; then :
    193   else
     261  if test $stat -ne 0; then
    194262    rm -f "$tmpdepfile"
    195263    exit $stat
     
    199267  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
    200268    echo "$object : \\" > "$depfile"
    201 
    202269    # Clip off the initial element (the dependent).  Don't try to be
    203270    # clever and replace this with sed code, as IRIX sed won't handle
    204271    # lines with more than a fixed number of characters (4096 in
    205272    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
    206     # the IRIX cc adds comments like `#:fec' to the end of the
     273    # the IRIX cc adds comments like '#:fec' to the end of the
    207274    # dependency line.
    208     tr ' ' '
    209 ' < "$tmpdepfile" \
    210     | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
    211     tr '
    212 ' ' ' >> "$depfile"
     275    tr ' ' "$nl" < "$tmpdepfile" \
     276      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
     277      | tr "$nl" ' ' >> "$depfile"
    213278    echo >> "$depfile"
    214 
    215279    # The second pass generates a dummy entry for each header file.
    216     tr ' ' '
    217 ' < "$tmpdepfile" \
    218    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
    219    >> "$depfile"
     280    tr ' ' "$nl" < "$tmpdepfile" \
     281      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
     282      >> "$depfile"
    220283  else
    221     # The sourcefile does not contain any dependencies, so just
    222     # store a dummy comment line, to avoid errors with the Makefile
    223     # "include basename.Plo" scheme.
    224     echo "#dummy" > "$depfile"
     284    make_dummy_depfile
    225285  fi
    226286  rm -f "$tmpdepfile"
     287  ;;
     288
     289xlc)
     290  # This case exists only to let depend.m4 do its work.  It works by
     291  # looking at the text of this script.  This case will never be run,
     292  # since it is checked for above.
     293  exit 1
    227294  ;;
    228295
     
    230297  # The C for AIX Compiler uses -M and outputs the dependencies
    231298  # in a .u file.  In older versions, this file always lives in the
    232   # current directory.  Also, the AIX compiler puts `$object:' at the
     299  # current directory.  Also, the AIX compiler puts '$object:' at the
    233300  # start of each line; $object doesn't have directory information.
    234301  # Version 6 uses the directory in both cases.
    235   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
    236   test "x$dir" = "x$object" && dir=
    237   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
     302  set_dir_from "$object"
     303  set_base_from "$object"
    238304  if test "$libtool" = yes; then
    239305    tmpdepfile1=$dir$base.u
     
    248314  fi
    249315  stat=$?
    250 
    251   if test $stat -eq 0; then :
    252   else
     316  if test $stat -ne 0; then
    253317    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
    254318    exit $stat
     
    259323    test -f "$tmpdepfile" && break
    260324  done
    261   if test -f "$tmpdepfile"; then
    262     # Each line is of the form `foo.o: dependent.h'.
    263     # Do two passes, one to just change these to
    264     # `$object: dependent.h' and one to simply `dependent.h:'.
    265     sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
    266     # That's a tab and a space in the [].
    267     sed -e 's,^.*\.[a-z]*:[      ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
    268   else
    269     # The sourcefile does not contain any dependencies, so just
    270     # store a dummy comment line, to avoid errors with the Makefile
    271     # "include basename.Plo" scheme.
    272     echo "#dummy" > "$depfile"
    273   fi
     325  aix_post_process_depfile
     326  ;;
     327
     328tcc)
     329  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
     330  # FIXME: That version still under development at the moment of writing.
     331  #        Make that this statement remains true also for stable, released
     332  #        versions.
     333  # It will wrap lines (doesn't matter whether long or short) with a
     334  # trailing '\', as in:
     335  #
     336  #   foo.o : \
     337  #    foo.c \
     338  #    foo.h \
     339  #
     340  # It will put a trailing '\' even on the last line, and will use leading
     341  # spaces rather than leading tabs (at least since its commit 0394caf7
     342  # "Emit spaces for -MD").
     343  "$@" -MD -MF "$tmpdepfile"
     344  stat=$?
     345  if test $stat -ne 0; then
     346    rm -f "$tmpdepfile"
     347    exit $stat
     348  fi
     349  rm -f "$depfile"
     350  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
     351  # We have to change lines of the first kind to '$object: \'.
     352  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
     353  # And for each line of the second kind, we have to emit a 'dep.h:'
     354  # dummy dependency, to avoid the deleted-header problem.
     355  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
    274356  rm -f "$tmpdepfile"
    275357  ;;
    276358
    277 icc)
    278   # Intel's C compiler understands `-MD -MF file'.  However on
    279   #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
    280   # ICC 7.0 will fill foo.d with something like
    281   #    foo.o: sub/foo.c
    282   #    foo.o: sub/foo.h
    283   # which is wrong.  We want:
    284   #    sub/foo.o: sub/foo.c
    285   #    sub/foo.o: sub/foo.h
    286   #    sub/foo.c:
    287   #    sub/foo.h:
    288   # ICC 7.1 will output
     359## The order of this option in the case statement is important, since the
     360## shell code in configure will try each of these formats in the order
     361## listed in this file.  A plain '-MD' option would be understood by many
     362## compilers, so we must ensure this comes after the gcc and icc options.
     363pgcc)
     364  # Portland's C compiler understands '-MD'.
     365  # Will always output deps to 'file.d' where file is the root name of the
     366  # source file under compilation, even if file resides in a subdirectory.
     367  # The object file name does not affect the name of the '.d' file.
     368  # pgcc 10.2 will output
    289369  #    foo.o: sub/foo.c sub/foo.h
    290   # and will wrap long lines using \ :
     370  # and will wrap long lines using '\' :
    291371  #    foo.o: sub/foo.c ... \
    292372  #     sub/foo.h ... \
    293373  #     ...
    294 
    295   "$@" -MD -MF "$tmpdepfile"
    296   stat=$?
    297   if test $stat -eq 0; then :
    298   else
     374  set_dir_from "$object"
     375  # Use the source, not the object, to determine the base name, since
     376  # that's sadly what pgcc will do too.
     377  set_base_from "$source"
     378  tmpdepfile=$base.d
     379
     380  # For projects that build the same source file twice into different object
     381  # files, the pgcc approach of using the *source* file root name can cause
     382  # problems in parallel builds.  Use a locking strategy to avoid stomping on
     383  # the same $tmpdepfile.
     384  lockdir=$base.d-lock
     385  trap "
     386    echo '$0: caught signal, cleaning up...' >&2
     387    rmdir '$lockdir'
     388    exit 1
     389  " 1 2 13 15
     390  numtries=100
     391  i=$numtries
     392  while test $i -gt 0; do
     393    # mkdir is a portable test-and-set.
     394    if mkdir "$lockdir" 2>/dev/null; then
     395      # This process acquired the lock.
     396      "$@" -MD
     397      stat=$?
     398      # Release the lock.
     399      rmdir "$lockdir"
     400      break
     401    else
     402      # If the lock is being held by a different process, wait
     403      # until the winning process is done or we timeout.
     404      while test -d "$lockdir" && test $i -gt 0; do
     405        sleep 1
     406        i=`expr $i - 1`
     407      done
     408    fi
     409    i=`expr $i - 1`
     410  done
     411  trap - 1 2 13 15
     412  if test $i -le 0; then
     413    echo "$0: failed to acquire lock after $numtries attempts" >&2
     414    echo "$0: check lockdir '$lockdir'" >&2
     415    exit 1
     416  fi
     417
     418  if test $stat -ne 0; then
    299419    rm -f "$tmpdepfile"
    300420    exit $stat
     
    308428  # Some versions of the HPUX 10.20 sed can't process this invocation
    309429  # correctly.  Breaking it into two sed invocations is a workaround.
    310   sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
    311     sed -e 's/$/ :/' >> "$depfile"
     430  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
     431    | sed -e 's/$/ :/' >> "$depfile"
    312432  rm -f "$tmpdepfile"
    313433  ;;
     
    320440  # happens to be.
    321441  # Much of this is similar to the tru64 case; see comments there.
    322   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
    323   test "x$dir" = "x$object" && dir=
    324   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
     442  set_dir_from  "$object"
     443  set_base_from "$object"
    325444  if test "$libtool" = yes; then
    326445    tmpdepfile1=$dir$base.d
     
    333452  fi
    334453  stat=$?
    335   if test $stat -eq 0; then :
    336   else
     454  if test $stat -ne 0; then
    337455     rm -f "$tmpdepfile1" "$tmpdepfile2"
    338456     exit $stat
     
    344462  done
    345463  if test -f "$tmpdepfile"; then
    346     sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
    347     # Add `dependent.h:' lines.
     464    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
     465    # Add 'dependent.h:' lines.
    348466    sed -ne '2,${
    349                s/^ *//
    350                s/ \\*$//
    351                s/$/:/
    352                p
    353              }' "$tmpdepfile" >> "$depfile"
     467               s/^ *//
     468               s/ \\*$//
     469               s/$/:/
     470               p
     471             }' "$tmpdepfile" >> "$depfile"
    354472  else
    355     echo "#dummy" > "$depfile"
     473    make_dummy_depfile
    356474  fi
    357475  rm -f "$tmpdepfile" "$tmpdepfile2"
     
    359477
    360478tru64)
    361    # The Tru64 compiler uses -MD to generate dependencies as a side
    362    # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
    363    # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
    364    # dependencies in `foo.d' instead, so we check for that too.
    365    # Subdirectories are respected.
    366    dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
    367    test "x$dir" = "x$object" && dir=
    368    base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
    369 
    370    if test "$libtool" = yes; then
    371       # With Tru64 cc, shared objects can also be used to make a
    372       # static library.  This mechanism is used in libtool 1.4 series to
    373       # handle both shared and static libraries in a single compilation.
    374       # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
    375       #
    376       # With libtool 1.5 this exception was removed, and libtool now
    377       # generates 2 separate objects for the 2 libraries.  These two
    378       # compilations output dependencies in $dir.libs/$base.o.d and
    379       # in $dir$base.o.d.  We have to check for both files, because
    380       # one of the two compilations can be disabled.  We should prefer
    381       # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
    382       # automatically cleaned when .libs/ is deleted, while ignoring
    383       # the former would cause a distcleancheck panic.
    384       tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
    385       tmpdepfile2=$dir$base.o.d          # libtool 1.5
    386       tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
    387       tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
    388       "$@" -Wc,-MD
    389    else
    390       tmpdepfile1=$dir$base.o.d
    391       tmpdepfile2=$dir$base.d
    392       tmpdepfile3=$dir$base.d
    393       tmpdepfile4=$dir$base.d
    394       "$@" -MD
    395    fi
    396 
    397    stat=$?
    398    if test $stat -eq 0; then :
    399    else
    400       rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
    401       exit $stat
    402    fi
    403 
    404    for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
    405    do
    406      test -f "$tmpdepfile" && break
    407    done
    408    if test -f "$tmpdepfile"; then
    409       sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
    410       # That's a tab and a space in the [].
    411       sed -e 's,^.*\.[a-z]*:[    ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
    412    else
    413       echo "#dummy" > "$depfile"
    414    fi
    415    rm -f "$tmpdepfile"
    416    ;;
     479  # The Tru64 compiler uses -MD to generate dependencies as a side
     480  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
     481  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
     482  # dependencies in 'foo.d' instead, so we check for that too.
     483  # Subdirectories are respected.
     484  set_dir_from  "$object"
     485  set_base_from "$object"
     486
     487  if test "$libtool" = yes; then
     488    # Libtool generates 2 separate objects for the 2 libraries.  These
     489    # two compilations output dependencies in $dir.libs/$base.o.d and
     490    # in $dir$base.o.d.  We have to check for both files, because
     491    # one of the two compilations can be disabled.  We should prefer
     492    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
     493    # automatically cleaned when .libs/ is deleted, while ignoring
     494    # the former would cause a distcleancheck panic.
     495    tmpdepfile1=$dir$base.o.d          # libtool 1.5
     496    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
     497    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
     498    "$@" -Wc,-MD
     499  else
     500    tmpdepfile1=$dir$base.d
     501    tmpdepfile2=$dir$base.d
     502    tmpdepfile3=$dir$base.d
     503    "$@" -MD
     504  fi
     505
     506  stat=$?
     507  if test $stat -ne 0; then
     508    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
     509    exit $stat
     510  fi
     511
     512  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
     513  do
     514    test -f "$tmpdepfile" && break
     515  done
     516  # Same post-processing that is required for AIX mode.
     517  aix_post_process_depfile
     518  ;;
    417519
    418520msvc7)
     
    425527  stat=$?
    426528  grep -v '^Note: including file: ' "$tmpdepfile"
    427   if test "$stat" = 0; then :
    428   else
     529  if test $stat -ne 0; then
    429530    rm -f "$tmpdepfile"
    430531    exit $stat
     
    444545}' | $cygpath_u | sort -u | sed -n '
    445546s/ /\\ /g
    446 s/\(.*\)/       \1 \\/p
     547s/\(.*\)/'"$tab"'\1 \\/p
    447548s/.\(.*\) \\/\1:/
    448549H
    449550$ {
    450   s/.*/ /
     551  s/.*/'"$tab"'/
    451552  G
    452553  p
    453554}' >> "$depfile"
     555  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
    454556  rm -f "$tmpdepfile"
    455557  ;;
     
    479581  fi
    480582
    481   # Remove `-o $object'.
     583  # Remove '-o $object'.
    482584  IFS=" "
    483585  for arg
     
    499601
    500602  test -z "$dashmflag" && dashmflag=-M
    501   # Require at least two characters before searching for `:'
     603  # Require at least two characters before searching for ':'
    502604  # in the target name.  This is to cope with DOS-style filenames:
    503   # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
     605  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
    504606  "$@" $dashmflag |
    505     sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
     607    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
    506608  rm -f "$depfile"
    507609  cat < "$tmpdepfile" > "$depfile"
    508   tr ' ' '
    509 ' < "$tmpdepfile" | \
    510 ## Some versions of the HPUX 10.20 sed can't process this invocation
    511 ## correctly.  Breaking it into two sed invocations is a workaround.
    512     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
     610  # Some versions of the HPUX 10.20 sed can't process this sed invocation
     611  # correctly.  Breaking it into two sed invocations is a workaround.
     612  tr ' ' "$nl" < "$tmpdepfile" \
     613    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
     614    | sed -e 's/$/ :/' >> "$depfile"
    513615  rm -f "$tmpdepfile"
    514616  ;;
     
    563665  # No need to regex-escape $object, excess matching of '.' is harmless.
    564666  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
    565   sed '1,2d' "$tmpdepfile" | tr ' ' '
    566 ' | \
    567 ## Some versions of the HPUX 10.20 sed can't process this invocation
    568 ## correctly.  Breaking it into two sed invocations is a workaround.
    569     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
     667  # Some versions of the HPUX 10.20 sed can't process the last invocation
     668  # correctly.  Breaking it into two sed invocations is a workaround.
     669  sed '1,2d' "$tmpdepfile" \
     670    | tr ' ' "$nl" \
     671    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
     672    | sed -e 's/$/ :/' >> "$depfile"
    570673  rm -f "$tmpdepfile" "$tmpdepfile".bak
    571674  ;;
     
    584687  fi
    585688
    586   # Remove `-o $object'.
     689  # Remove '-o $object'.
    587690  IFS=" "
    588691  for arg
     
    603706  done
    604707
    605   "$@" -E |
    606     sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
    607        -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
    608     sed '$ s: \\$::' > "$tmpdepfile"
     708  "$@" -E \
     709    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
     710             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
     711    | sed '$ s: \\$::' > "$tmpdepfile"
    609712  rm -f "$depfile"
    610713  echo "$object : \\" > "$depfile"
     
    638741      ;;
    639742    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
    640         set fnord "$@"
    641         shift
    642         shift
    643         ;;
     743        set fnord "$@"
     744        shift
     745        shift
     746        ;;
    644747    *)
    645         set fnord "$@" "$arg"
    646         shift
    647         shift
    648         ;;
     748        set fnord "$@" "$arg"
     749        shift
     750        shift
     751        ;;
    649752    esac
    650753  done
     
    653756  rm -f "$depfile"
    654757  echo "$object : \\" > "$depfile"
    655   sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::      \1 \\:p' >> "$depfile"
    656   echo "        " >> "$depfile"
     758  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
     759  echo "$tab" >> "$depfile"
    657760  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
    658761  rm -f "$tmpdepfile"
  • automake/install-sh

    r275f4b4 rcd7ef0b  
    22# install - install a program, script, or datafile
    33
    4 scriptversion=2011-01-19.21; # UTC
     4scriptversion=2014-09-12.12; # UTC
    55
    66# This originates from X11R5 (mit/util/scripts/install.sh), which was
     
    3636#
    3737# Calling this script install-sh is preferred over install.sh, to prevent
    38 # `make' implicit rules from creating a file called install from it
     38# 'make' implicit rules from creating a file called install from it
    3939# when there is no Makefile.
    4040#
     
    4242# from scratch.
    4343
     44tab='   '
    4445nl='
    4546'
    46 IFS=" ""        $nl"
    47 
    48 # set DOITPROG to echo to test this script
    49 
    50 # Don't use :- since 4.3BSD and earlier shells don't like it.
     47IFS=" $tab$nl"
     48
     49# Set DOITPROG to "echo" to test this script.
     50
    5151doit=${DOITPROG-}
    52 if test -z "$doit"; then
    53   doit_exec=exec
    54 else
    55   doit_exec=$doit
    56 fi
     52doit_exec=${doit:-exec}
    5753
    5854# Put in absolute file names if you don't have them in your path;
     
    6965stripprog=${STRIPPROG-strip}
    7066
    71 posix_glob='?'
    72 initialize_posix_glob='
    73   test "$posix_glob" != "?" || {
    74     if (set -f) 2>/dev/null; then
    75       posix_glob=
    76     else
    77       posix_glob=:
    78     fi
    79   }
    80 '
    81 
    8267posix_mkdir=
    8368
     
    9883
    9984copy_on_change=false
    100 no_target_directory=
     85is_target_a_directory=possibly
    10186
    10287usage="\
     
    138123
    139124    -g) chgrpcmd="$chgrpprog $2"
    140         shift;;
     125        shift;;
    141126
    142127    --help) echo "$usage"; exit $?;;
    143128
    144129    -m) mode=$2
    145         case $mode in
    146           *' '* | *'    '* | *'
    147 '*        | *'*'* | *'?'* | *'['*)
    148             echo "$0: invalid mode: $mode" >&2
    149             exit 1;;
    150         esac
    151         shift;;
     130        case $mode in
     131          *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*)
     132            echo "$0: invalid mode: $mode" >&2
     133            exit 1;;
     134        esac
     135        shift;;
    152136
    153137    -o) chowncmd="$chownprog $2"
    154         shift;;
     138        shift;;
    155139
    156140    -s) stripcmd=$stripprog;;
    157141
    158     -t) dst_arg=$2
    159         # Protect names problematic for `test' and other utilities.
    160         case $dst_arg in
    161           -* | [=\(\)!]) dst_arg=./$dst_arg;;
    162         esac
    163         shift;;
    164 
    165     -T) no_target_directory=true;;
     142    -t)
     143        is_target_a_directory=always
     144        dst_arg=$2
     145        # Protect names problematic for 'test' and other utilities.
     146        case $dst_arg in
     147          -* | [=\(\)!]) dst_arg=./$dst_arg;;
     148        esac
     149        shift;;
     150
     151    -T) is_target_a_directory=never;;
    166152
    167153    --version) echo "$0 $scriptversion"; exit $?;;
    168154
    169     --) shift
    170         break;;
    171 
    172     -*) echo "$0: invalid option: $1" >&2
    173         exit 1;;
     155    --) shift
     156        break;;
     157
     158    -*) echo "$0: invalid option: $1" >&2
     159        exit 1;;
    174160
    175161    *)  break;;
     
    177163  shift
    178164done
     165
     166# We allow the use of options -d and -T together, by making -d
     167# take the precedence; this is for compatibility with GNU install.
     168
     169if test -n "$dir_arg"; then
     170  if test -n "$dst_arg"; then
     171    echo "$0: target directory not allowed when installing a directory." >&2
     172    exit 1
     173  fi
     174fi
    179175
    180176if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
     
    191187    shift # arg
    192188    dst_arg=$arg
    193     # Protect names problematic for `test' and other utilities.
     189    # Protect names problematic for 'test' and other utilities.
    194190    case $dst_arg in
    195191      -* | [=\(\)!]) dst_arg=./$dst_arg;;
     
    203199    exit 1
    204200  fi
    205   # It's OK to call `install-sh -d' without argument.
     201  # It's OK to call 'install-sh -d' without argument.
    206202  # This can happen when creating conditional directories.
    207203  exit 0
     204fi
     205
     206if test -z "$dir_arg"; then
     207  if test $# -gt 1 || test "$is_target_a_directory" = always; then
     208    if test ! -d "$dst_arg"; then
     209      echo "$0: $dst_arg: Is not a directory." >&2
     210      exit 1
     211    fi
     212  fi
    208213fi
    209214
     
    224229    *[0-7])
    225230      if test -z "$stripcmd"; then
    226         u_plus_rw=
     231        u_plus_rw=
    227232      else
    228         u_plus_rw='% 200'
     233        u_plus_rw='% 200'
    229234      fi
    230235      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
    231236    *)
    232237      if test -z "$stripcmd"; then
    233         u_plus_rw=
     238        u_plus_rw=
    234239      else
    235         u_plus_rw=,u+rw
     240        u_plus_rw=,u+rw
    236241      fi
    237242      cp_umask=$mode$u_plus_rw;;
     
    241246for src
    242247do
    243   # Protect names problematic for `test' and other utilities.
     248  # Protect names problematic for 'test' and other utilities.
    244249  case $src in
    245250    -* | [=\(\)!]) src=./$src;;
     
    270275    # if double slashes aren't ignored.
    271276    if test -d "$dst"; then
    272       if test -n "$no_target_directory"; then
    273         echo "$0: $dst_arg: Is a directory" >&2
    274         exit 1
     277      if test "$is_target_a_directory" = never; then
     278        echo "$0: $dst_arg: Is a directory" >&2
     279        exit 1
    275280      fi
    276281      dstdir=$dst
     
    278283      dstdir_status=0
    279284    else
    280       # Prefer dirname, but fall back on a substitute if dirname fails.
    281       dstdir=`
    282         (dirname "$dst") 2>/dev/null ||
    283         expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
    284              X"$dst" : 'X\(//\)[^/]' \| \
    285              X"$dst" : 'X\(//\)$' \| \
    286              X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
    287         echo X"$dst" |
    288             sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
    289                    s//\1/
    290                    q
    291                  }
    292                  /^X\(\/\/\)[^/].*/{
    293                    s//\1/
    294                    q
    295                  }
    296                  /^X\(\/\/\)$/{
    297                    s//\1/
    298                    q
    299                  }
    300                  /^X\(\/\).*/{
    301                    s//\1/
    302                    q
    303                  }
    304                  s/.*/./; q'
    305       `
    306 
     285      dstdir=`dirname "$dst"`
    307286      test -d "$dstdir"
    308287      dstdir_status=$?
     
    315294    case $posix_mkdir in
    316295      '')
    317         # Create intermediate dirs using mode 755 as modified by the umask.
    318         # This is like FreeBSD 'install' as of 1997-10-28.
    319         umask=`umask`
    320         case $stripcmd.$umask in
    321           # Optimize common cases.
    322           *[2367][2367]) mkdir_umask=$umask;;
    323           .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
    324 
    325           *[0-7])
    326             mkdir_umask=`expr $umask + 22 \
    327               - $umask % 100 % 40 + $umask % 20 \
    328               - $umask % 10 % 4 + $umask % 2
    329             `;;
    330           *) mkdir_umask=$umask,go-w;;
    331         esac
    332 
    333         # With -d, create the new directory with the user-specified mode.
    334         # Otherwise, rely on $mkdir_umask.
    335         if test -n "$dir_arg"; then
    336           mkdir_mode=-m$mode
    337         else
    338           mkdir_mode=
    339         fi
    340 
    341         posix_mkdir=false
    342         case $umask in
    343           *[123567][0-7][0-7])
    344             # POSIX mkdir -p sets u+wx bits regardless of umask, which
    345             # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
    346             ;;
    347           *)
    348             tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
    349             trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
    350 
    351             if (umask $mkdir_umask &&
    352                 exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
    353             then
    354               if test -z "$dir_arg" || {
    355                    # Check for POSIX incompatibilities with -m.
    356                    # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
    357                    # other-writeable bit of parent directory when it shouldn't.
    358                    # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
    359                    ls_ld_tmpdir=`ls -ld "$tmpdir"`
    360                    case $ls_ld_tmpdir in
    361                      d????-?r-*) different_mode=700;;
    362                      d????-?--*) different_mode=755;;
    363                      *) false;;
    364                    esac &&
    365                    $mkdirprog -m$different_mode -p -- "$tmpdir" && {
    366                      ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
    367                      test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
    368                    }
    369                  }
    370               then posix_mkdir=:
    371               fi
    372               rmdir "$tmpdir/d" "$tmpdir"
    373             else
    374               # Remove any dirs left behind by ancient mkdir implementations.
    375               rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
    376             fi
    377             trap '' 0;;
    378         esac;;
     296        # Create intermediate dirs using mode 755 as modified by the umask.
     297        # This is like FreeBSD 'install' as of 1997-10-28.
     298        umask=`umask`
     299        case $stripcmd.$umask in
     300          # Optimize common cases.
     301          *[2367][2367]) mkdir_umask=$umask;;
     302          .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
     303
     304          *[0-7])
     305            mkdir_umask=`expr $umask + 22 \
     306              - $umask % 100 % 40 + $umask % 20 \
     307              - $umask % 10 % 4 + $umask % 2
     308            `;;
     309          *) mkdir_umask=$umask,go-w;;
     310        esac
     311
     312        # With -d, create the new directory with the user-specified mode.
     313        # Otherwise, rely on $mkdir_umask.
     314        if test -n "$dir_arg"; then
     315          mkdir_mode=-m$mode
     316        else
     317          mkdir_mode=
     318        fi
     319
     320        posix_mkdir=false
     321        case $umask in
     322          *[123567][0-7][0-7])
     323            # POSIX mkdir -p sets u+wx bits regardless of umask, which
     324            # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
     325            ;;
     326          *)
     327            # $RANDOM is not portable (e.g. dash);  use it when possible to
     328            # lower collision chance
     329            tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
     330            trap 'ret=$?; rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null; exit $ret' 0
     331
     332            # As "mkdir -p" follows symlinks and we work in /tmp possibly;  so
     333            # create the $tmpdir first (and fail if unsuccessful) to make sure
     334            # that nobody tries to guess the $tmpdir name.
     335            if (umask $mkdir_umask &&
     336                $mkdirprog $mkdir_mode "$tmpdir" &&
     337                exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
     338            then
     339              if test -z "$dir_arg" || {
     340                   # Check for POSIX incompatibilities with -m.
     341                   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
     342                   # other-writable bit of parent directory when it shouldn't.
     343                   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
     344                   test_tmpdir="$tmpdir/a"
     345                   ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
     346                   case $ls_ld_tmpdir in
     347                     d????-?r-*) different_mode=700;;
     348                     d????-?--*) different_mode=755;;
     349                     *) false;;
     350                   esac &&
     351                   $mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
     352                     ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
     353                     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
     354                   }
     355                 }
     356              then posix_mkdir=:
     357              fi
     358              rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
     359            else
     360              # Remove any dirs left behind by ancient mkdir implementations.
     361              rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
     362            fi
     363            trap '' 0;;
     364        esac;;
    379365    esac
    380366
    381367    if
    382368      $posix_mkdir && (
    383         umask $mkdir_umask &&
    384         $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
     369        umask $mkdir_umask &&
     370        $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
    385371      )
    386372    then :
     
    392378
    393379      case $dstdir in
    394         /*) prefix='/';;
    395         [-=\(\)!]*) prefix='./';;
    396         *)  prefix='';;
     380        /*) prefix='/';;
     381        [-=\(\)!]*) prefix='./';;
     382        *)  prefix='';;
    397383      esac
    398 
    399       eval "$initialize_posix_glob"
    400384
    401385      oIFS=$IFS
    402386      IFS=/
    403       $posix_glob set -f
     387      set -f
    404388      set fnord $dstdir
    405389      shift
    406       $posix_glob set +f
     390      set +f
    407391      IFS=$oIFS
    408392
     
    411395      for d
    412396      do
    413         test X"$d" = X && continue
    414 
    415         prefix=$prefix$d
    416         if test -d "$prefix"; then
    417           prefixes=
    418         else
    419           if $posix_mkdir; then
    420             (umask=$mkdir_umask &&
    421              $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
    422             # Don't fail if two instances are running concurrently.
    423             test -d "$prefix" || exit 1
    424           else
    425             case $prefix in
    426               *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
    427               *) qprefix=$prefix;;
    428             esac
    429             prefixes="$prefixes '$qprefix'"
    430           fi
    431         fi
    432         prefix=$prefix/
     397        test X"$d" = X && continue
     398
     399        prefix=$prefix$d
     400        if test -d "$prefix"; then
     401          prefixes=
     402        else
     403          if $posix_mkdir; then
     404            (umask=$mkdir_umask &&
     405             $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
     406            # Don't fail if two instances are running concurrently.
     407            test -d "$prefix" || exit 1
     408          else
     409            case $prefix in
     410              *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
     411              *) qprefix=$prefix;;
     412            esac
     413            prefixes="$prefixes '$qprefix'"
     414          fi
     415        fi
     416        prefix=$prefix/
    433417      done
    434418
    435419      if test -n "$prefixes"; then
    436         # Don't fail if two instances are running concurrently.
    437         (umask $mkdir_umask &&
    438         eval "\$doit_exec \$mkdirprog $prefixes") ||
    439           test -d "$dstdir" || exit 1
    440         obsolete_mkdir_used=true
     420        # Don't fail if two instances are running concurrently.
     421        (umask $mkdir_umask &&
     422        eval "\$doit_exec \$mkdirprog $prefixes") ||
     423          test -d "$dstdir" || exit 1
     424        obsolete_mkdir_used=true
    441425      fi
    442426    fi
     
    473457    # If -C, don't bother to copy if it wouldn't change the file.
    474458    if $copy_on_change &&
    475        old=`LC_ALL=C ls -dlL "$dst"     2>/dev/null` &&
    476        new=`LC_ALL=C ls -dlL "$dsttmp"  2>/dev/null` &&
    477 
    478        eval "$initialize_posix_glob" &&
    479        $posix_glob set -f &&
     459       old=`LC_ALL=C ls -dlL "$dst"     2>/dev/null` &&
     460       new=`LC_ALL=C ls -dlL "$dsttmp"  2>/dev/null` &&
     461       set -f &&
    480462       set X $old && old=:$2:$4:$5:$6 &&
    481463       set X $new && new=:$2:$4:$5:$6 &&
    482        $posix_glob set +f &&
    483 
     464       set +f &&
    484465       test "$old" = "$new" &&
    485466       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
     
    494475      # support -f.
    495476      {
    496         # Now remove or move aside any old file at destination location.
    497         # We try this two ways since rm can't unlink itself on some
    498         # systems and the destination file might be busy for other
    499         # reasons.  In this case, the final cleanup might fail but the new
    500         # file should still install successfully.
    501         {
    502           test ! -f "$dst" ||
    503           $doit $rmcmd -f "$dst" 2>/dev/null ||
    504           { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
    505             { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
    506           } ||
    507           { echo "$0: cannot unlink or rename $dst" >&2
    508             (exit 1); exit 1
    509           }
    510         } &&
    511 
    512         # Now rename the file to the real destination.
    513         $doit $mvcmd "$dsttmp" "$dst"
     477        # Now remove or move aside any old file at destination location.
     478        # We try this two ways since rm can't unlink itself on some
     479        # systems and the destination file might be busy for other
     480        # reasons.  In this case, the final cleanup might fail but the new
     481        # file should still install successfully.
     482        {
     483          test ! -f "$dst" ||
     484          $doit $rmcmd -f "$dst" 2>/dev/null ||
     485          { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
     486            { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
     487          } ||
     488          { echo "$0: cannot unlink or rename $dst" >&2
     489            (exit 1); exit 1
     490          }
     491        } &&
     492
     493        # Now rename the file to the real destination.
     494        $doit $mvcmd "$dsttmp" "$dst"
    514495      }
    515496    fi || exit 1
  • automake/test-driver

    • Property mode changed from 120000 to 100755
    r275f4b4 rcd7ef0b  
    1 /usr/share/automake-1.15/test-driver
     1#! /bin/sh
     2# test-driver - basic testsuite driver script.
     3
     4scriptversion=2013-07-13.22; # UTC
     5
     6# Copyright (C) 2011-2014 Free Software Foundation, Inc.
     7#
     8# This program is free software; you can redistribute it and/or modify
     9# it under the terms of the GNU General Public License as published by
     10# the Free Software Foundation; either version 2, or (at your option)
     11# any later version.
     12#
     13# This program is distributed in the hope that it will be useful,
     14# but WITHOUT ANY WARRANTY; without even the implied warranty of
     15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16# GNU General Public License for more details.
     17#
     18# You should have received a copy of the GNU General Public License
     19# along with this program.  If not, see <http://www.gnu.org/licenses/>.
     20
     21# As a special exception to the GNU General Public License, if you
     22# distribute this file as part of a program that contains a
     23# configuration script generated by Autoconf, you may include it under
     24# the same distribution terms that you use for the rest of that program.
     25
     26# This file is maintained in Automake, please report
     27# bugs to <bug-automake@gnu.org> or send patches to
     28# <automake-patches@gnu.org>.
     29
     30# Make unconditional expansion of undefined variables an error.  This
     31# helps a lot in preventing typo-related bugs.
     32set -u
     33
     34usage_error ()
     35{
     36  echo "$0: $*" >&2
     37  print_usage >&2
     38  exit 2
     39}
     40
     41print_usage ()
     42{
     43  cat <<END
     44Usage:
     45  test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
     46              [--expect-failure={yes|no}] [--color-tests={yes|no}]
     47              [--enable-hard-errors={yes|no}] [--]
     48              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
     49The '--test-name', '--log-file' and '--trs-file' options are mandatory.
     50END
     51}
     52
     53test_name= # Used for reporting.
     54log_file=  # Where to save the output of the test script.
     55trs_file=  # Where to save the metadata of the test run.
     56expect_failure=no
     57color_tests=no
     58enable_hard_errors=yes
     59while test $# -gt 0; do
     60  case $1 in
     61  --help) print_usage; exit $?;;
     62  --version) echo "test-driver $scriptversion"; exit $?;;
     63  --test-name) test_name=$2; shift;;
     64  --log-file) log_file=$2; shift;;
     65  --trs-file) trs_file=$2; shift;;
     66  --color-tests) color_tests=$2; shift;;
     67  --expect-failure) expect_failure=$2; shift;;
     68  --enable-hard-errors) enable_hard_errors=$2; shift;;
     69  --) shift; break;;
     70  -*) usage_error "invalid option: '$1'";;
     71   *) break;;
     72  esac
     73  shift
     74done
     75
     76missing_opts=
     77test x"$test_name" = x && missing_opts="$missing_opts --test-name"
     78test x"$log_file"  = x && missing_opts="$missing_opts --log-file"
     79test x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
     80if test x"$missing_opts" != x; then
     81  usage_error "the following mandatory options are missing:$missing_opts"
     82fi
     83
     84if test $# -eq 0; then
     85  usage_error "missing argument"
     86fi
     87
     88if test $color_tests = yes; then
     89  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
     90  red='[0;31m' # Red.
     91  grn='[0;32m' # Green.
     92  lgn='[1;32m' # Light green.
     93  blu='[1;34m' # Blue.
     94  mgn='[0;35m' # Magenta.
     95  std='[m'     # No color.
     96else
     97  red= grn= lgn= blu= mgn= std=
     98fi
     99
     100do_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
     101trap "st=129; $do_exit" 1
     102trap "st=130; $do_exit" 2
     103trap "st=141; $do_exit" 13
     104trap "st=143; $do_exit" 15
     105
     106# Test script is run here.
     107"$@" >$log_file 2>&1
     108estatus=$?
     109
     110if test $enable_hard_errors = no && test $estatus -eq 99; then
     111  tweaked_estatus=1
     112else
     113  tweaked_estatus=$estatus
     114fi
     115
     116case $tweaked_estatus:$expect_failure in
     117  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
     118  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
     119  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
     120  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
     121  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
     122  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
     123esac
     124
     125# Report the test outcome and exit status in the logs, so that one can
     126# know whether the test passed or failed simply by looking at the '.log'
     127# file, without the need of also peaking into the corresponding '.trs'
     128# file (automake bug#11814).
     129echo "$res $test_name (exit status: $estatus)" >>$log_file
     130
     131# Report outcome to console.
     132echo "${col}${res}${std}: $test_name"
     133
     134# Register the test result, and other relevant metadata.
     135echo ":test-result: $res" > $trs_file
     136echo ":global-test-result: $res" >> $trs_file
     137echo ":recheck: $recheck" >> $trs_file
     138echo ":copy-in-global-log: $gcopy" >> $trs_file
     139
     140# Local Variables:
     141# mode: shell-script
     142# sh-indentation: 2
     143# eval: (add-hook 'write-file-hooks 'time-stamp)
     144# time-stamp-start: "scriptversion="
     145# time-stamp-format: "%:y-%02m-%02d.%02H"
     146# time-stamp-time-zone: "UTC"
     147# time-stamp-end: "; # UTC"
     148# End:
  • automake/ylwrap

    r275f4b4 rcd7ef0b  
    22# ylwrap - wrapper for lex/yacc invocations.
    33
    4 scriptversion=2011-08-25.18; # UTC
    5 
    6 # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005,
    7 # 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
     4scriptversion=2013-01-12.17; # UTC
     5
     6# Copyright (C) 1996-2014 Free Software Foundation, Inc.
    87#
    98# Written by Tom Tromey <tromey@cygnus.com>.
     
    3130# <automake-patches@gnu.org>.
    3231
     32get_dirname ()
     33{
     34  case $1 in
     35    */*|*\\*) printf '%s\n' "$1" | sed -e 's|\([\\/]\)[^\\/]*$|\1|';;
     36    # Otherwise,  we want the empty string (not ".").
     37  esac
     38}
     39
     40# guard FILE
     41# ----------
     42# The CPP macro used to guard inclusion of FILE.
     43guard ()
     44{
     45  printf '%s\n' "$1"                                                    \
     46    | sed                                                               \
     47        -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'   \
     48        -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'                        \
     49        -e 's/__*/_/g'
     50}
     51
     52# quote_for_sed [STRING]
     53# ----------------------
     54# Return STRING (or stdin) quoted to be used as a sed pattern.
     55quote_for_sed ()
     56{
     57  case $# in
     58    0) cat;;
     59    1) printf '%s\n' "$1";;
     60  esac \
     61    | sed -e 's|[][\\.*]|\\&|g'
     62}
     63
    3364case "$1" in
    3465  '')
    35     echo "$0: No files given.  Try \`$0 --help' for more information." 1>&2
     66    echo "$0: No files given.  Try '$0 --help' for more information." 1>&2
    3667    exit 1
    3768    ;;
     
    6697
    6798# The input.
    68 input="$1"
     99input=$1
    69100shift
    70 case "$input" in
     101# We'll later need for a correct munging of "#line" directives.
     102input_sub_rx=`get_dirname "$input" | quote_for_sed`
     103case $input in
    71104  [\\/]* | ?:[\\/]*)
    72105    # Absolute path; do nothing.
     
    74107  *)
    75108    # Relative path.  Make it absolute.
    76     input="`pwd`/$input"
    77     ;;
    78 esac
    79 
    80 pairlist=
    81 while test "$#" -ne 0; do
    82   if test "$1" = "--"; then
     109    input=`pwd`/$input
     110    ;;
     111esac
     112input_rx=`get_dirname "$input" | quote_for_sed`
     113
     114# Since DOS filename conventions don't allow two dots,
     115# the DOS version of Bison writes out y_tab.c instead of y.tab.c
     116# and y_tab.h instead of y.tab.h. Test to see if this is the case.
     117y_tab_nodot=false
     118if test -f y_tab.c || test -f y_tab.h; then
     119  y_tab_nodot=true
     120fi
     121
     122# The parser itself, the first file, is the destination of the .y.c
     123# rule in the Makefile.
     124parser=$1
     125
     126# A sed program to s/FROM/TO/g for all the FROM/TO so that, for
     127# instance, we rename #include "y.tab.h" into #include "parse.h"
     128# during the conversion from y.tab.c to parse.c.
     129sed_fix_filenames=
     130
     131# Also rename header guards, as Bison 2.7 for instance uses its header
     132# guard in its implementation file.
     133sed_fix_header_guards=
     134
     135while test $# -ne 0; do
     136  if test x"$1" = x"--"; then
    83137    shift
    84138    break
    85139  fi
    86   pairlist="$pairlist $1"
     140  from=$1
     141  # Handle y_tab.c and y_tab.h output by DOS
     142  if $y_tab_nodot; then
     143    case $from in
     144      "y.tab.c") from=y_tab.c;;
     145      "y.tab.h") from=y_tab.h;;
     146    esac
     147  fi
    87148  shift
     149  to=$1
     150  shift
     151  sed_fix_filenames="${sed_fix_filenames}s|"`quote_for_sed "$from"`"|$to|g;"
     152  sed_fix_header_guards="${sed_fix_header_guards}s|"`guard "$from"`"|"`guard "$to"`"|g;"
    88153done
    89154
    90155# The program to run.
    91 prog="$1"
     156prog=$1
    92157shift
    93158# Make any relative path in $prog absolute.
    94 case "$prog" in
     159case $prog in
    95160  [\\/]* | ?:[\\/]*) ;;
    96   *[\\/]*) prog="`pwd`/$prog" ;;
    97 esac
    98 
    99 # FIXME: add hostname here for parallel makes that run commands on
    100 # other machines.  But that might take us over the 14-char limit.
     161  *[\\/]*) prog=`pwd`/$prog ;;
     162esac
     163
    101164dirname=ylwrap$$
    102165do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret'
     
    116179
    117180if test $ret -eq 0; then
    118   set X $pairlist
    119   shift
    120   first=yes
    121   # Since DOS filename conventions don't allow two dots,
    122   # the DOS version of Bison writes out y_tab.c instead of y.tab.c
    123   # and y_tab.h instead of y.tab.h. Test to see if this is the case.
    124   y_tab_nodot="no"
    125   if test -f y_tab.c || test -f y_tab.h; then
    126     y_tab_nodot="yes"
    127   fi
    128 
    129   # The directory holding the input.
    130   input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`
    131   # Quote $INPUT_DIR so we can use it in a regexp.
    132   # FIXME: really we should care about more than `.' and `\'.
    133   input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'`
    134 
    135   while test "$#" -ne 0; do
    136     from="$1"
    137     # Handle y_tab.c and y_tab.h output by DOS
    138     if test $y_tab_nodot = "yes"; then
    139       if test $from = "y.tab.c"; then
    140         from="y_tab.c"
    141       else
    142         if test $from = "y.tab.h"; then
    143           from="y_tab.h"
    144         fi
    145       fi
    146     fi
     181  for from in *
     182  do
     183    to=`printf '%s\n' "$from" | sed "$sed_fix_filenames"`
    147184    if test -f "$from"; then
    148185      # If $2 is an absolute path name, then just use that,
    149       # otherwise prepend `../'.
    150       case "$2" in
    151         [\\/]* | ?:[\\/]*) target="$2";;
    152         *) target="../$2";;
     186      # otherwise prepend '../'.
     187      case $to in
     188        [\\/]* | ?:[\\/]*) target=$to;;
     189        *) target=../$to;;
    153190      esac
    154191
    155       # We do not want to overwrite a header file if it hasn't
    156       # changed.  This avoid useless recompilations.  However the
    157       # parser itself (the first file) should always be updated,
    158       # because it is the destination of the .y.c rule in the
    159       # Makefile.  Divert the output of all other files to a temporary
    160       # file so we can compare them to existing versions.
    161       if test $first = no; then
    162         realtarget="$target"
    163         target="tmp-`echo $target | sed s/.*[\\/]//g`"
     192      # Do not overwrite unchanged header files to avoid useless
     193      # recompilations.  Always update the parser itself: it is the
     194      # destination of the .y.c rule in the Makefile.  Divert the
     195      # output of all other files to a temporary file so we can
     196      # compare them to existing versions.
     197      if test $from != $parser; then
     198        realtarget=$target
     199        target=tmp-`printf '%s\n' "$target" | sed 's|.*[\\/]||g'`
    164200      fi
    165       # Edit out `#line' or `#' directives.
    166       #
    167       # We don't want the resulting debug information to point at
    168       # an absolute srcdir; it is better for it to just mention the
    169       # .y file with no path.
    170       #
    171       # We want to use the real output file name, not yy.lex.c for
    172       # instance.
    173       #
    174       # We want the include guards to be adjusted too.
    175       FROM=`echo "$from" | sed \
    176             -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
    177             -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
    178       TARGET=`echo "$2" | sed \
    179             -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
    180             -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
    181 
    182       sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \
    183           -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?
    184 
    185       # Check whether header files must be updated.
    186       if test $first = no; then
     201
     202      # Munge "#line" or "#" directives.  Don't let the resulting
     203      # debug information point at an absolute srcdir.  Use the real
     204      # output file name, not yy.lex.c for instance.  Adjust the
     205      # include guards too.
     206      sed -e "/^#/!b"                           \
     207          -e "s|$input_rx|$input_sub_rx|"       \
     208          -e "$sed_fix_filenames"               \
     209          -e "$sed_fix_header_guards"           \
     210        "$from" >"$target" || ret=$?
     211
     212      # Check whether files must be updated.
     213      if test "$from" != "$parser"; then
    187214        if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
    188           echo "$2" is unchanged
     215          echo "$to is unchanged"
    189216          rm -f "$target"
    190217        else
    191           echo updating "$2"
     218          echo "updating $to"
    192219          mv -f "$target" "$realtarget"
    193220        fi
    194221      fi
    195222    else
    196       # A missing file is only an error for the first file.  This
    197       # is a blatant hack to let us support using "yacc -d".  If -d
    198       # is not specified, we don't want an error when the header
    199       # file is "missing".
    200       if test $first = yes; then
     223      # A missing file is only an error for the parser.  This is a
     224      # blatant hack to let us support using "yacc -d".  If -d is not
     225      # specified, don't fail when the header file is "missing".
     226      if test "$from" = "$parser"; then
    201227        ret=1
    202228      fi
    203229    fi
    204     shift
    205     shift
    206     first=no
    207230  done
    208 else
    209   ret=$?
    210231fi
    211232
  • doc/LaTeXmacros/common.tex

    r275f4b4 rcd7ef0b  
    1111%% Created On       : Sat Apr  9 10:06:17 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Mon Jul 17 10:21:17 2017
    14 %% Update Count     : 348
     13%% Last Modified On : Mon Jul 24 21:02:14 2017
     14%% Update Count     : 352
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    234234basicstyle=\linespread{0.9}\sf,                                                 % reduce line spacing and use sanserif font
    235235stringstyle=\tt,                                                                                % use typewriter font
    236 tabsize=6,                                                                                              % N space tabbing
     236tabsize=5,                                                                                              % N space tabbing
    237237xleftmargin=\parindentlnth,                                                             % indent code to paragraph indentation
    238238extendedchars=true,                                                                             % allow ASCII characters in the range 128-255
  • doc/LaTeXmacros/lstlang.sty

    r275f4b4 rcd7ef0b  
    88%% Created On       : Sat May 13 16:34:42 2017
    99%% Last Modified By : Peter A. Buhr
    10 %% Last Modified On : Wed Jul 12 22:42:09 2017
    11 %% Update Count     : 12
     10%% Last Modified On : Mon Jul 24 20:40:37 2017
     11%% Update Count     : 13
    1212%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1313
     
    112112                finally, forall, ftype, _Generic, _Imaginary, inline, __label__, lvalue, _Noreturn, one_t,
    113113                otype, restrict, _Static_assert, throw, throwResume, trait, try, ttype, typeof, __typeof,
    114                 __typeof__, with, zero_t},
     114                __typeof__, virtual, with, zero_t},
    115115        morekeywords=[2]{
    116116                _Atomic, coroutine, is_coroutine, is_monitor, is_thread, monitor, mutex, nomutex,
  • doc/generic_types/generic_types.tex

    r275f4b4 rcd7ef0b  
    4949
    5050% Useful macros
    51 \newcommand{\CFA}{C\raisebox{\depth}{\rotatebox{180}{\textsf{A}}}\hspace{-1pt}\xspace} % Cforall symbolic name
    52 %\newcommand{\CFA}{C$\mathbf\forall$\xspace} % Cforall symbolic name
    53 \newcommand{\CC}{\rm C\kern-.1em\hbox{+\kern-.25em+}\xspace} % C++ symbolic name
    54 \newcommand{\CCeleven}{\rm C\kern-.1em\hbox{+\kern-.25em+}11\xspace} % C++11 symbolic name
    55 \newcommand{\CCfourteen}{\rm C\kern-.1em\hbox{+\kern-.25em+}14\xspace} % C++14 symbolic name
    56 \newcommand{\CCseventeen}{\rm C\kern-.1em\hbox{+\kern-.25em+}17\xspace} % C++17 symbolic name
    57 \newcommand{\CCtwenty}{\rm C\kern-.1em\hbox{+\kern-.25em+}20\xspace} % C++20 symbolic name
     51\newcommand{\CFAIcon}{\textsf{C}\raisebox{\depth}{\rotatebox{180}{\textsf{A}}}\xspace} % Cforall symbolic name
     52\newcommand{\CFA}{\protect\CFAIcon} % safe for section/caption
     53\newcommand{\CC}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}\xspace} % C++ symbolic name
     54\newcommand{\CCeleven}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}11\xspace} % C++11 symbolic name
     55\newcommand{\CCfourteen}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}14\xspace} % C++14 symbolic name
     56\newcommand{\CCseventeen}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}17\xspace} % C++17 symbolic name
     57\newcommand{\CCtwenty}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}20\xspace} % C++20 symbolic name
    5858\newcommand{\CCV}{\rm C\kern-.1em\hbox{+\kern-.25em+}obj\xspace} % C++ virtual symbolic name
    5959\newcommand{\Csharp}{C\raisebox{-0.7ex}{\Large$^\sharp$}\xspace} % C# symbolic name
     
    443443This function could acquire the layout for @set(T)@ by calling its layout function with the layout of @T@ implicitly passed into the function.
    444444
    445 Whether a type is concrete, dtype-static, or dynamic is decided solely on the type parameters and @forall@ clause on a declaration.
    446 This design allows opaque forward declarations of generic types, \eg @forall(otype T) struct Box@ -- like in C, all uses of @Box(T)@ can be separately compiled, and callers from other translation units know the proper calling conventions to use.
    447 If the definition of a structure type is included in deciding whether a generic type is dynamic or concrete, some further types may be recognized as dtype-static (\eg @forall(otype T) struct unique_ptr { T * p }@ does not depend on @T@ for its layout, but the existence of an @otype@ parameter means that it \emph{could}.), but preserving separate compilation (and the associated C compatibility) in the existing design is judged to be an appropriate trade-off.
     445Whether a type is concrete, dtype-static, or dynamic is decided solely on the @forall@'s type parameters.
     446This design allows opaque forward declarations of generic types, \eg @forall(otype T)@ @struct Box@ -- like in C, all uses of @Box(T)@ can be separately compiled, and callers from other translation units know the proper calling conventions to use.
     447If the definition of a structure type is included in deciding whether a generic type is dynamic or concrete, some further types may be recognized as dtype-static (\eg @forall(otype T)@ @struct unique_ptr { T * p }@ does not depend on @T@ for its layout, but the existence of an @otype@ parameter means that it \emph{could}.), but preserving separate compilation (and the associated C compatibility) in the existing design is judged to be an appropriate trade-off.
    448448
    449449
     
    855855}
    856856\end{lstlisting}
     857\begin{sloppypar}
    857858Tuple expressions are then simply converted directly into compound literals, \eg @[5, 'x', 1.24]@ becomes @(_tuple3(int, char, double)){ 5, 'x', 1.24 }@.
     859\end{sloppypar}
    858860
    859861\begin{comment}
  • doc/refrat/Makefile

    r275f4b4 rcd7ef0b  
    99SOURCES = ${addsuffix .tex, \
    1010refrat \
     11keywords \
     12operidents \
    1113}
    1214
  • doc/refrat/refrat.tex

    r275f4b4 rcd7ef0b  
    1111%% Created On       : Wed Apr  6 14:52:25 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Fri Jun  2 10:43:14 2017
    14 %% Update Count     : 83
     13%% Last Modified On : Sun Aug  6 10:25:31 2017
     14%% Update Count     : 105
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
    1717% requires tex packages: texlive-base texlive-latex-base tex-common texlive-humanities texlive-latex-extra texlive-fonts-recommended
    1818
    19 \documentclass[openright,twoside]{report}
     19\documentclass[openright,twoside,11pt]{report}
    2020
    2121%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    3737\usepackage{mathptmx}                                   % better math font with "times"
    3838\usepackage[usenames]{color}
    39 \usepackage[pagewise]{lineno}
    40 \renewcommand{\linenumberfont}{\scriptsize\sffamily}
    41 \input{common}                                          % bespoke macros used in the document
     39\input{common}                                          % common CFA document macros
    4240\usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref}
    4341\usepackage{breakurl}
    4442\renewcommand{\UrlFont}{\small\sf}
    4543
     44\usepackage[pagewise]{lineno}
     45\renewcommand{\linenumberfont}{\scriptsize\sffamily}
     46\usepackage[firstpage]{draftwatermark}
     47\SetWatermarkLightness{0.9}
     48
     49% Default underscore is too low and wide. Cannot use lstlisting "literate" as replacing underscore
     50% removes it as a variable-name character so keywords in variables are highlighted. MUST APPEAR
     51% AFTER HYPERREF.
     52\renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
     53
    4654\setlength{\topmargin}{-0.45in}                                                 % move running title into header
    4755\setlength{\headsep}{0.25in}
     
    5058
    5159\CFAStyle                                                                                               % use default CFA format-style
     60\lstnewenvironment{C++}[1][]                            % use C++ style
     61{\lstset{language=C++,moredelim=**[is][\protect\color{red}]{®}{®}#1}}
     62{}
    5263
    5364% inline code ©...© (copyright symbol) emacs: C-q M-)
     
    8798
    8899\date{
    89 DRAFT \\ \today
     100\today
    90101}% date
    91102
     
    112123
    113124\clearpage
     125\thispagestyle{plain}
    114126\pdfbookmark[1]{Contents}{section}
    115127\tableofcontents
    116128
    117129\clearpage
     130\thispagestyle{plain}
    118131\pagenumbering{arabic}
    119132
     
    417430
    418431\begin{syntax}
    419 \oldlhs{keyword}
    420 \rhs ©forall©
    421 \rhs ©lvalue©
    422 \rhs ©trait©
    423 \rhs ©dtype©
    424 \rhs ©ftype©
    425 \rhs ©otype©
     432\lhs{keyword} one of
     433\rhs \dots
     434\rhs \input{keywords}
    426435\end{syntax}
    427436
     
    469478
    470479\begin{table}[hbt]
    471 \hfil
    472 \begin{tabular}[t]{ll}
    473 %identifier & operation \\ \hline
    474 ©?[?]© & subscripting \impl{?[?]}\\
    475 ©?()© & function call \impl{?()}\\
    476 ©?++© & postfix increment \impl{?++}\\
    477 ©?--© & postfix decrement \impl{?--}\\
    478 ©++?© & prefix increment \impl{++?}\\
    479 ©--?© & prefix decrement \impl{--?}\\
    480 ©*?© & dereference \impl{*?}\\
    481 ©+?© & unary plus \impl{+?}\\
    482 ©-?© & arithmetic negation \impl{-?}\\
    483 ©~?© & bitwise negation \impl{~?}\\
    484 ©!?© & logical complement \impl{"!?}\\
    485 ©?*?© & multiplication \impl{?*?}\\
    486 ©?/?© & division \impl{?/?}\\
    487 \end{tabular}\hfil
    488 \begin{tabular}[t]{ll}
    489 %identifier & operation \\ \hline
    490 ©?%?© & remainder \impl{?%?}\\
    491 ©?+?© & addition \impl{?+?}\\
    492 ©?-?© & subtraction \impl{?-?}\\
    493 ©?<<?© & left shift \impl{?<<?}\\
    494 ©?>>?© & right shift \impl{?>>?}\\
    495 ©?<?© & less than \impl{?<?}\\
    496 ©?<=?© & less than or equal \impl{?<=?}\\
    497 ©?>=?© & greater than or equal \impl{?>=?}\\
    498 ©?>?© & greater than \impl{?>?}\\
    499 ©?==?© & equality \impl{?==?}\\
    500 ©?!=?© & inequality \impl{?"!=?}\\
    501 ©?&?© & bitwise AND \impl{?&?}\\
    502 \end{tabular}\hfil
    503 \begin{tabular}[t]{ll}
    504 %identifier & operation \\ \hline
    505 ©?^?© & exclusive OR \impl{?^?}\\
    506 ©?|?© & inclusive OR \impl{?"|?}\\
    507 ©?=?© & simple assignment \impl{?=?}\\
    508 ©?*=?© & multiplication assignment \impl{?*=?}\\
    509 ©?/=?© & division assignment \impl{?/=?}\\
    510 ©?%=?© & remainder assignment \impl{?%=?}\\
    511 ©?+=?© & addition assignment \impl{?+=?}\\
    512 ©?-=?© & subtraction assignment \impl{?-=?}\\
    513 ©?<<=?© & left-shift assignment \impl{?<<=?}\\
    514 ©?>>=?© & right-shift assignment \impl{?>>=?}\\
    515 ©?&=?© & bitwise AND assignment \impl{?&=?}\\
    516 ©?^=?© & exclusive OR assignment \impl{?^=?}\\
    517 ©?|=?© & inclusive OR assignment \impl{?"|=?}\\
    518 \end{tabular}
    519 \hfil
     480\centering
     481\input{operidents}
    520482\caption{Operator Identifiers}
    521483\label{opids}
  • doc/rob_thesis/Makefile

    r275f4b4 rcd7ef0b  
    1 ## Define the appropriate configuration variables.
    2 
    3 TeXLIB = .:../LaTeXmacros:../LaTeXmacros/listings:../LaTeXmacros/enumitem:../bibliography/:
     1TeXLIB = .:../LaTeXmacros:../bibliography/:
    42LaTeX  = TEXINPUTS=${TeXLIB} && export TEXINPUTS && pdflatex -halt-on-error
    53BibTeX = BIBINPUTS=${TeXLIB} && export BIBINPUTS && bibtex
    64
    7 ## Define the text source files.
     5all : thesis.pdf
    86
    9 # SOURCES = ${addsuffix .tex, \
    10 # thesis \
    11 # }
     7thesis.pdf : Makefile ../LaTeXmacros/common.tex cfa-format.tex thesis.tex intro.tex ctordtor.tex tuples.tex variadic.tex conclusions.tex
     8        ${LaTeX} thesis
     9        ${BibTeX} thesis
     10        ${LaTeX} thesis
     11        ${LaTeX} thesis
     12        pdf2ps thesis.pdf thesis.ps
    1213
    13 # FIGURES = ${addsuffix .tex, \
    14 # }
    15 
    16 # PICTURES = ${addsuffix .pstex, \
    17 # }
    18 
    19 # PROGRAMS = ${addsuffix .tex, \
    20 # }
    21 
    22 # GRAPHS = ${addsuffix .tex, \
    23 # }
    24 
    25 # ## Define the documents that need to be made.
    26 
    27 # DOCUMENT = thesis.pdf
    28 
    29 # Directives #
    30 
    31 # all : ${DOCUMENT}
    32 
    33 # clean :
    34 #       rm -f *.bbl *.aux *.dvi *.idx *.ilg *.ind *.brf *.out *.log *.toc *.blg *.pstex_t *.cf \
    35 #               ${FIGURES} ${PICTURES} ${PROGRAMS} ${GRAPHS} ${basename ${DOCUMENT}}.ps ${DOCUMENT}
    36 
    37 # File Dependencies #
    38 
    39 # ${DOCUMENT} : ${basename ${DOCUMENT}}.ps
    40 #       ps2pdf $<
    41 
    42 # ${basename ${DOCUMENT}}.ps : ${basename ${DOCUMENT}}.dvi
    43 #       dvips $< -o $@
    44 
    45 # ${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex \
    46 #               ../LaTeXmacros/common.tex ../LaTeXmacros/indexstyle ../bibliography/cfa.bib
    47 #       # Conditionally create an empty *.ind (index) file for inclusion until makeindex is run.
    48 #       if [ ! -r ${basename $@}.ind ] ; then touch ${basename $@}.ind ; fi
    49 #       # Must have *.aux file containing citations for bibtex
    50 #       if [ ! -r ${basename $@}.aux ] ; then ${LaTeX} ${basename $@}.tex ; fi
    51 #       -${BibTeX} ${basename $@}
    52 #       # Some citations reference others so run steps again to resolve these citations
    53 #       ${LaTeX} ${basename $@}.tex
    54 #       -${BibTeX} ${basename $@}
    55 #       # Make index from *.aux entries and input index at end of document
    56 #       makeindex -s ../LaTeXmacros/indexstyle ${basename $@}.idx
    57 #       ${LaTeX} ${basename $@}.tex
    58 #       # Run again to get index title into table of contents
    59 #       ${LaTeX} ${basename $@}.tex
    60 
    61 # predefined :
    62 #       sed -f predefined.sed ${basename ${DOCUMENT}}.tex > ${basename $@}.cf
    63 
    64 # ## Define the default recipes.
    65 
    66 # %.tex : %.fig
    67 #       fig2dev -L eepic $< > $@
    68 
    69 # %.ps : %.fig
    70 #       fig2dev -L ps $< > $@
    71 
    72 # %.pstex : %.fig
    73 #       fig2dev -L pstex $< > $@
    74 #       fig2dev -L pstex_t -p $@ $< > $@_t
    75 
    76 
    77 all:
    78         $(LaTeX) thesis
    79         $(BibTeX) thesis
    80         $(LaTeX) thesis
    81         $(LaTeX) thesis
    82 
    83 clean:
     14clean :
    8415        rm -f *.aux *.bbl *.blg *.lof *.log *.lot *.out *.toc
    8516
    86 splotless: clean
    87         rm -f thesis.pdf
     17spotless : clean
     18        rm -f thesis.pdf thesis.ps
  • doc/rob_thesis/thesis.tex

    r275f4b4 rcd7ef0b  
    135135    pdfpagelabels=true,     % adds page number as label in Acrobat's page count
    136136    bookmarks=true,         % show bookmarks bar?
    137     unicode=false,          % non-Latin characters in Acrobats bookmarks
    138     pdftoolbar=true,        % show Acrobats toolbar?
    139     pdfmenubar=true,        % show Acrobats menu?
     137    unicode=false,          % non-Latin characters in Acrobat's bookmarks
     138    pdftoolbar=true,        % show Acrobat's toolbar?
     139    pdfmenubar=true,        % show Acrobat's menu?
    140140    pdffitwindow=false,     % window fit to page when opened
    141141    pdfstartview={FitH},    % fits the width of the page to the window
  • doc/user/Makefile

    r275f4b4 rcd7ef0b  
    99SOURCES = ${addsuffix .tex, \
    1010user \
     11../refrat/keywords \
     12../refrat/operidents \
    1113}
    1214
  • doc/user/user.tex

    r275f4b4 rcd7ef0b  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sat Jul 22 11:01:19 2017
    14 %% Update Count     : 2878
     13%% Last Modified On : Sun Aug  6 10:24:21 2017
     14%% Update Count     : 3036
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    3737\usepackage{mathptmx}                                   % better math font with "times"
    3838\usepackage[usenames]{color}
    39 \usepackage[pagewise]{lineno}
    40 \renewcommand{\linenumberfont}{\scriptsize\sffamily}
    4139\input{common}                                          % common CFA document macros
    4240\usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref}
     
    4442\renewcommand{\UrlFont}{\small\sf}
    4543
     44\usepackage[pagewise]{lineno}
     45\renewcommand{\linenumberfont}{\scriptsize\sffamily}
     46\usepackage[firstpage]{draftwatermark}
     47\SetWatermarkLightness{0.9}
     48
    4649% Default underscore is too low and wide. Cannot use lstlisting "literate" as replacing underscore
    4750% removes it as a variable-name character so keywords in variables are highlighted. MUST APPEAR
    4851% AFTER HYPERREF.
    49 \renewcommand{\_}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
    5052\renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
    5153
     
    5658
    5759\CFAStyle                                                                                               % use default CFA format-style
    58 
    59 \lstnewenvironment{C++}[1][]
     60\lstnewenvironment{C++}[1][]                            % use C++ style
    6061{\lstset{language=C++,moredelim=**[is][\protect\color{red}]{®}{®}#1}}
    6162{}
     
    7879\newcommand{\B}[1]{{\Textbf[blue]{#1}}}
    7980\newcommand{\G}[1]{{\Textbf[OliveGreen]{#1}}}
     81\newcommand{\KWC}{K-W C\xspace}
    8082
    8183\newsavebox{\LstBox}
     
    105107
    106108\date{
    107 DRAFT \\ \today
     109\today
    108110}% date
    109111
     
    197199This document is a programmer reference-manual for the \CFA programming language.
    198200The manual covers the core features of the language and runtime-system, with simple examples illustrating syntax and semantics of each feature.
    199 The manual does not teach programming, i.e., how to combine the new constructs to build complex programs.
     201The manual does not teach programming, \ie how to combine the new constructs to build complex programs.
    200202A reader should already have an intermediate knowledge of control flow, data structures, and concurrency issues to understand the ideas presented, as well as some experience programming in C/\CC.
    201203Implementers should refer to the \CFA Programming Language Specification for details about the language syntax and semantics.
     
    247249\section{History}
    248250
    249 The \CFA project started with \Index*{K-W C}~\cite{Buhr94a,Till89}, which extended C with new declaration syntax, multiple return values from routines, and advanced assignment capabilities using the notion of tuples.
     251The \CFA project started with \Index*{Dave Till}\index{Till, Dave}'s \Index*{K-W C}~\cite{Buhr94a,Till89}, which extended C with new declaration syntax, multiple return values from routines, and advanced assignment capabilities using the notion of tuples.
    250252(See~\cite{Werther96} for similar work in \Index*[C++]{\CC{}}.)
    251 The first \CFA implementation of these extensions was by Esteves~\cite{Esteves04}.
     253The first \CFA implementation of these extensions was by \Index*{Rodolfo Esteves}\index{Esteves, Rodolfo}~\cite{Esteves04}.
    252254
    253255The signature feature of \CFA is \emph{\Index{overload}able} \Index{parametric-polymorphic} functions~\cite{forceone:impl,Cormack90,Duggan96} with functions generalized using a ©forall© clause (giving the language its name):
     
    257259\end{lstlisting}
    258260% extending the C type system with parametric polymorphism and overloading, as opposed to the \Index*[C++]{\CC{}} approach of object-oriented extensions.
    259 \CFA{}\hspace{1pt}'s polymorphism was originally formalized by Ditchfield~\cite{Ditchfield92}, and first implemented by Bilson~\cite{Bilson03}.
     261\CFA{}\hspace{1pt}'s polymorphism was originally formalized by \Index*{Glen Ditchfield}\index{Ditchfield, Glen}~\cite{Ditchfield92}, and first implemented by \Index*{Richard Bilson}\index{Bilson, Richard}~\cite{Bilson03}.
    260262However, at that time, there was little interesting in extending C, so work did not continue.
    261263As the saying goes, ``\Index*{What goes around, comes around.}'', and there is now renewed interest in the C programming language because of legacy code-bases, so the \CFA project has been restarted.
     
    344346The command ©cfa© is used to compile a \CFA program and is based on the \Index{GNU} \Indexc{gcc} command, \eg:
    345347\begin{cfa}
    346 cfa§\indexc{cfa}\index{compilation!cfa@©cfa©}§ [ gcc-options ] C/§\CFA{}§-files [ assembler/loader-files ]
     348cfa§\indexc{cfa}\index{compilation!cfa@©cfa©}§ [ gcc-options ] [ C/§\CFA{}§ source-files ] [ assembler/loader files ]
    347349\end{cfa}
    348350\CFA programs having the following ©gcc© flags turned on:
     
    509511For both ©continue© and ©break©, the target label must be directly associated with a ©for©, ©while© or ©do© statement;
    510512for ©break©, the target label can also be associated with a ©switch©, ©if© or compound (©{}©) statement.
    511 \VRef[Figure]{f:MultiLevelResumeTermination} shows the labelled ©continue© and ©break©, specifying which control structure is the target for exit, and the corresponding C program using only ©goto©.
    512 The innermost loop has 7 exit points, which cause resumption or termination of one or more of the 7 \Index{nested control-structure}s.
     513\VRef[Figure]{f:MultiLevelExit} shows ©continue© and ©break© indicating the specific control structure, and the corresponding C program using only ©goto© and labels.
     514The innermost loop has 7 exit points, which cause continuation or termination of one or more of the 7 \Index{nested control-structure}s.
    513515
    514516\begin{figure}
    515 \begin{tabular}{@{\hspace{\parindentlnth}}l@{\hspace{1.5em}}l@{}}
    516 \multicolumn{1}{c@{\hspace{1.5em}}}{\textbf{\CFA}}      & \multicolumn{1}{c}{\textbf{C}}        \\
     517\begin{tabular}{@{\hspace{\parindentlnth}}l@{\hspace{\parindentlnth}}l@{\hspace{\parindentlnth}}l@{}}
     518\multicolumn{1}{@{\hspace{\parindentlnth}}c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}   & \multicolumn{1}{@{\hspace{\parindentlnth}}c}{\textbf{C}}      \\
    517519\begin{cfa}
    518520®LC:® {
     
    523525                        ®LF:® for ( ... ) {
    524526                                ®LW:® while ( ... ) {
    525                                         ... break ®LC®; ...             // terminate compound
    526                                         ... break ®LS®; ...             // terminate switch
    527                                         ... break ®LIF®; ...    // terminate if
    528                                         ... continue ®LF;® ...  // resume loop
    529                                         ... break ®LF®; ...             // terminate loop
    530                                         ... continue ®LW®; ...  // resume loop
    531                                         ... break ®LW®; ...             // terminate loop
     527                                        ... break ®LC®; ...
     528                                        ... break ®LS®; ...
     529                                        ... break ®LIF®; ...
     530                                        ... continue ®LF;® ...
     531                                        ... break ®LF®; ...
     532                                        ... continue ®LW®; ...
     533                                        ... break ®LW®; ...
    532534                                } // while
    533535                        } // for
    534536                } else {
    535                         ... break ®LIF®; ...                    // terminate if
     537                        ... break ®LIF®; ...
    536538                } // if
    537539        } // switch
     
    562564} ®LC:® ;
    563565\end{cfa}
     566&
     567\begin{cfa}
     568
     569
     570
     571
     572
     573
     574
     575// terminate compound
     576// terminate switch
     577// terminate if
     578// continue loop
     579// terminate loop
     580// continue loop
     581// terminate loop
     582
     583
     584
     585// terminate if
     586
     587
     588
     589\end{cfa}
    564590\end{tabular}
    565 \caption{Multi-level Resume/Termination}
    566 \label{f:MultiLevelResumeTermination}
     591\caption{Multi-level Exit}
     592\label{f:MultiLevelExit}
    567593\end{figure}
    568 
    569 \begin{comment}
    570 int main() {
    571   LC: {
    572           LS: switch ( 1 ) {
    573                   case 3:
    574                   LIF: if ( 1 ) {
    575                           LF: for ( ;; ) {
    576                                   LW: while ( 1 ) {
    577                                                 break LC;               // terminate compound
    578                                                 break LS;               // terminate switch
    579                                                 break LIF;              // terminate if
    580                                                 continue LF;    // resume loop
    581                                                 break LF;               // terminate loop
    582                                                 continue LW;    // resume loop
    583                                                 break LW;               // terminate loop
    584                                         } // while
    585                                 } // for
    586                         } else {
    587                                 break LIF;                               // terminate if
    588                         } // if
    589                 } // switch
    590         } // compound
    591         {
    592                 switch ( 1 ) {
    593                   case 3:
    594                         if ( 1 ) {
    595                                 for ( ;; ) {
    596                                         while ( 1 ) {
    597                                                 goto LCx;
    598                                                 goto LSx;
    599                                                 goto LIF;
    600                                                 goto LFC;
    601                                                 goto LFB;
    602                                                 goto LWC;
    603                                                 goto LWB;
    604                                           LWC: ; } LWB: ;
    605                                   LFC: ; } LFB: ;
    606                         } else {
    607                                 goto LIF;
    608                         } L3: ;
    609                 } LSx: ;
    610         } LCx: ;
    611 }
    612 
    613 // Local Variables: //
    614 // tab-width: 4 //
    615 // End: //
    616 \end{comment}
    617 
    618594
    619595Both labelled ©continue© and ©break© are a ©goto©\index{goto@\lstinline $goto$!restricted} restricted in the following ways:
     
    920896class C {
    921897        int i, j;
    922         int mem() {              ®// implicit "this" parameter
    923 ®               i = 1;          ®// this->i
    924 ®               j = 3;          ®// this->j
    925 ®       }
     898        int mem() {                                     §\C{\color{red}// implicit "this" parameter}§
     899                i = 1;                                  §\C{\color{red}// this->i}§
     900                j = 2;                                  §\C{\color{red}// this->j}§
     901        }
    926902}
    927903\end{C++}
     
    929905\begin{cfa}
    930906struct S { int i, j; };
    931 int mem( S &this ) {    // explicit "this" parameter
    932         ®this.®i = 1;                     // "this" is not elided
     907int mem( S &®this® ) {                  §\C{// explicit "this" parameter}§
     908        ®this.®i = 1;                           §\C{// "this" is not elided}§
    933909        ®this.®j = 2;
    934910}
     
    938914\CFA provides a ©with© clause/statement (see Pascal~\cite[\S~4.F]{Pascal}) to elided the "©this.©" by opening a scope containing field identifiers, changing the qualified fields into variables and giving an opportunity for optimizing qualified references.
    939915\begin{cfa}
    940 int mem( S &this ) ®with this® {        // with clause
    941         i = 1;                  ®// this.i
    942 ®       j = 2;                  ®// this.j
    943 ®}
     916int mem( S &this ) ®with this® { §\C{// with clause}§
     917        i = 1;                                          §\C{\color{red}// this->i}§
     918        j = 2;                                          §\C{\color{red}// this->j}§
     919}
    944920\end{cfa}
    945921which extends to multiple routine parameters:
     
    992968Exception handling provides two mechanism: change of control flow from a raise to a handler, and communication from the raise to the handler.
    993969Transfer of control can be local, within a routine, or non-local, among routines.
    994 Non-local transfer can cause stack unwinding, i.e., non-local routine termination, depending on the kind of raise.
     970Non-local transfer can cause stack unwinding, \ie non-local routine termination, depending on the kind of raise.
    995971\begin{cfa}
    996972exception_t E {};                               §\C{// exception type}§
     
    1001977try {
    1002978        f(...);
    1003 } catch( E e : §boolean-predicate§ ) {                  §\C{// termination handler}§
     979} catch( E e : §boolean-predicate§ ) {                  §\C[8cm]{// termination handler}§
    1004980        // recover and continue
    1005 } catchResume( E e : §boolean-predicate§ ) {    §\C{// resumption handler}§
     981} catchResume( E e : §boolean-predicate§ ) {    §\C{// resumption handler}\CRT§
    1006982        // repair and return
    1007983} finally {
     
    12301206
    12311207As for \Index{division}, there are exponentiation operators for integral and floating-point types, including the builtin \Index{complex} types.
    1232 Unsigned integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication (or shifting if the base is 2).
    1233 Signed integral exponentiation\index{exponentiation!signed integral} is performed with repeated multiplication (or shifting if the base is 2), but yields a floating-point result because $b^{-e}=1/b^e$.
     1208Unsigned integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication\footnote{The multiplication computation is optimized to $O(\log y)$.} (or shifting if the base is 2).
     1209Signed integral exponentiation\index{exponentiation!signed integral} is performed with repeated multiplication (or shifting if the base is 2), but yields a floating-point result because $x^{-y}=1/x^y$.
    12341210Hence, it is important to designate exponent integral-constants as unsigned or signed: ©3 \ 3u© return an integral result, while ©3 \ 3© returns a floating-point result.
    12351211Floating-point exponentiation\index{exponentiation!floating point} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the base cannot be negative.
     
    14461422int w, x, y, z, & ar[3] = { x, y, z }; §\C{// initialize array of references}§
    14471423&ar[1] = &w;                                            §\C{// change reference array element}§
    1448 typeof( ar[1] ) p;                                      §\C{// (gcc) is int, i.e., the type of referenced object}§
    1449 typeof( &ar[1] ) q;                                     §\C{// (gcc) is int \&, i.e., the type of reference}§
    1450 sizeof( ar[1] ) == sizeof( int );       §\C{// is true, i.e., the size of referenced object}§
    1451 sizeof( &ar[1] ) == sizeof( int *)      §\C{// is true, i.e., the size of a reference}§
     1424typeof( ar[1] ) p;                                      §\C{// (gcc) is int, \ie the type of referenced object}§
     1425typeof( &ar[1] ) q;                                     §\C{// (gcc) is int \&, \ie the type of reference}§
     1426sizeof( ar[1] ) == sizeof( int );       §\C{// is true, \ie the size of referenced object}§
     1427sizeof( &ar[1] ) == sizeof( int *)      §\C{// is true, \ie the size of a reference}§
    14521428\end{cfa}
    14531429
     
    17881764
    17891765In detail, the brackets, ©[]©, enclose the result type, where each return value is named and that name is a local variable of the particular return type.\footnote{
    1790 \Index*{Michael Tiemann}, with help from \Index*{Doug Lea}, provided named return values in g++, circa 1989.}
     1766\Index*{Michael Tiemann}\index{Tiemann, Michael}, with help from \Index*{Doug Lea}\index{Lea, Doug}, provided named return values in g++, circa 1989.}
    17911767The value of each local return variable is automatically returned at routine termination.
    17921768Declaration qualifiers can only appear at the start of a routine definition, \eg:
     
    22452221
    22462222Currently, there are no \Index{lambda} expressions, \ie unnamed routines because routine names are very important to properly select the correct routine.
     2223
     2224
     2225\section{Tuple}
     2226
     2227In C and \CFA, lists of elements appear in several contexts, such as the parameter list of a routine call.
     2228\begin{cfa}
     2229f( ®2, x, 3 + i® );                             §\C{// element list}§
     2230\end{cfa}
     2231A list of elements is called a \newterm{tuple}, and is different from a \Index{comma expression}.
     2232
     2233
     2234\subsection{Multiple-Return-Value Functions}
     2235\label{s:MRV_Functions}
     2236
     2237In standard C, functions can return at most one value.
     2238To emulate functions with multiple return values, \emph{\Index{aggregation}} and/or \emph{\Index{aliasing}} is used.
     2239In the former situation, the function designer creates a record type that combines all of the return values into a single type.
     2240For example, consider a function returning the most frequently occurring letter in a string, and its frequency.
     2241This example is complex enough to illustrate that an array is insufficient, since arrays are homogeneous, and demonstrates a potential pitfall that exists with aliasing.
     2242\begin{cfa}
     2243struct mf_ret {
     2244        int freq;
     2245        char ch;
     2246};
     2247
     2248struct mf_ret most_frequent(const char * str) {
     2249        char freqs [26] = { 0 };
     2250        struct mf_ret ret = { 0, 'a' };
     2251        for (int i = 0; str[i] != '\0'; ++i) {
     2252                if (isalpha(str[i])) {        // only count letters
     2253                        int ch = tolower(str[i]);   // convert to lower case
     2254                        int idx = ch-'a';
     2255                        if (++freqs[idx] > ret.freq) {  // update on new max
     2256                          ret.freq = freqs[idx];
     2257                          ret.ch = ch;
     2258                        }
     2259                }
     2260        }
     2261        return ret;
     2262}
     2263
     2264const char * str = "hello world";
     2265struct mf_ret ret = most_frequent(str);
     2266printf("%s -- %d %c\n", str, ret.freq, ret.ch);
     2267\end{cfa}
     2268Of note, the designer must come up with a name for the return type and for each of its fields.
     2269Unnecessary naming is a common programming language issue, introducing verbosity and a complication of the user's mental model.
     2270That is, adding another named type creates another association in the programmer's mind that needs to be kept track of when reading and writing code.
     2271As such, this technique is effective when used sparingly, but can quickly get out of hand if many functions need to return different combinations of types.
     2272
     2273In the latter approach, the designer simulates multiple return values by passing the additional return values as pointer parameters.
     2274The pointer parameters are assigned inside of the routine body to emulate a return.
     2275Using the same example,
     2276\begin{cfa}
     2277int most_frequent(const char * str, char * ret_ch) {
     2278        char freqs [26] = { 0 };
     2279        int ret_freq = 0;
     2280        for (int i = 0; str[i] != '\0'; ++i) {
     2281                if (isalpha(str[i])) {        // only count letters
     2282                        int ch = tolower(str[i]);   // convert to lower case
     2283                        int idx = ch-'a';
     2284                        if (++freqs[idx] > ret_freq) {  // update on new max
     2285                          ret_freq = freqs[idx];
     2286                          *ret_ch = ch;   // assign to out parameter
     2287                        }
     2288                }
     2289        }
     2290        return ret_freq;  // only one value returned directly
     2291}
     2292
     2293const char * str = "hello world";
     2294char ch;                            // pre-allocate return value
     2295int freq = most_frequent(str, &ch); // pass return value as out parameter
     2296printf("%s -- %d %c\n", str, freq, ch);
     2297\end{cfa}
     2298Notably, using this approach, the caller is directly responsible for allocating storage for the additional temporary return values, which complicates the call site with a sequence of variable declarations leading up to the call.
     2299Also, while a disciplined use of ©const© can give clues about whether a pointer parameter is going to be used as an out parameter, it is not immediately obvious from only the routine signature whether the callee expects such a parameter to be initialized before the call.
     2300Furthermore, while many C routines that accept pointers are designed so that it is safe to pass ©NULL© as a parameter, there are many C routines that are not null-safe.
     2301On a related note, C does not provide a standard mechanism to state that a parameter is going to be used as an additional return value, which makes the job of ensuring that a value is returned more difficult for the compiler.
     2302Interestingly, there is a subtle bug in the previous example, in that ©ret_ch© is never assigned for a string that does not contain any letters, which can lead to undefined behaviour.
     2303In this particular case, it turns out that the frequency return value also doubles as an error code, where a frequency of 0 means the character return value should be ignored.
     2304Still, not every routine with multiple return values should be required to return an error code, and error codes are easily ignored, so this is not a satisfying solution.
     2305As with the previous approach, this technique can simulate multiple return values, but in practice it is verbose and error prone.
     2306
     2307In \CFA, functions can be declared to return multiple values with an extension to the function declaration syntax.
     2308Multiple return values are declared as a comma-separated list of types in square brackets in the same location that the return type appears in standard C function declarations.
     2309The ability to return multiple values from a function requires a new syntax for the return statement.
     2310For consistency, the return statement in \CFA accepts a comma-separated list of expressions in square brackets.
     2311The expression resolution phase of the \CFA translator ensures that the correct form is used depending on the values being returned and the return type of the current function.
     2312A multiple-returning function with return type ©T© can return any expression that is implicitly convertible to ©T©.
     2313Using the running example, the ©most_frequent© function can be written using multiple return values as such,
     2314\begin{cfa}
     2315[int, char] most_frequent(const char * str) {
     2316        char freqs [26] = { 0 };
     2317        int ret_freq = 0;
     2318        char ret_ch = 'a';  // arbitrary default value for consistent results
     2319        for (int i = 0; str[i] != '\0'; ++i) {
     2320                if (isalpha(str[i])) {        // only count letters
     2321                        int ch = tolower(str[i]);   // convert to lower case
     2322                        int idx = ch-'a';
     2323                        if (++freqs[idx] > ret_freq) {  // update on new max
     2324                          ret_freq = freqs[idx];
     2325                          ret_ch = ch;
     2326                        }
     2327                }
     2328        }
     2329        return [ret_freq, ret_ch];
     2330}
     2331\end{cfa}
     2332This approach provides the benefits of compile-time checking for appropriate return statements as in aggregation, but without the required verbosity of declaring a new named type, which precludes the bug seen with out-parameters.
     2333
     2334The addition of multiple-return-value functions necessitates a syntax for accepting multiple values at the call-site.
     2335The simplest mechanism for retaining a return value in C is variable assignment.
     2336By assigning the return value into a variable, its value can be retrieved later at any point in the program.
     2337As such, \CFA allows assigning multiple values from a function into multiple variables, using a square-bracketed list of lvalue expressions on the left side.
     2338\begin{cfa}
     2339const char * str = "hello world";
     2340int freq;
     2341char ch;
     2342[freq, ch] = most_frequent(str);  // assign into multiple variables
     2343printf("%s -- %d %c\n", str, freq, ch);
     2344\end{cfa}
     2345It is also common to use a function's output as the input to another function.
     2346\CFA also allows this case, without any new syntax.
     2347When a function call is passed as an argument to another call, the expression resolver attempts to find the best match of actual arguments to formal parameters given all of the possible expression interpretations in the current scope \cite{Bilson03}.
     2348For example,
     2349\begin{cfa}
     2350void process(int);       // (1)
     2351void process(char);      // (2)
     2352void process(int, char); // (3)
     2353void process(char, int); // (4)
     2354
     2355process(most_frequent("hello world"));  // selects (3)
     2356\end{cfa}
     2357In this case, there is only one option for a function named ©most_frequent© that takes a string as input.
     2358This function returns two values, one ©int© and one ©char©.
     2359There are four options for a function named ©process©, but only two that accept two arguments, and of those the best match is (3), which is also an exact match.
     2360This expression first calls ©most_frequent("hello world")©, which produces the values ©3© and ©'l'©, which are fed directly to the first and second parameters of (3), respectively.
     2361
     2362\section{Tuple Expressions}
     2363Multiple-return-value functions provide \CFA with a new syntax for expressing a combination of expressions in the return statement and a combination of types in a function signature.
     2364These notions can be generalized to provide \CFA with \emph{tuple expressions} and \emph{tuple types}.
     2365A tuple expression is an expression producing a fixed-size, ordered list of values of heterogeneous types.
     2366The type of a tuple expression is the tuple of the subexpression types, or a \emph{tuple type}.
     2367In \CFA, a tuple expression is denoted by a comma-separated list of expressions enclosed in square brackets.
     2368For example, the expression ©[5, 'x', 10.5]© has type ©[int, char, double]©.
     2369The previous expression has 3 \emph{components}.
     2370Each component in a tuple expression can be any \CFA expression, including another tuple expression.
     2371The order of evaluation of the components in a tuple expression is unspecified, to allow a compiler the greatest flexibility for program optimization.
     2372It is, however, guaranteed that each component of a tuple expression is evaluated for side-effects, even if the result is not used.
     2373Multiple-return-value functions can equivalently be called \emph{tuple-returning functions}.
     2374
     2375\subsection{Tuple Variables}
     2376The call-site of the ©most_frequent© routine has a notable blemish, in that it required the preallocation of return variables in a manner similar to the aliasing example, since it is impossible to declare multiple variables of different types in the same declaration in standard C.
     2377In \CFA, it is possible to overcome this restriction by declaring a \emph{tuple variable}.
     2378\begin{cfa}[emph=ret, emphstyle=\color{red}]
     2379const char * str = "hello world";
     2380[int, char] ret = most_frequent(str);  // initialize tuple variable
     2381printf("%s -- %d %c\n", str, ret);
     2382\end{cfa}
     2383It is now possible to accept multiple values into a single piece of storage, in much the same way that it was previously possible to pass multiple values from one function call to another.
     2384These variables can be used in any of the contexts where a tuple expression is allowed, such as in the ©printf© function call.
     2385As in the ©process© example, the components of the tuple value are passed as separate parameters to ©printf©, allowing very simple printing of tuple expressions.
     2386One way to access the individual components is with a simple assignment, as in previous examples.
     2387\begin{cfa}
     2388int freq;
     2389char ch;
     2390[freq, ch] = ret;
     2391\end{cfa}
     2392
     2393\begin{sloppypar}
     2394In addition to variables of tuple type, it is also possible to have pointers to tuples, and arrays of tuples.
     2395Tuple types can be composed of any types, except for array types, since array assignment is disallowed, which makes tuple assignment difficult when a tuple contains an array.
     2396\begin{cfa}
     2397[double, int] di;
     2398[double, int] * pdi
     2399[double, int] adi[10];
     2400\end{cfa}
     2401This examples declares a variable of type ©[double, int]©, a variable of type pointer to ©[double, int]©, and an array of ten ©[double, int]©.
     2402\end{sloppypar}
     2403
     2404\subsection{Tuple Indexing}
     2405
     2406At times, it is desirable to access a single component of a tuple-valued expression without creating unnecessary temporary variables to assign to.
     2407Given a tuple-valued expression ©e© and a compile-time constant integer $i$ where $0 \leq i < n$, where $n$ is the number of components in ©e©, ©e.i© accesses the $i$\textsuperscript{th} component of ©e©.
     2408For example,
     2409\begin{cfa}
     2410[int, double] x;
     2411[char *, int] f();
     2412void g(double, int);
     2413[int, double] * p;
     2414
     2415int y = x.0;                                                    §\C{// access int component of x}§
     2416y = f().1;                                                              §\C{// access int component of f}§
     2417p->0 = 5;                                                               §\C{// access int component of tuple pointed-to by p}§
     2418g( x.1, x.0 );                                                  §\C{// rearrange x to pass to g}§
     2419double z = [x, f()].0.1;                                §\C{// access second component of first component of tuple expression}§
     2420\end{cfa}
     2421As seen above, tuple-index expressions can occur on any tuple-typed expression, including tuple-returning functions, square-bracketed tuple expressions, and other tuple-index expressions, provided the retrieved component is also a tuple.
     2422This feature was proposed for \KWC but never implemented \cite[p.~45]{Till89}.
     2423
     2424\subsection{Flattening and Structuring}
     2425As evident in previous examples, tuples in \CFA do not have a rigid structure.
     2426In function call contexts, tuples support implicit flattening and restructuring conversions.
     2427Tuple flattening recursively expands a tuple into the list of its basic components.
     2428Tuple structuring packages a list of expressions into a value of tuple type.
     2429\begin{cfa}
     2430int f(int, int);
     2431int g([int, int]);
     2432int h(int, [int, int]);
     2433[int, int] x;
     2434int y;
     2435
     2436f(x);      // flatten
     2437g(y, 10);  // structure
     2438h(x, y);   // flatten & structure
     2439\end{cfa}
     2440In \CFA, each of these calls is valid.
     2441In the call to ©f©, ©x© is implicitly flattened so that the components of ©x© are passed as the two arguments to ©f©.
     2442For the call to ©g©, the values ©y© and ©10© are structured into a single argument of type ©[int, int]© to match the type of the parameter of ©g©.
     2443Finally, in the call to ©h©, ©x© is flattened to yield an argument list of length 3, of which the first component of ©x© is passed as the first parameter of ©h©, and the second component of ©x© and ©y© are structured into the second argument of type ©[int, int]©.
     2444The flexible structure of tuples permits a simple and expressive function-call syntax to work seamlessly with both single- and multiple-return-value functions, and with any number of arguments of arbitrarily complex structure.
     2445
     2446In \KWC \cite{Buhr94a,Till89}, there were 4 tuple coercions: opening, closing, flattening, and structuring.
     2447Opening coerces a tuple value into a tuple of values, while closing converts a tuple of values into a single tuple value.
     2448Flattening coerces a nested tuple into a flat tuple, \ie it takes a tuple with tuple components and expands it into a tuple with only non-tuple components.
     2449Structuring moves in the opposite direction, \ie it takes a flat tuple value and provides structure by introducing nested tuple components.
     2450
     2451In \CFA, the design has been simplified to require only the two conversions previously described, which trigger only in function call and return situations.
     2452This simplification is a primary contribution of this thesis to the design of tuples in \CFA.
     2453Specifically, the expression resolution algorithm examines all of the possible alternatives for an expression to determine the best match.
     2454In resolving a function call expression, each combination of function value and list of argument alternatives is examined.
     2455Given a particular argument list and function value, the list of argument alternatives is flattened to produce a list of non-tuple valued expressions.
     2456Then the flattened list of expressions is compared with each value in the function's parameter list.
     2457If the parameter's type is not a tuple type, then the current argument value is unified with the parameter type, and on success the next argument and parameter are examined.
     2458If the parameter's type is a tuple type, then the structuring conversion takes effect, recursively applying the parameter matching algorithm using the tuple's component types as the parameter list types.
     2459Assuming a successful unification, eventually the algorithm gets to the end of the tuple type, which causes all of the matching expressions to be consumed and structured into a tuple expression.
     2460For example, in
     2461\begin{cfa}
     2462int f(int, [double, int]);
     2463f([5, 10.2], 4);
     2464\end{cfa}
     2465There is only a single definition of ©f©, and 3 arguments with only single interpretations.
     2466First, the argument alternative list ©[5, 10.2], 4© is flattened to produce the argument list ©5, 10.2, 4©.
     2467Next, the parameter matching algorithm begins, with $P = $©int© and $A = $©int©, which unifies exactly.
     2468Moving to the next parameter and argument, $P = $©[double, int]© and $A = $©double©.
     2469This time, the parameter is a tuple type, so the algorithm applies recursively with $P' = $©double© and $A = $©double©, which unifies exactly.
     2470Then $P' = $©int© and $A = $©double©, which again unifies exactly.
     2471At this point, the end of $P'$ has been reached, so the arguments ©10.2, 4© are structured into the tuple expression ©[10.2, 4]©.
     2472Finally, the end of the parameter list $P$ has also been reached, so the final expression is ©f(5, [10.2, 4])©.
     2473
     2474\section{Tuple Assignment}
     2475\label{s:TupleAssignment}
     2476An assignment where the left side of the assignment operator has a tuple type is called tuple assignment.
     2477There are two kinds of tuple assignment depending on whether the right side of the assignment operator has a tuple type or a non-tuple type, called \emph{Multiple} and \emph{Mass} Assignment, respectively.
     2478\begin{cfa}
     2479int x;
     2480double y;
     2481[int, double] z;
     2482[y, x] = 3.14;  // mass assignment
     2483[x, y] = z;     // multiple assignment
     2484z = 10;         // mass assignment
     2485z = [x, y];     // multiple assignment
     2486\end{cfa}
     2487Let $L_i$ for $i$ in $[0, n)$ represent each component of the flattened left side, $R_i$ represent each component of the flattened right side of a multiple assignment, and $R$ represent the right side of a mass assignment.
     2488
     2489For a multiple assignment to be valid, both tuples must have the same number of elements when flattened.
     2490For example, the following is invalid because the number of components on the left does not match the number of components on the right.
     2491\begin{cfa}
     2492[int, int] x, y, z;
     2493[x, y] = z;   // multiple assignment, invalid 4 != 2
     2494\end{cfa}
     2495Multiple assignment assigns $R_i$ to $L_i$ for each $i$.
     2496That is, ©?=?(&$L_i$, $R_i$)© must be a well-typed expression.
     2497In the previous example, ©[x, y] = z©, ©z© is flattened into ©z.0, z.1©, and the assignments ©x = z.0© and ©y = z.1© happen.
     2498
     2499A mass assignment assigns the value $R$ to each $L_i$.
     2500For a mass assignment to be valid, ©?=?(&$L_i$, $R$)© must be a well-typed expression.
     2501These semantics differ from C cascading assignment (\eg ©a=b=c©) in that conversions are applied to $R$ in each individual assignment, which prevents data loss from the chain of conversions that can happen during a cascading assignment.
     2502For example, ©[y, x] = 3.14© performs the assignments ©y = 3.14© and ©x = 3.14©, which results in the value ©3.14© in ©y© and the value ©3© in ©x©.
     2503On the other hand, the C cascading assignment ©y = x = 3.14© performs the assignments ©x = 3.14© and ©y = x©, which results in the value ©3© in ©x©, and as a result the value ©3© in ©y© as well.
     2504
     2505Both kinds of tuple assignment have parallel semantics, such that each value on the left side and right side is evaluated \emph{before} any assignments occur.
     2506As a result, it is possible to swap the values in two variables without explicitly creating any temporary variables or calling a function.
     2507\begin{cfa}
     2508int x = 10, y = 20;
     2509[x, y] = [y, x];
     2510\end{cfa}
     2511After executing this code, ©x© has the value ©20© and ©y© has the value ©10©.
     2512
     2513In \CFA, tuple assignment is an expression where the result type is the type of the left side of the assignment, as in normal assignment.
     2514That is, a tuple assignment produces the value of the left-hand side after assignment.
     2515These semantics allow cascading tuple assignment to work out naturally in any context where a tuple is permitted.
     2516These semantics are a change from the original tuple design in \KWC \cite{Till89}, wherein tuple assignment was a statement that allows cascading assignments as a special case.
     2517Restricting tuple assignment to statements was an attempt to to fix what was seen as a problem with side-effects, wherein assignment can be used in many different locations, such as in function-call argument position.
     2518While permitting assignment as an expression does introduce the potential for subtle complexities, it is impossible to remove assignment expressions from \CFA without affecting backwards compatibility.
     2519Furthermore, there are situations where permitting assignment as an expression improves readability by keeping code succinct and reducing repetition, and complicating the definition of tuple assignment puts a greater cognitive burden on the user.
     2520In another language, tuple assignment as a statement could be reasonable, but it would be inconsistent for tuple assignment to be the only kind of assignment that is not an expression.
     2521In addition, \KWC permits the compiler to optimize tuple assignment as a block copy, since it does not support user-defined assignment operators.
     2522This optimization could be implemented in \CFA, but it requires the compiler to verify that the selected assignment operator is trivial.
     2523
     2524The following example shows multiple, mass, and cascading assignment used in one expression
     2525\begin{cfa}
     2526        int a, b;
     2527        double c, d;
     2528        [void] f([int, int]);
     2529        f([c, a] = [b, d] = 1.5);  // assignments in parameter list
     2530\end{cfa}
     2531The tuple expression begins with a mass assignment of ©1.5© into ©[b, d]©, which assigns ©1.5© into ©b©, which is truncated to ©1©, and ©1.5© into ©d©, producing the tuple ©[1, 1.5]© as a result.
     2532That tuple is used as the right side of the multiple assignment (\ie, ©[c, a] = [1, 1.5]©) that assigns ©1© into ©c© and ©1.5© into ©a©, which is truncated to ©1©, producing the result ©[1, 1]©.
     2533Finally, the tuple ©[1, 1]© is used as an expression in the call to ©f©.
     2534
     2535\subsection{Tuple Construction}
     2536Tuple construction and destruction follow the same rules and semantics as tuple assignment, except that in the case where there is no right side, the default constructor or destructor is called on each component of the tuple.
     2537As constructors and destructors did not exist in previous versions of \CFA or in \KWC, this is a primary contribution of this thesis to the design of tuples.
     2538\begin{cfa}
     2539struct S;
     2540void ?{}(S *);         // (1)
     2541void ?{}(S *, int);    // (2)
     2542void ?{}(S * double);  // (3)
     2543void ?{}(S *, S);      // (4)
     2544
     2545[S, S] x = [3, 6.28];  // uses (2), (3), specialized constructors
     2546[S, S] y;              // uses (1), (1), default constructor
     2547[S, S] z = x.0;        // uses (4), (4), copy constructor
     2548\end{cfa}
     2549In this example, ©x© is initialized by the multiple constructor calls ©?{}(&x.0, 3)© and ©?{}(&x.1, 6.28)©, while ©y© is initialized by two default constructor calls ©?{}(&y.0)© and ©?{}(&y.1)©.
     2550©z© is initialized by mass copy constructor calls ©?{}(&z.0, x.0)© and ©?{}(&z.1, x.0)©.
     2551Finally, ©x©, ©y©, and ©z© are destructed, \ie the calls ©^?{}(&x.0)©, ©^?{}(&x.1)©, ©^?{}(&y.0)©, ©^?{}(&y.1)©, ©^?{}(&z.0)©, and ©^?{}(&z.1)©.
     2552
     2553It is possible to define constructors and assignment functions for tuple types that provide new semantics, if the existing semantics do not fit the needs of an application.
     2554For example, the function ©void ?{}([T, U] *, S);© can be defined to allow a tuple variable to be constructed from a value of type ©S©.
     2555\begin{cfa}
     2556struct S { int x; double y; };
     2557void ?{}([int, double] * this, S s) {
     2558        this->0 = s.x;
     2559        this->1 = s.y;
     2560}
     2561\end{cfa}
     2562Due to the structure of generated constructors, it is possible to pass a tuple to a generated constructor for a type with a member prefix that matches the type of the tuple.
     2563For example,
     2564\begin{cfa}
     2565struct S { int x; double y; int z };
     2566[int, double] t;
     2567S s = t;
     2568\end{cfa}
     2569The initialization of ©s© with ©t© works by default because ©t© is flattened into its components, which satisfies the generated field constructor ©?{}(S *, int, double)© to initialize the first two values.
     2570
     2571\section{Member-Access Tuple Expression}
     2572\label{s:MemberAccessTuple}
     2573It is possible to access multiple fields from a single expression using a \emph{Member-Access Tuple Expression}.
     2574The result is a single tuple-valued expression whose type is the tuple of the types of the members.
     2575For example,
     2576\begin{cfa}
     2577struct S { int x; double y; char * z; } s;
     2578s.[x, y, z];
     2579\end{cfa}
     2580Here, the type of ©s.[x, y, z]© is ©[int, double, char *]©.
     2581A member tuple expression has the form ©a.[x, y, z];© where ©a© is an expression with type ©T©, where ©T© supports member access expressions, and ©x, y, z© are all members of ©T© with types ©T$_x$©, ©T$_y$©, and ©T$_z$© respectively.
     2582Then the type of ©a.[x, y, z]© is ©[T_x, T_y, T_z]©.
     2583
     2584Since tuple index expressions are a form of member-access expression, it is possible to use tuple-index expressions in conjunction with member tuple expressions to manually restructure a tuple (\eg, rearrange components, drop components, duplicate components, etc.).
     2585\begin{cfa}
     2586[int, int, long, double] x;
     2587void f(double, long);
     2588
     2589f(x.[0, 3]);          // f(x.0, x.3)
     2590x.[0, 1] = x.[1, 0];  // [x.0, x.1] = [x.1, x.0]
     2591[long, int, long] y = x.[2, 0, 2];
     2592\end{cfa}
     2593
     2594It is possible for a member tuple expression to contain other member access expressions.
     2595For example,
     2596\begin{cfa}
     2597struct A { double i; int j; };
     2598struct B { int * k; short l; };
     2599struct C { int x; A y; B z; } v;
     2600v.[x, y.[i, j], z.k];
     2601\end{cfa}
     2602This expression is equivalent to ©[v.x, [v.y.i, v.y.j], v.z.k]©.
     2603That is, the aggregate expression is effectively distributed across the tuple, which allows simple and easy access to multiple components in an aggregate, without repetition.
     2604It is guaranteed that the aggregate expression to the left of the ©.© in a member tuple expression is evaluated exactly once.
     2605As such, it is safe to use member tuple expressions on the result of a side-effecting function.
     2606\begin{cfa}
     2607[int, float, double] f();
     2608[double, float] x = f().[2, 1];
     2609\end{cfa}
     2610
     2611In \KWC, member tuple expressions are known as \emph{record field tuples} \cite{Till89}.
     2612Since \CFA permits these tuple-access expressions using structures, unions, and tuples, \emph{member tuple expression} or \emph{field tuple expression} is more appropriate.
     2613
     2614It is possible to extend member-access expressions further.
     2615Currently, a member-access expression whose member is a name requires that the aggregate is a structure or union, while a constant integer member requires the aggregate to be a tuple.
     2616In the interest of orthogonal design, \CFA could apply some meaning to the remaining combinations as well.
     2617For example,
     2618\begin{cfa}
     2619struct S { int x, y; } s;
     2620[S, S] z;
     2621
     2622s.x;  // access member
     2623z.0;  // access component
     2624
     2625s.1;  // ???
     2626z.y;  // ???
     2627\end{cfa}
     2628One possibility is for ©s.1© to select the second member of ©s©.
     2629Under this interpretation, it becomes possible to not only access members of a struct by name, but also by position.
     2630Likewise, it seems natural to open this mechanism to enumerations as well, wherein the left side would be a type, rather than an expression.
     2631One benefit of this interpretation is familiarity, since it is extremely reminiscent of tuple-index expressions.
     2632On the other hand, it could be argued that this interpretation is brittle in that changing the order of members or adding new members to a structure becomes a brittle operation.
     2633This problem is less of a concern with tuples, since modifying a tuple affects only the code that directly uses the tuple, whereas modifying a structure has far reaching consequences for every instance of the structure.
     2634
     2635As for ©z.y©, one interpretation is to extend the meaning of member tuple expressions.
     2636That is, currently the tuple must occur as the member, \ie to the right of the dot.
     2637Allowing tuples to the left of the dot could distribute the member across the elements of the tuple, in much the same way that member tuple expressions distribute the aggregate across the member tuple.
     2638In this example, ©z.y© expands to ©[z.0.y, z.1.y]©, allowing what is effectively a very limited compile-time field-sections map operation, where the argument must be a tuple containing only aggregates having a member named ©y©.
     2639It is questionable how useful this would actually be in practice, since structures often do not have names in common with other structures, and further this could cause maintainability issues in that it encourages programmers to adopt very simple naming conventions to maximize the amount of overlap between different types.
     2640Perhaps more useful would be to allow arrays on the left side of the dot, which would likewise allow mapping a field access across the entire array, producing an array of the contained fields.
     2641The immediate problem with this idea is that C arrays do not carry around their size, which would make it impossible to use this extension for anything other than a simple stack allocated array.
     2642
     2643Supposing this feature works as described, it would be necessary to specify an ordering for the expansion of member-access expressions versus member-tuple expressions.
     2644\begin{cfa}
     2645struct { int x, y; };
     2646[S, S] z;
     2647z.[x, y];  // ???
     2648// => [z.0, z.1].[x, y]
     2649// => [z.0.x, z.0.y, z.1.x, z.1.y]
     2650// or
     2651// => [z.x, z.y]
     2652// => [[z.0, z.1].x, [z.0, z.1].y]
     2653// => [z.0.x, z.1.x, z.0.y, z.1.y]
     2654\end{cfa}
     2655Depending on exactly how the two tuples are combined, different results can be achieved.
     2656As such, a specific ordering would need to be imposed to make this feature useful.
     2657Furthermore, this addition moves a member-tuple expression's meaning from being clear statically to needing resolver support, since the member name needs to be distributed appropriately over each member of the tuple, which could itself be a tuple.
     2658
     2659A second possibility is for \CFA to have named tuples, as they exist in Swift and D.
     2660\begin{cfa}
     2661typedef [int x, int y] Point2D;
     2662Point2D p1, p2;
     2663p1.x + p1.y + p2.x + p2.y;
     2664p1.0 + p1.1 + p2.0 + p2.1;  // equivalent
     2665\end{cfa}
     2666In this simpler interpretation, a tuple type carries with it a list of possibly empty identifiers.
     2667This approach fits naturally with the named return-value feature, and would likely go a long way towards implementing it.
     2668
     2669Ultimately, the first two extensions introduce complexity into the model, with relatively little perceived benefit, and so were dropped from consideration.
     2670Named tuples are a potentially useful addition to the language, provided they can be parsed with a reasonable syntax.
     2671
     2672
     2673\section{Casting}
     2674In C, the cast operator is used to explicitly convert between types.
     2675In \CFA, the cast operator has a secondary use, which is type ascription, since it forces the expression resolution algorithm to choose the lowest cost conversion to the target type.
     2676That is, a cast can be used to select the type of an expression when it is ambiguous, as in the call to an overloaded function.
     2677\begin{cfa}
     2678int f();     // (1)
     2679double f();  // (2)
     2680
     2681f();       // ambiguous - (1),(2) both equally viable
     2682(int)f();  // choose (2)
     2683\end{cfa}
     2684Since casting is a fundamental operation in \CFA, casts need to be given a meaningful interpretation in the context of tuples.
     2685Taking a look at standard C provides some guidance with respect to the way casts should work with tuples.
     2686\begin{cfa}[numbers=left]
     2687int f();
     2688void g();
     2689
     2690(void)f();  // valid, ignore results
     2691(int)g();   // invalid, void cannot be converted to int
     2692
     2693struct A { int x; };
     2694(struct A)f();  // invalid, int cannot be converted to A
     2695\end{cfa}
     2696In C, line 4 is a valid cast, which calls ©f© and discards its result.
     2697On the other hand, line 5 is invalid, because ©g© does not produce a result, so requesting an ©int© to materialize from nothing is nonsensical.
     2698Finally, line 8 is also invalid, because in C casts only provide conversion between scalar types \cite[p.~91]{C11}.
     2699For consistency, this implies that any case wherein the number of components increases as a result of the cast is invalid, while casts that have the same or fewer number of components may be valid.
     2700
     2701Formally, a cast to tuple type is valid when $T_n \leq S_m$, where $T_n$ is the number of components in the target type and $S_m$ is the number of components in the source type, and for each $i$ in $[0, n)$, $S_i$ can be cast to $T_i$.
     2702Excess elements ($S_j$ for all $j$ in $[n, m)$) are evaluated, but their values are discarded so that they are not included in the result expression.
     2703This discarding naturally follows the way that a cast to void works in C.
     2704
     2705For example,
     2706\begin{cfa}
     2707        [int, int, int] f();
     2708        [int, [int, int], int] g();
     2709
     2710        ([int, double])f();           // (1) valid
     2711        ([int, int, int])g();         // (2) valid
     2712        ([void, [int, int]])g();      // (3) valid
     2713        ([int, int, int, int])g();    // (4) invalid
     2714        ([int, [int, int, int]])g();  // (5) invalid
     2715\end{cfa}
     2716
     2717(1) discards the last element of the return value and converts the second element to type double.
     2718Since ©int© is effectively a 1-element tuple, (2) discards the second component of the second element of the return value of ©g©.
     2719If ©g© is free of side effects, this is equivalent to ©[(int)(g().0), (int)(g().1.0), (int)(g().2)]©.
     2720Since ©void© is effectively a 0-element tuple, (3) discards the first and third return values, which is effectively equivalent to ©[(int)(g().1.0), (int)(g().1.1)]©).
     2721% will this always hold true? probably, as constructors should give all of the conversion power we need. if casts become function calls, what would they look like? would need a way to specify the target type, which seems awkward. Also, C++ basically only has this because classes are closed to extension, while we don't have that problem (can have floating constructors for any type).
     2722Note that a cast is not a function call in \CFA, so flattening and structuring conversions do not occur for cast expressions.
     2723As such, (4) is invalid because the cast target type contains 4 components, while the source type contains only 3.
     2724Similarly, (5) is invalid because the cast ©([int, int, int])(g().1)© is invalid.
     2725That is, it is invalid to cast ©[int, int]© to ©[int, int, int]©.
     2726
     2727\section{Polymorphism}
     2728Due to the implicit flattening and structuring conversions involved in argument passing, ©otype© and ©dtype© parameters are restricted to matching only with non-tuple types.
     2729The integration of polymorphism, type assertions, and monomorphic specialization of tuple-assertions are a primary contribution of this thesis to the design of tuples.
     2730\begin{cfa}
     2731forall(otype T, dtype U)
     2732void f(T x, U * y);
     2733
     2734f([5, "hello"]);
     2735\end{cfa}
     2736In this example, ©[5, "hello"]© is flattened, so that the argument list appears as ©5, "hello"©.
     2737The argument matching algorithm binds ©T© to ©int© and ©U© to ©const char©, and calls the function as normal.
     2738
     2739Tuples can contain otype and dtype components.
     2740For example, a plus operator can be written to add two triples of a type together.
     2741\begin{cfa}
     2742forall(otype T | { T ?+?(T, T); })
     2743[T, T, T] ?+?([T, T, T] x, [T, T, T] y) {
     2744        return [x.0+y.0, x.1+y.1, x.2+y.2];
     2745}
     2746[int, int, int] x;
     2747int i1, i2, i3;
     2748[i1, i2, i3] = x + ([10, 20, 30]);
     2749\end{cfa}
     2750Note that due to the implicit tuple conversions, this function is not restricted to the addition of two triples.
     2751A call to this plus operator type checks as long as a total of 6 non-tuple arguments are passed after flattening, and all of the arguments have a common type that can bind to ©T©, with a pairwise ©?+?© over ©T©.
     2752For example, these expressions also succeed and produce the same value.
     2753\begin{cfa}
     2754([x.0, x.1]) + ([x.2, 10, 20, 30]);  // x + ([10, 20, 30])
     2755x.0 + ([x.1, x.2, 10, 20, 30]);      // x + ([10, 20, 30])
     2756\end{cfa}
     2757This presents a potential problem if structure is important, as these three expressions look like they should have different meanings.
     2758Furthermore, these calls can be made ambiguous by introducing seemingly different functions.
     2759\begin{cfa}
     2760forall(otype T | { T ?+?(T, T); })
     2761[T, T, T] ?+?([T, T] x, [T, T, T, T]);
     2762forall(otype T | { T ?+?(T, T); })
     2763[T, T, T] ?+?(T x, [T, T, T, T, T]);
     2764\end{cfa}
     2765It is also important to note that these calls could be disambiguated if the function return types were different, as they likely would be for a reasonable implementation of ©?+?©, since the return type is used in overload resolution.
     2766Still, these semantics are a deficiency of the current argument matching algorithm, and depending on the function, differing return values may not always be appropriate.
     2767These issues could be rectified by applying an appropriate conversion cost to the structuring and flattening conversions, which are currently 0-cost conversions in the expression resolver.
     2768Care would be needed in this case to ensure that exact matches do not incur such a cost.
     2769\begin{cfa}
     2770void f([int, int], int, int);
     2771
     2772f([0, 0], 0, 0);    // no cost
     2773f(0, 0, 0, 0);      // cost for structuring
     2774f([0, 0,], [0, 0]); // cost for flattening
     2775f([0, 0, 0], 0);    // cost for flattening and structuring
     2776\end{cfa}
     2777
     2778Until this point, it has been assumed that assertion arguments must match the parameter type exactly, modulo polymorphic specialization (\ie, no implicit conversions are applied to assertion arguments).
     2779This decision presents a conflict with the flexibility of tuples.
     2780\subsection{Assertion Inference}
     2781\begin{cfa}
     2782int f([int, double], double);
     2783forall(otype T, otype U | { T f(T, U, U); })
     2784void g(T, U);
     2785g(5, 10.21);
     2786\end{cfa}
     2787If assertion arguments must match exactly, then the call to ©g© cannot be resolved, since the expected type of ©f© is flat, while the only ©f© in scope requires a tuple type.
     2788Since tuples are fluid, this requirement reduces the usability of tuples in polymorphic code.
     2789To ease this pain point, function parameter and return lists are flattened for the purposes of type unification, which allows the previous example to pass expression resolution.
     2790
     2791This relaxation is made possible by extending the existing thunk generation scheme, as described by Bilson \cite{Bilson03}.
     2792Now, whenever a candidate's parameter structure does not exactly match the formal parameter's structure, a thunk is generated to specialize calls to the actual function.
     2793\begin{cfa}
     2794int _thunk(int _p0, double _p1, double _p2) {
     2795        return f([_p0, _p1], _p2);
     2796}
     2797\end{cfa}
     2798Essentially, this provides flattening and structuring conversions to inferred functions, improving the compatibility of tuples and polymorphism.
    22472799
    22482800
     
    31363688
    31373689\begin{table}[hbt]
    3138 \hfil
    3139 \begin{tabular}[t]{ll}
    3140 %identifier & operation \\ \hline
    3141 ©?[?]© & subscripting \impl{?[?]}\\
    3142 ©?()© & function call \impl{?()}\\
    3143 ©?++© & postfix increment \impl{?++}\\
    3144 ©?--© & postfix decrement \impl{?--}\\
    3145 ©++?© & prefix increment \impl{++?}\\
    3146 ©--?© & prefix decrement \impl{--?}\\
    3147 ©*?© & dereference \impl{*?}\\
    3148 ©+?© & unary plus \impl{+?}\\
    3149 ©-?© & arithmetic negation \impl{-?}\\
    3150 ©~?© & bitwise negation \impl{~?}\\
    3151 ©!?© & logical complement \impl{"!?}\\
    3152 ©?*?© & multiplication \impl{?*?}\\
    3153 ©?/?© & division \impl{?/?}\\
    3154 \end{tabular}\hfil
    3155 \begin{tabular}[t]{ll}
    3156 %identifier & operation \\ \hline
    3157 ©?%?© & remainder \impl{?%?}\\
    3158 ©?+?© & addition \impl{?+?}\\
    3159 ©?-?© & subtraction \impl{?-?}\\
    3160 ©?<<?© & left shift \impl{?<<?}\\
    3161 ©?>>?© & right shift \impl{?>>?}\\
    3162 ©?<?© & less than \impl{?<?}\\
    3163 ©?<=?© & less than or equal \impl{?<=?}\\
    3164 ©?>=?© & greater than or equal \impl{?>=?}\\
    3165 ©?>?© & greater than \impl{?>?}\\
    3166 ©?==?© & equality \impl{?==?}\\
    3167 ©?!=?© & inequality \impl{?"!=?}\\
    3168 ©?&?© & bitwise AND \impl{?&?}\\
    3169 \end{tabular}\hfil
    3170 \begin{tabular}[t]{ll}
    3171 %identifier & operation \\ \hline
    3172 ©?^?© & exclusive OR \impl{?^?}\\
    3173 ©?|?© & inclusive OR \impl{?"|?}\\
    3174 ©?=?© & simple assignment \impl{?=?}\\
    3175 ©?*=?© & multiplication assignment \impl{?*=?}\\
    3176 ©?/=?© & division assignment \impl{?/=?}\\
    3177 ©?%=?© & remainder assignment \impl{?%=?}\\
    3178 ©?+=?© & addition assignment \impl{?+=?}\\
    3179 ©?-=?© & subtraction assignment \impl{?-=?}\\
    3180 ©?<<=?© & left-shift assignment \impl{?<<=?}\\
    3181 ©?>>=?© & right-shift assignment \impl{?>>=?}\\
    3182 ©?&=?© & bitwise AND assignment \impl{?&=?}\\
    3183 ©?^=?© & exclusive OR assignment \impl{?^=?}\\
    3184 ©?|=?© & inclusive OR assignment \impl{?"|=?}\\
    3185 \end{tabular}
    3186 \hfil
     3690\centering
     3691\input{../refrat/operidents}
    31873692\caption{Operator Identifiers}
    31883693\label{opids}
     
    32313736\section{Auto Type-Inferencing}
    32323737
    3233 Auto type-inferencing occurs in a declaration where a variable's type is inferred from its initialization expression type.
     3738Auto type-inferencing occurs in a declaration where a variable's type is inferred from its initialization ex\-pression type.
    32343739\begin{quote2}
    32353740\begin{tabular}{@{}l@{\hspace{3em}}ll@{}}
     
    32603765\begin{itemize}
    32613766\item
    3262 preventing having to determine or write out long generic types,
     3767preventing having to determine or write long generic types,
    32633768\item
    32643769ensure secondary variables, related to a primary variable, always have the same type.
     
    32843789There is also the conundrum in type inferencing of when to \emph{\Index{brand}} a type.
    32853790That is, when is the type of the variable more important than the type of its initialization expression.
    3286 For example, if a change is made in an initialization expression, it can cause hundreds or thousands of cascading type changes and/or errors.
    3287 At some point, a programmer wants the type of the variable to remain constant and the expression to be in error when it changes.
     3791For example, if a change is made in an initialization expression, it can cause significant cascading type changes and/or errors.
     3792At some point, a variable type needs to remain constant and the expression to be in error when it changes.
    32883793
    32893794Given ©typedef© and ©typeof© in \CFA, and the strong need to use the type of left-hand side in inferencing, auto type-inferencing is not supported at this time.
     
    34984003        }
    34994004\end{cfa}
    3500 \end{comment}
    3501 
    3502 
    3503 \subsection{Memory Management}
    3504 
    3505 
    3506 \subsubsection{Manual Memory Management}
    3507 
    3508 Using malloc and free to dynamically allocate memory exposes several potential, and common, errors.
    3509 First, malloc breaks type safety because it returns a pointer to void.
    3510 There is no relationship between the type that the returned pointer is cast to, and the amount of memory allocated.
    3511 This problem is solved with a type-safe malloc.
    3512 Do.s type-safe malloc does not take any arguments for size.
    3513 Instead, it infers the type based on the return value, and then allocates space for the inferred type.
    3514 
    3515 \begin{cfa}
    3516 float *f = malloc(); // allocates the size of a float
    3517 
    3518 struct S {
    3519         int i, j, k;
    3520 };
    3521 
    3522 struct S *s = malloc(); // allocates the size of a struct S
    3523 \end{cfa}
    3524 
    3525 In addition to the improved malloc, \CFA also provides a technique for combining allocation and initialization into one step, using the new function.
    3526 For all constructors defined for a given type (see Operator Overloading), a corresponding call to new can be used to allocate and construct that type.
    3527 
    3528 \begin{cfa}
    3529 type Complex = struct {
    3530         float real;
    3531         float imag;
    3532 };
    3533 
    3534 // default constructor
    3535 
    3536 void ?{}(Complex &c) {
    3537         c.real = 0.0;
    3538         c.imag = 0.0;
    3539 }
    3540 
    3541 
    3542 
    3543 // 2 parameter constructor
    3544 
    3545 void ?{}(Complex &c, float real, float imag) {
    3546         c.real = real;
    3547         c.imag = imag;
    3548 }
    3549 
    3550 
    3551 int main() {
    3552         Complex c1; // No constructor is called
    3553         Complex c2{}; // Default constructor called
    3554         Complex c3{1.0, -1.0}; // 2 parameter constructor is called
    3555 
    3556         Complex *p1 = malloc(); // allocate
    3557         Complex *p2 = new(); // allocate + default constructor
    3558         Complex *p3 = new(0.5, 1.0); // allocate + 2 param constructor
    3559 }
    3560 \end{cfa}
    3561 
    3562 
    3563 \subsubsection{Automatic Memory Management}
    3564 
    3565 \CFA may also support automatic memory management to further improve safety.
    3566 If the compiler can insert all of the code needed to manage dynamically allocated memory (automatic reference counting), then developers can avoid problems with dangling pointers, double frees, memory leaks, etc.
    3567 This feature requires further investigation.
    3568 \CFA will not have a garbage collector, but might use some kind of region-based memory management.
    3569 
    3570 
    3571 \begin{comment}
    3572 \subsection{Unsafe C Constructs}
    3573 
    3574 C programmers are able to access all of the low-level tricks that are sometimes needed for close-to-the-hardware programming.
    3575 Some of these practices however are often error-prone and difficult to read and maintain.
    3576 Since \CFA is designed to be safer than C, such constructs are disallowed in \CFA code.
    3577 If a programmer wants to use one of these unsafe C constructs, the unsafe code must be contained in a C linkage block (see Interoperability), which will be compiled like C code.
    3578 This block means that the user is telling the tools, .I know this is unsafe, but I.m going to do it anyway..
    3579 
    3580 The exact set of unsafe C constructs that will be disallowed in \CFA has not yet been decided, but is sure to include pointer arithmetic, pointer casting, etc.
    3581 Once the full set is decided, the rules will be listed here.
    35824005\end{comment}
    35834006
     
    38034226\label{f:SimpleTasks}
    38044227\end{figure}
    3805 
    3806 
    3807 \begin{comment}
    3808 \begin{cfa}
    3809 type Adder = task {
    3810         int *row;
    3811         int size;
    3812         int &subtotal;
    3813 }
    3814 \end{cfa}
    3815 
    3816 A task may define a constructor, which will be called upon allocation and run on the caller.s thread.
    3817 A destructor may also be defined, which is called at deallocation (when a dynamic object is deleted or when a local object goes out of scope).
    3818 After a task is allocated and initialized, its thread is spawned implicitly and begins executing in its function call method.
    3819 All tasks must define this function call method, with a void return value and no additional parameters, or the compiler will report an error.
    3820 Below are example functions for the above Adder task, and its usage to sum up a matrix on multiple threads.
    3821 (Note that this example is designed to display the syntax and functionality, not the best method to solve this problem)
    3822 \begin{cfa}
    3823 void ?{}(Adder &a, int r[], int s, int &st) { // constructor
    3824         a.row = r;
    3825         a.size = s;
    3826         a.subtotal = st;
    3827 }
    3828 
    3829 // implicitly spawn thread and begin execution here
    3830 
    3831 void ?()(Adder &a) {
    3832         int c;
    3833         subtotal = 0;
    3834         for (c=0; c<a.size; ++c) {
    3835         subtotal += row[c];
    3836         }
    3837 }
    3838 
    3839 int main() {
    3840         const int rows = 100, cols = 1000000;
    3841         int matrix[rows][cols];
    3842         int subtotals[rows];
    3843         int total = 0;
    3844         int r;
    3845 
    3846         { // create a new scope here for our adders
    3847         Adder adders[rows];
    3848         // read in the matrix
    3849         ...
    3850         for (r=0; r<rows; ++r) {
    3851         // tasks are initialized on this thread
    3852         Adders[r] = {matrix[r], cols, subtotals[r]};
    3853         Adders[r](); // spawn thread and begin execution
    3854         }
    3855         } // adders go out of scope; block here until they all finish
    3856         total += subtotals[r];
    3857         printf(.total is %d\n., total);
    3858 }
    3859 \end{cfa}
    3860 
    3861 \subsection{Cooperative Scheduling}
    3862 
    3863 Tasks in \CFA are cooperatively scheduled, meaning that a task will not be interrupted by another task, except at specific yield points.
    3864 In Listing 31, there are no yield points, so each task runs to completion with no interruptions.
    3865 Places where a task could yield include waiting for a lock (explicitly or implicitly), waiting for I/O, or waiting for a specific function (or one of a set of functions) to be called.
    3866 This last option is introduced with the yield function. yield is used to indicate that this task should yield its thread until the specified function is called.
    3867 For example, the code below defines a monitor that maintains a generic list.
    3868 When a task tries to pop from the list, but it is empty, the task should yield until another task puts something into the list, with the push function.
    3869 Similarly, when a task tries to push something onto the list, but it is full, it will yield until another task frees some space with the pop function.
    3870 
    3871 \begin{cfa}
    3872 // type T is used as a generic type for all definitions inside
    3873 // the curly brackets
    3874 
    3875 generic(type T) {
    3876         type Channel = monitor {
    3877         List(T) list; // list is a simple generic list type
    3878         };
    3879 
    3880         T pop(mutex &Channel(T) ch) {
    3881         if (ch.list.empty()) {
    3882         // yield until push is called for this channel
    3883         yield(push);
    3884         }
    3885         return ch.list.pop();
    3886         }
    3887 
    3888         void push(mutex &Channel(T)ch, T val) {
    3889         if (ch.list.full()) {
    3890         // yield until pop is called for this channel
    3891         yield(pop);
    3892         }
    3893         ch.list.push(val);
    3894         }
    3895 }
    3896 \end{cfa}
    3897 
    3898 A task can also yield indefinitely by calling yield with no arguments.
    3899 This will tell the scheduler to yield this task until it is resumed by some other task.
    3900 A task can resume another task by using its functional call operator.
    3901 The code below shows a simple ping-pong example, where two tasks yield back and forth to each other using these methods.
    3902 
    3903 \begin{cfa}
    3904 type Ping = task {
    3905         Pong *partner;
    3906 };
    3907 
    3908 void ?{}(Ping &p, Pong *partner = 0) {
    3909         p.partner = partner;
    3910 }
    3911 
    3912 void ?()(Ping &p) {
    3913         for(;;) { // loop forever
    3914         printf(.ping\n.);
    3915         partner(); // resumes the partner task
    3916         yield(); // yields this task
    3917         }
    3918 }
    3919 
    3920 type Pong = task {
    3921         Ping *partner;
    3922 };
    3923 
    3924 void ?{}(Pong &p, Ping *partner = 0) {
    3925         p.partner = partner;
    3926 }
    3927 
    3928 void ?()(Pong &p) {
    3929         for(;;) { // loop forever
    3930         yield(); // yields this task
    3931         printf(.pong/n.);
    3932         partner(); // resumes the partner task
    3933         }
    3934 }
    3935 
    3936 void main() {
    3937         Ping ping; // allocate ping
    3938         Pong pong{ping}; // allocate, initialize, and start pong
    3939         Ping{pong}; // initialize and start ping
    3940 }
    3941 \end{cfa}
    3942 
    3943 The same functionality can be accomplished by providing functions to be called by the partner task.
    3944 \begin{cfa}
    3945 type Pingpong = task {
    3946         String msg;
    3947         Pingpong *partner;
    3948 };
    3949 
    3950 void ?{}(Pingpong &p, String msg, Pingpong *partner = 0) {
    3951         p.msg = msg;
    3952         p.partner = partner;
    3953 }
    3954 
    3955 void ?()(Pingpong &p) {
    3956         for(;;) {
    3957         yield(go);
    3958         }
    3959 }
    3960 
    3961 void go(Pingpong &p) {
    3962         print(.%(p.msg)\n.);
    3963         go(p.partner);
    3964 }
    3965 
    3966 void main() {
    3967         Pingpong ping = {.ping.};
    3968         Pingpong pong = {.pong., ping};
    3969         ping.partner = pong;
    3970         go(ping);
    3971 }
    3972 \end{cfa}
    3973 \end{comment}
    39744228
    39754229
     
    46324886
    46334887
    4634 \section{Comparison with Other Languages}
     4888\section{Language Comparisons}
    46354889
    46364890\CFA is one of many languages that attempts to improve upon C.
     
    53675621
    53685622
    5369 \section{\texorpdfstring{\CFA Keywords}{Cforall Keywords}}
    5370 \label{s:CFAKeywords}
    5371 
    5372 \CFA introduces the following new keywords.
    5373 
    5374 \begin{quote2}
    5375 \begin{tabular}{lllll}
    5376 \begin{tabular}{@{}l@{}}
    5377 ©_At©                   \\
    5378 ©catch©                 \\
    5379 ©catchResume©   \\
    5380 ©choose©                \\
    5381 ©coroutine©             \\
    5382 \end{tabular}
    5383 &
    5384 \begin{tabular}{@{}l@{}}
    5385 ©disable©               \\
    5386 ©dtype©                 \\
    5387 ©enable©                \\
    5388 ©fallthrough©   \\
    5389 ©fallthru©              \\
    5390 \end{tabular}
    5391 &
    5392 \begin{tabular}{@{}l@{}}
    5393 ©finally©               \\
    5394 ©forall©                \\
    5395 ©ftype©                 \\
    5396 ©lvalue©                \\
    5397 ©monitor©               \\
    5398 \end{tabular}
    5399 &
    5400 \begin{tabular}{@{}l@{}}
    5401 ©mutex©                 \\
    5402 ©one_t©                 \\
    5403 ©otype©                 \\
    5404 ©throw©                 \\
    5405 ©throwResume©   \\
    5406 \end{tabular}
    5407 &
    5408 \begin{tabular}{@{}l@{}}
    5409 ©trait©                 \\
    5410 ©try©                   \\
    5411 ©ttype©                 \\
    5412 ©with©                  \\
    5413 ©zero_t©                \\
    5414 \end{tabular}
    5415 \end{tabular}
    5416 \end{quote2}
    5417 
    5418 
    5419 \section{Incompatible}
     5623\section{C Incompatibles}
    54205624
    54215625The following incompatibles exist between \CFA and C, and are similar to Annex C for \CC~\cite{C++14}.
     
    55185722struct X { int i; struct X *next; };
    55195723static struct X a;                              §\C{// forward definition}§
    5520 static struct X b = { 0, ®&a® };        §\C{// forward reference, valid in C, invalid in \CFA}§
     5724static struct X b = { 0, ®&a® };§\C{// forward reference, valid in C, invalid in \CFA}§
    55215725static struct X a = { 1, &b };  §\C{// definition}§
    55225726\end{cfa}
     
    55335737enum ®Colour® { R, G, B, Y, C, M };
    55345738struct Person {
    5535         enum ®Colour® { R, G, B };      §\C{// nested type}§
     5739        enum ®Colour® { R, G, B };      §\C[7cm]{// nested type}§
    55365740        struct Face {                           §\C{// nested type}§
    55375741                ®Colour® Eyes, Hair;    §\C{// type defined outside (1 level)}§
     
    55425746};
    55435747®Colour® c = R;                                 §\C{// type/enum defined same level}§
    5544 Person®.Colour® pc = Person®.®R;        §\C{// type/enum defined inside}§
    5545 Person®.®Face pretty;                   §\C{// type defined inside}§
     5748Person®.Colour® pc = Person®.®R;§\C{// type/enum defined inside}§
     5749Person®.®Face pretty;                   §\C{// type defined inside}\CRT§
    55465750\end{cfa}
    55475751In C, the name of the nested types belongs to the same scope as the name of the outermost enclosing structure, \ie the nested types are hoisted to the scope of the outer-most type, which is not useful and confusing.
     
    55725776\item
    55735777\begin{description}
     5778\item[Change:] remove implicit conversion of ©void *© to or from any ©T *© pointer:
     5779\begin{cfa}
     5780void foo() {
     5781        int * b = malloc( sizeof(int) );        §\C{// implicitly convert void * to int *}§
     5782        char * c = b;                           §\C{// implicitly convert int * to void *, and then void * to char *}§
     5783}
     5784\end{cfa}
     5785\item[Rationale:] increase type safety
     5786\item[Effect on original feature:] deletion of semantically well-defined feature.
     5787\item[Difficulty of converting:] requires adding a cast (see \VRef{s:StorageManagement} for better alternatives):
     5788\begin{cfa}
     5789        int * b = (int *)malloc( sizeof(int) );
     5790        char * c = (char *)b;
     5791\end{cfa}
     5792\item[How widely used:] Significant.
     5793Some C translators already give a warning if the cast is not used.
     5794\end{description}
     5795
     5796\item
     5797\begin{description}
     5798\item[Change:] Types must be declared in declarations, not in expressions
     5799In C, a sizeof expression or cast expression may create a new type. For example,
     5800\begin{cfa}
     5801p = (void*)(struct x {int i;} *)0;
     5802\end{cfa}
     5803declares a new type, struct x .
     5804\item[Rationale:] This prohibition helps to clarify the location of declarations in the source code.
     5805\item[Effect on original feature:] Deletion of a semantically welldefined feature.
     5806\item[Difficulty of converting:] Syntactic transformation.
     5807\item[How widely used:] Seldom.
     5808\end{description}
     5809
     5810\item
     5811\begin{description}
    55745812\item[Change:] comma expression is disallowed as subscript
    55755813\item[Rationale:] safety issue to prevent subscripting error for multidimensional arrays: ©x[i,j]© instead of ©x[i][j]©, and this syntactic form then taken by \CFA for new style arrays.
    55765814\item[Effect on original feature:] change to semantics of well-defined feature.
    55775815\item[Difficulty of converting:] semantic transformation of ©x[i,j]© to ©x[(i,j)]©
    5578 \item[How widely used:] seldom.
     5816\item[How widely used:] Seldom.
    55795817\end{description}
    55805818\end{enumerate}
    55815819
    55825820
     5821\section{\texorpdfstring{\CFA Keywords}{Cforall Keywords}}
     5822\label{s:CFAKeywords}
     5823
     5824\CFA introduces the following new keywords.
     5825
     5826\begin{quote2}
     5827\input{../refrat/keywords}
     5828\end{quote2}
     5829
     5830
    55835831\section{Standard Headers}
    55845832\label{s:StandardHeaders}
     
    55865834\Celeven prescribes the following standard header-files~\cite[\S~7.1.2]{C11} and \CFA adds to this list:
    55875835\begin{quote2}
    5588 \begin{tabular}{@{}lllll|l@{}}
    5589 \multicolumn{5}{c|}{C11} & \multicolumn{1}{c}{\CFA}             \\
     5836\begin{tabular}{@{}llllll|l@{}}
     5837\multicolumn{6}{c|}{C11} & \multicolumn{1}{c}{\CFA}             \\
    55905838\hline
    55915839\begin{tabular}{@{}l@{}}
     
    55955843\Indexc{errno.h}                \\
    55965844\Indexc{fenv.h}                 \\
    5597 \Indexc[deletekeywords=float]{float.h} \\
    55985845\end{tabular}
    55995846&
    56005847\begin{tabular}{@{}l@{}}
     5848\Indexc[deletekeywords=float]{float.h} \\
    56015849\Indexc{inttypes.h}             \\
    56025850\Indexc{iso646.h}               \\
    56035851\Indexc{limits.h}               \\
    56045852\Indexc{locale.h}               \\
    5605 \Indexc{math.h}                 \\
    5606 \Indexc{setjmp.h}               \\
    56075853\end{tabular}
    56085854&
    56095855\begin{tabular}{@{}l@{}}
     5856\Indexc{math.h}                 \\
     5857\Indexc{setjmp.h}               \\
    56105858\Indexc{signal.h}               \\
    56115859\Indexc{stdalign.h}             \\
    56125860\Indexc{stdarg.h}               \\
     5861\end{tabular}
     5862&
     5863\begin{tabular}{@{}l@{}}
    56135864\Indexc{stdatomic.h}    \\
    56145865\Indexc{stdbool.h}              \\
    56155866\Indexc{stddef.h}               \\
     5867\Indexc{stdint.h}               \\
     5868\Indexc{stdio.h}                \\
    56165869\end{tabular}
    56175870&
    56185871\begin{tabular}{@{}l@{}}
    5619 \Indexc{stdint.h}               \\
    5620 \Indexc{stdio.h}                \\
    56215872\Indexc{stdlib.h}               \\
    56225873\Indexc{stdnoreturn.h}  \\
    56235874\Indexc{string.h}               \\
    56245875\Indexc{tgmath.h}               \\
     5876\Indexc{threads.h}              \\
    56255877\end{tabular}
    56265878&
    56275879\begin{tabular}{@{}l@{}}
    5628 \Indexc{threads.h}              \\
    56295880\Indexc{time.h}                 \\
    56305881\Indexc{uchar.h}                \\
     
    56355886&
    56365887\begin{tabular}{@{}l@{}}
     5888\Indexc{gmp.h}                  \\
     5889\Indexc{malloc.h}               \\
    56375890\Indexc{unistd.h}               \\
    5638 \Indexc{gmp.h}                  \\
    5639                                                 \\
    5640                                                 \\
    56415891                                                \\
    56425892                                                \\
     
    56475897hence, names in these include files are not mangled\index{mangling!name} (see~\VRef{s:Interoperability}).
    56485898All other C header files must be explicitly wrapped in ©extern "C"© to prevent name mangling.
    5649 For \Index*[C++]{\CC{}}, the name-mangling issue is handled implicitly because most C header-files are augmented with checks for preprocessor variable ©__cplusplus©, which adds appropriate ©extern "C"© qualifiers.
     5899For \Index*[C++]{\CC{}}, the name-mangling issue is often handled internally in many C header-files through checks for preprocessor variable ©__cplusplus©, which adds appropriate ©extern "C"© qualifiers.
    56505900
    56515901
     
    56575907
    56585908\subsection{Storage Management}
     5909\label{s:StorageManagement}
    56595910
    56605911The storage-management routines extend their C equivalents by overloading, alternate names, providing shallow type-safety, and removing the need to specify the allocation size for non-array types.
     
    58706121long double remainder( long double, long double );
    58716122
    5872 [ int, float ] remquo( float, float );§\indexc{remquo}§
    5873 float remquo( float, float, int * );
     6123float remquo( float, float, int * );§\indexc{remquo}§
     6124double remquo( double, double, int * );
     6125long double remquo( long double, long double, int * );
     6126[ int, float ] remquo( float, float );
    58746127[ int, double ] remquo( double, double );
    5875 double remquo( double, double, int * );
    58766128[ int, long double ] remquo( long double, long double );
    5877 long double remquo( long double, long double, int * );
    5878 
    5879 [ int, float ] div( float, float );                                             // alternative name for remquo
    5880 float div( float, float, int * );§\indexc{div}§
     6129
     6130float div( float, float, int * );§\indexc{div}§ §\C{// alternative name for remquo}§
     6131double div( double, double, int * );
     6132long double div( long double, long double, int * );
     6133[ int, float ] div( float, float );
    58816134[ int, double ] div( double, double );
    5882 double div( double, double, int * );
    58836135[ int, long double ] div( long double, long double );
    5884 long double div( long double, long double, int * );
    58856136
    58866137float fma( float, float, float );§\indexc{fma}§
     
    59126163double exp2( double );
    59136164long double exp2( long double );
    5914 float _Complex exp2( float _Complex );
    5915 double _Complex exp2( double _Complex );
    5916 long double _Complex exp2( long double _Complex );
     6165// float _Complex exp2( float _Complex );
     6166// double _Complex exp2( double _Complex );
     6167// long double _Complex exp2( long double _Complex );
    59176168
    59186169float expm1( float );§\indexc{expm1}§
     
    59206171long double expm1( long double );
    59216172
     6173float pow( float, float );§\indexc{pow}§
     6174double pow( double, double );
     6175long double pow( long double, long double );
     6176float _Complex pow( float _Complex, float _Complex );
     6177double _Complex pow( double _Complex, double _Complex );
     6178long double _Complex pow( long double _Complex, long double _Complex );
     6179\end{cfa}
     6180
     6181
     6182\subsection{Logarithm}
     6183
     6184\leavevmode
     6185\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    59226186float log( float );§\indexc{log}§
    59236187double log( double );
     
    59306194double log2( double );
    59316195long double log2( long double );
    5932 float _Complex log2( float _Complex );
    5933 double _Complex log2( double _Complex );
    5934 long double _Complex log2( long double _Complex );
     6196// float _Complex log2( float _Complex );
     6197// double _Complex log2( double _Complex );
     6198// long double _Complex log2( long double _Complex );
    59356199
    59366200float log10( float );§\indexc{log10}§
    59376201double log10( double );
    59386202long double log10( long double );
    5939 float _Complex log10( float _Complex );
    5940 double _Complex log10( double _Complex );
    5941 long double _Complex log10( long double _Complex );
     6203// float _Complex log10( float _Complex );
     6204// double _Complex log10( double _Complex );
     6205// long double _Complex log10( long double _Complex );
    59426206
    59436207float log1p( float );§\indexc{log1p}§
     
    59526216double logb( double );
    59536217long double logb( long double );
    5954 \end{cfa}
    5955 
    5956 
    5957 \subsection{Power}
    5958 
    5959 \leavevmode
    5960 \begin{cfa}[aboveskip=0pt,belowskip=0pt]
     6218
    59616219float sqrt( float );§\indexc{sqrt}§
    59626220double sqrt( double );
     
    59736231double hypot( double, double );
    59746232long double hypot( long double, long double );
    5975 
    5976 float pow( float, float );§\indexc{pow}§
    5977 double pow( double, double );
    5978 long double pow( long double, long double );
    5979 float _Complex pow( float _Complex, float _Complex );
    5980 double _Complex pow( double _Complex, double _Complex );
    5981 long double _Complex pow( long double _Complex, long double _Complex );
    59826233\end{cfa}
    59836234
     
    60336284long double atan2( long double, long double );
    60346285
    6035 float atan( float, float );                                                             // alternative name for atan2
     6286float atan( float, float );                                     §\C{// alternative name for atan2}§
    60366287double atan( double, double );§\indexc{atan}§
    60376288long double atan( long double, long double );
     
    62216472
    62226473\begin{cfa}
    6223 void ?{}( Int * this );                                 §\C{// constructor
     6474void ?{}( Int * this );                                 §\C{// constructor/destructor
    62246475void ?{}( Int * this, Int init );
    62256476void ?{}( Int * this, zero_t );
     
    64766727// implementation
    64776728struct Rational {§\indexc{Rational}§
    6478         long int numerator, denominator;                                        // invariant: denominator > 0
     6729        long int numerator, denominator;        §\C{// invariant: denominator > 0}§
    64796730}; // Rational
    64806731
  • src/ControlStruct/ExceptTranslate.cc

    r275f4b4 rcd7ef0b  
    1010// Created On       : Wed Jun 14 16:49:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jul 18 10:09:00 2017
    13 // Update Count     : 4
     12// Last Modified On : Tus Aug  8 16:54:00 2017
     13// Update Count     : 7
    1414//
    1515
     
    2121#include "SynTree/Type.h"
    2222#include "SynTree/Attribute.h"
     23#include "SynTree/VarExprReplacer.h"
    2324
    2425namespace ControlStruct {
    2526
    26         // This (large) section could probably be moved out of the class
    27         // and be static helpers instead.
    28 
    29         // Type(Qualifiers &, false, std::list<Attribute *> &)
    30 
    31         // void (*function)();
    32         static FunctionType try_func_t(Type::Qualifiers(), false);
    33         // void (*function)(int, exception);
    34         static FunctionType catch_func_t(Type::Qualifiers(), false);
    35         // int (*function)(exception);
    36         static FunctionType match_func_t(Type::Qualifiers(), false);
    37         // bool (*function)(exception);
    38         static FunctionType handle_func_t(Type::Qualifiers(), false);
    39         // void (*function)(__attribute__((unused)) void *);
    40         static FunctionType finally_func_t(Type::Qualifiers(), false);
    41 
    42         static void init_func_types() {
    43                 static bool init_complete = false;
    44                 if (init_complete) {
    45                         return;
    46                 }
     27        // Buricratic Helpers (Not having to do with the paritular operation.)
     28
     29        typedef std::list<CatchStmt*> CatchList;
     30
     31        void split( CatchList& allHandlers, CatchList& terHandlers,
     32                                CatchList& resHandlers ) {
     33                while ( !allHandlers.empty() ) {
     34                        CatchStmt * stmt = allHandlers.front();
     35                        allHandlers.pop_front();
     36                        if (CatchStmt::Terminate == stmt->get_kind()) {
     37                                terHandlers.push_back(stmt);
     38                        } else {
     39                                resHandlers.push_back(stmt);
     40                        }
     41                }
     42        }
     43
     44        void appendDeclStmt( CompoundStmt * block, Declaration * item ) {
     45                block->push_back(new DeclStmt(noLabels, item));
     46        }
     47
     48        Expression * nameOf( DeclarationWithType * decl ) {
     49                return new VariableExpr( decl );
     50        }
     51
     52        class ExceptionMutatorCore : public WithGuards {
     53                enum Context { NoHandler, TerHandler, ResHandler };
     54
     55                // Also need to handle goto, break & continue.
     56                // They need to be cut off in a ResHandler, until we enter another
     57                // loop, switch or the goto stays within the function.
     58
     59                Context cur_context;
     60
     61                // The current (innermost) termination handler exception declaration.
     62                ObjectDecl * handler_except_decl;
     63
     64                // The built in types used in translation.
     65                StructDecl * except_decl;
     66                StructDecl * node_decl;
     67                StructDecl * hook_decl;
     68
     69                // The many helper functions for code/syntree generation.
     70                Statement * create_given_throw(
     71                        const char * throwFunc, ThrowStmt * throwStmt );
     72                Statement * create_terminate_throw( ThrowStmt * throwStmt );
     73                Statement * create_terminate_rethrow( ThrowStmt * throwStmt );
     74                Statement * create_resume_throw( ThrowStmt * throwStmt );
     75                Statement * create_resume_rethrow( ThrowStmt * throwStmt );
     76                CompoundStmt * take_try_block( TryStmt * tryStmt );
     77                FunctionDecl * create_try_wrapper( CompoundStmt * body );
     78                FunctionDecl * create_terminate_catch( CatchList &handlers );
     79                CompoundStmt * create_single_matcher(
     80                        DeclarationWithType * except_obj, CatchStmt * modded_handler );
     81                FunctionDecl * create_terminate_match( CatchList &handlers );
     82                CompoundStmt * create_terminate_caller( FunctionDecl * try_wrapper,
     83                        FunctionDecl * terminate_catch, FunctionDecl * terminate_match );
     84                FunctionDecl * create_resume_handler( CatchList &handlers );
     85                CompoundStmt * create_resume_wrapper(
     86                        Statement * wraps, FunctionDecl * resume_handler );
     87                FunctionDecl * create_finally_wrapper( TryStmt * tryStmt );
     88                ObjectDecl * create_finally_hook( FunctionDecl * finally_wrapper );
     89
     90                // Types used in translation, make sure to use clone.
     91                // void (*function)();
     92                FunctionType try_func_t;
     93                // void (*function)(int, exception);
     94                FunctionType catch_func_t;
     95                // int (*function)(exception);
     96                FunctionType match_func_t;
     97                // bool (*function)(exception);
     98                FunctionType handle_func_t;
     99                // void (*function)(__attribute__((unused)) void *);
     100                FunctionType finally_func_t;
     101
     102                StructInstType * create_except_type() {
     103                        assert( except_decl );
     104                        return new StructInstType( noQualifiers, except_decl );
     105                }
     106                void init_func_types();
     107
     108        public:
     109                ExceptionMutatorCore() :
     110                        cur_context( NoHandler ),
     111                        handler_except_decl( nullptr ),
     112                        except_decl( nullptr ), node_decl( nullptr ), hook_decl( nullptr ),
     113                        try_func_t( noQualifiers, false ),
     114                        catch_func_t( noQualifiers, false ),
     115                        match_func_t( noQualifiers, false ),
     116                        handle_func_t( noQualifiers, false ),
     117                        finally_func_t( noQualifiers, false )
     118                {}
     119
     120                void premutate( CatchStmt *catchStmt );
     121                void premutate( StructDecl *structDecl );
     122                Statement * postmutate( ThrowStmt *throwStmt );
     123                Statement * postmutate( TryStmt *tryStmt );
     124        };
     125
     126        void ExceptionMutatorCore::init_func_types() {
     127                assert( except_decl );
     128
    47129                ObjectDecl index_obj(
    48130                        "__handler_index",
     
    60142                        new PointerType(
    61143                                noQualifiers,
    62                                 new BasicType( noQualifiers, BasicType::SignedInt )
     144                                new StructInstType( noQualifiers, except_decl )
    63145                                ),
    64146                        /*init*/ NULL
     
    69151                        LinkageSpec::Cforall,
    70152                        /*bitfieldWidth*/ NULL,
    71                         new BasicType(noQualifiers, BasicType::Bool),
     153                        new BasicType( noQualifiers, BasicType::Bool ),
    72154                        /*init*/ NULL
    73155                        );
     
    82164                                        noQualifiers
    83165                                        ),
    84                                 std::list<Attribute *>{new Attribute("unused")}
     166                                std::list<Attribute *>{ new Attribute( "unused" ) }
    85167                                ),
    86168                        NULL
     
    94176                handle_func_t.get_parameters().push_back( exception_obj.clone() );
    95177                finally_func_t.get_parameters().push_back( voidptr_obj.clone() );
    96 
    97                 init_complete = true;
    98         }
    99 
    100         // Buricratic Helpers (Not having to do with the paritular operation.)
    101 
    102         typedef std::list<CatchStmt*> CatchList;
    103 
    104         void split( CatchList& allHandlers, CatchList& terHandlers,
    105                                 CatchList& resHandlers ) {
    106                 while ( !allHandlers.empty() ) {
    107                         CatchStmt * stmt = allHandlers.front();
    108                         allHandlers.pop_front();
    109                         if (CatchStmt::Terminate == stmt->get_kind()) {
    110                                 terHandlers.push_back(stmt);
    111                         } else {
    112                                 resHandlers.push_back(stmt);
    113                         }
    114                 }
    115         }
    116 
    117         template<typename T>
    118         void free_all( std::list<T *> &list ) {
    119                 typename std::list<T *>::iterator it;
    120                 for ( it = list.begin() ; it != list.end() ; ++it ) {
    121                         delete *it;
    122                 }
    123                 list.clear();
    124         }
    125 
    126         void appendDeclStmt( CompoundStmt * block, Declaration * item ) {
    127                 block->push_back(new DeclStmt(noLabels, item));
    128         }
    129 
    130         Expression * nameOf( DeclarationWithType * decl ) {
    131                 return new VariableExpr( decl );
    132178        }
    133179
    134180        // ThrowStmt Mutation Helpers
    135181
    136         Statement * create_given_throw(
     182        Statement * ExceptionMutatorCore::create_given_throw(
    137183                        const char * throwFunc, ThrowStmt * throwStmt ) {
    138                 // { int NAME = EXPR; throwFunc( &NAME ); }
    139                 CompoundStmt * result = new CompoundStmt( noLabels );
    140                 ObjectDecl * local = new ObjectDecl(
    141                         "__local_exception_copy",
    142                         Type::StorageClasses(),
    143                         LinkageSpec::Cforall,
    144                         NULL,
    145                         new BasicType( noQualifiers, BasicType::SignedInt ),
    146                         new SingleInit( throwStmt->get_expr() )
    147                         );
    148                 appendDeclStmt( result, local );
     184                // `throwFunc`( `throwStmt->get_name` );
    149185                UntypedExpr * call = new UntypedExpr( new NameExpr( throwFunc ) );
    150                 call->get_args().push_back( new AddressExpr( nameOf( local ) ) );
    151                 result->push_back( new ExprStmt( throwStmt->get_labels(), call ) );
     186                call->get_args().push_back( throwStmt->get_expr() );
    152187                throwStmt->set_expr( nullptr );
    153188                delete throwStmt;
    154                 return result;
    155         }
    156 
    157         Statement * create_terminate_throw( ThrowStmt *throwStmt ) {
    158                 // { int NAME = EXPR; __throw_terminate( &NAME ); }
     189                return new ExprStmt( noLabels, call );
     190        }
     191
     192        Statement * ExceptionMutatorCore::create_terminate_throw(
     193                        ThrowStmt *throwStmt ) {
     194                // __throw_terminate( `throwStmt->get_name()` ); }
    159195                return create_given_throw( "__cfaehm__throw_terminate", throwStmt );
    160196        }
    161         Statement * create_terminate_rethrow( ThrowStmt *throwStmt ) {
    162                 // __rethrow_terminate();
     197
     198        Statement * ExceptionMutatorCore::create_terminate_rethrow(
     199                        ThrowStmt *throwStmt ) {
     200                // { `handler_except_decl` = NULL; __rethrow_terminate(); }
    163201                assert( nullptr == throwStmt->get_expr() );
    164                 Statement * result = new ExprStmt(
    165                         throwStmt->get_labels(),
     202                assert( handler_except_decl );
     203
     204                CompoundStmt * result = new CompoundStmt( throwStmt->get_labels() );
     205                result->push_back( new ExprStmt( noLabels, UntypedExpr::createAssign(
     206                        nameOf( handler_except_decl ),
     207                        new ConstantExpr( Constant::null(
     208                                new PointerType(
     209                                        noQualifiers,
     210                                        handler_except_decl->get_type()->clone()
     211                                        )
     212                                ) )
     213                        ) ) );
     214                result->push_back( new ExprStmt(
     215                        noLabels,
    166216                        new UntypedExpr( new NameExpr( "__cfaehm__rethrow_terminate" ) )
    167                         );
     217                        ) );
    168218                delete throwStmt;
    169219                return result;
    170220        }
    171         Statement * create_resume_throw( ThrowStmt *throwStmt ) {
    172                 // __throw_resume( EXPR );
     221
     222        Statement * ExceptionMutatorCore::create_resume_throw(
     223                        ThrowStmt *throwStmt ) {
     224                // __throw_resume( `throwStmt->get_name` );
    173225                return create_given_throw( "__cfaehm__throw_resume", throwStmt );
    174226        }
    175         Statement * create_resume_rethrow( ThrowStmt *throwStmt ) {
     227
     228        Statement * ExceptionMutatorCore::create_resume_rethrow(
     229                        ThrowStmt *throwStmt ) {
    176230                // return false;
    177231                Statement * result = new ReturnStmt(
     
    185239        // TryStmt Mutation Helpers
    186240
    187         CompoundStmt * take_try_block( TryStmt *tryStmt ) {
     241        CompoundStmt * ExceptionMutatorCore::take_try_block( TryStmt *tryStmt ) {
    188242                CompoundStmt * block = tryStmt->get_block();
    189243                tryStmt->set_block( nullptr );
    190244                return block;
    191245        }
    192         FunctionDecl * create_try_wrapper( CompoundStmt *body ) {
     246
     247        FunctionDecl * ExceptionMutatorCore::create_try_wrapper(
     248                        CompoundStmt *body ) {
    193249
    194250                return new FunctionDecl( "try", Type::StorageClasses(),
     
    196252        }
    197253
    198         FunctionDecl * create_terminate_catch( CatchList &handlers ) {
     254        FunctionDecl * ExceptionMutatorCore::create_terminate_catch(
     255                        CatchList &handlers ) {
    199256                std::list<CaseStmt *> handler_wrappers;
    200257
    201258                FunctionType *func_type = catch_func_t.clone();
    202259                DeclarationWithType * index_obj = func_type->get_parameters().front();
    203         //      DeclarationWithType * except_obj = func_type->get_parameters().back();
     260                DeclarationWithType * except_obj = func_type->get_parameters().back();
    204261
    205262                // Index 1..{number of handlers}
     
    210267                        CatchStmt * handler = *it;
    211268
    212                         // INTEGERconstant Version
    213269                        // case `index`:
    214270                        // {
    215                         //     `handler.body`
     271                        //     `handler.decl` = { (virtual `decl.type`)`except` };
     272                        //     `handler.body`;
    216273                        // }
    217274                        // return;
    218                         std::list<Statement *> caseBody;
    219                         caseBody.push_back( handler->get_body() );
     275                        CompoundStmt * block = new CompoundStmt( noLabels );
     276
     277                        // Just copy the exception value. (Post Validation)
     278                        ObjectDecl * handler_decl =
     279                                static_cast<ObjectDecl *>( handler->get_decl() );
     280                        ObjectDecl * local_except = handler_decl->clone();
     281                        local_except->set_init(
     282                                new ListInit({ new SingleInit(
     283                                        new VirtualCastExpr( nameOf( except_obj ),
     284                                                local_except->get_type()
     285                                                )
     286                                        ) })
     287                                );
     288                        block->push_back( new DeclStmt( noLabels, local_except ) );
     289
     290                        // Add the cleanup attribute.
     291                        local_except->get_attributes().push_back( new Attribute(
     292                                "cleanup",
     293                                { new NameExpr( "__cfaehm__cleanup_terminate" ) }
     294                                ) );
     295
     296                        // Update variables in the body to point to this local copy.
     297                        {
     298                                VarExprReplacer::DeclMap mapping;
     299                                mapping[ handler_decl ] = local_except;
     300                                VarExprReplacer mapper( mapping );
     301                                handler->get_body()->accept( mapper );
     302                        }
     303
     304                        block->push_back( handler->get_body() );
    220305                        handler->set_body( nullptr );
    221                         caseBody.push_back( new ReturnStmt( noLabels, nullptr ) );
    222 
     306
     307                        std::list<Statement *> caseBody
     308                                        { block, new ReturnStmt( noLabels, nullptr ) };
    223309                        handler_wrappers.push_back( new CaseStmt(
    224310                                noLabels,
     
    249335        // Create a single check from a moddified handler.
    250336        // except_obj is referenced, modded_handler will be freed.
    251         CompoundStmt *create_single_matcher(
     337        CompoundStmt * ExceptionMutatorCore::create_single_matcher(
    252338                        DeclarationWithType * except_obj, CatchStmt * modded_handler ) {
     339                // {
     340                //     `modded_handler.decl`
     341                //     if ( `decl.name = (virtual `decl.type`)`except`
     342                //             [&& `modded_handler.cond`] ) {
     343                //         `modded_handler.body`
     344                //     }
     345                // }
     346
    253347                CompoundStmt * block = new CompoundStmt( noLabels );
    254348
    255                 // INTEGERconstant Version
    256                 assert( nullptr == modded_handler->get_decl() );
    257                 ConstantExpr * number =
    258                         dynamic_cast<ConstantExpr*>( modded_handler->get_cond() );
    259                 assert( number );
    260                 modded_handler->set_cond( nullptr );
    261 
    262                 Expression * cond;
    263                 {
    264                         std::list<Expression *> args;
    265                         args.push_back( number );
    266 
    267                         std::list<Expression *> rhs_args;
    268                         rhs_args.push_back( nameOf( except_obj ) );
    269                         Expression * rhs = new UntypedExpr(
    270                                 new NameExpr( "*?" ), rhs_args );
    271                         args.push_back( rhs );
    272 
    273                         cond = new UntypedExpr( new NameExpr( "?==?" /*???*/), args );
    274                 }
    275 
     349                // Local Declaration
     350                ObjectDecl * local_except =
     351                        dynamic_cast<ObjectDecl *>( modded_handler->get_decl() );
     352                assert( local_except );
     353                block->push_back( new DeclStmt( noLabels, local_except ) );
     354
     355                // Check for type match.
     356                Expression * cond = UntypedExpr::createAssign( nameOf( local_except ),
     357                        new VirtualCastExpr( nameOf( except_obj ),
     358                                local_except->get_type()->clone() ) );
     359
     360                // Add the check on the conditional if it is provided.
    276361                if ( modded_handler->get_cond() ) {
    277362                        cond = new LogicalExpr( cond, modded_handler->get_cond() );
    278363                }
     364                // Construct the match condition.
    279365                block->push_back( new IfStmt( noLabels,
    280366                        cond, modded_handler->get_body(), nullptr ) );
     
    287373        }
    288374
    289         FunctionDecl * create_terminate_match( CatchList &handlers ) {
     375        FunctionDecl * ExceptionMutatorCore::create_terminate_match(
     376                        CatchList &handlers ) {
     377                // int match(exception * except) {
     378                //     HANDLER WRAPPERS { return `index`; }
     379                // }
     380
    290381                CompoundStmt * body = new CompoundStmt( noLabels );
    291382
     
    319410        }
    320411
    321         CompoundStmt * create_terminate_caller(
     412        CompoundStmt * ExceptionMutatorCore::create_terminate_caller(
    322413                        FunctionDecl * try_wrapper,
    323414                        FunctionDecl * terminate_catch,
    324                         FunctionDecl * terminate_match) {
     415                        FunctionDecl * terminate_match ) {
     416                // { __cfaehm__try_terminate(`try`, `catch`, `match`); }
    325417
    326418                UntypedExpr * caller = new UntypedExpr( new NameExpr(
     
    336428        }
    337429
    338         FunctionDecl * create_resume_handler( CatchList &handlers ) {
     430        FunctionDecl * ExceptionMutatorCore::create_resume_handler(
     431                        CatchList &handlers ) {
     432                // bool handle(exception * except) {
     433                //     HANDLER WRAPPERS { `hander->body`; return true; }
     434                // }
    339435                CompoundStmt * body = new CompoundStmt( noLabels );
    340436
     
    369465        }
    370466
    371         CompoundStmt * create_resume_wrapper(
    372                         StructDecl * node_decl,
     467        CompoundStmt * ExceptionMutatorCore::create_resume_wrapper(
    373468                        Statement * wraps,
    374469                        FunctionDecl * resume_handler ) {
     
    414509        }
    415510
    416         FunctionDecl * create_finally_wrapper( TryStmt * tryStmt ) {
     511        FunctionDecl * ExceptionMutatorCore::create_finally_wrapper(
     512                        TryStmt * tryStmt ) {
     513                // void finally() { <finally code> }
    417514                FinallyStmt * finally = tryStmt->get_finally();
    418515                CompoundStmt * body = finally->get_block();
     
    425522        }
    426523
    427         ObjectDecl * create_finally_hook(
    428                         StructDecl * hook_decl, FunctionDecl * finally_wrapper ) {
     524        ObjectDecl * ExceptionMutatorCore::create_finally_hook(
     525                        FunctionDecl * finally_wrapper ) {
    429526                // struct __cfaehm__cleanup_hook __finally_hook
    430527                //      __attribute__((cleanup( finally_wrapper )));
     
    452549        }
    453550
    454 
    455         class ExceptionMutatorCore : public WithGuards {
    456                 enum Context { NoHandler, TerHandler, ResHandler };
    457 
    458                 // Also need to handle goto, break & continue.
    459                 // They need to be cut off in a ResHandler, until we enter another
    460                 // loop, switch or the goto stays within the function.
    461 
    462                 Context cur_context;
    463 
    464                 // We might not need this, but a unique base for each try block's
    465                 // generated functions might be nice.
    466                 //std::string curFunctionName;
    467                 //unsigned int try_count = 0;
    468 
    469                 StructDecl *node_decl;
    470                 StructDecl *hook_decl;
    471 
    472         public:
    473                 ExceptionMutatorCore() :
    474                         cur_context(NoHandler),
    475                         node_decl(nullptr), hook_decl(nullptr)
    476                 {}
    477 
    478                 void premutate( CatchStmt *catchStmt );
    479                 void premutate( StructDecl *structDecl );
    480                 Statement * postmutate( ThrowStmt *throwStmt );
    481                 Statement * postmutate( TryStmt *tryStmt );
    482         };
     551        // Visiting/Mutating Functions
     552        void ExceptionMutatorCore::premutate( CatchStmt *catchStmt ) {
     553                // Validate the Statement's form.
     554                ObjectDecl * decl =
     555                        dynamic_cast<ObjectDecl *>( catchStmt->get_decl() );
     556                if ( decl && true /* check decl->get_type() */ ) {
     557                        // Pass.
     558                } else if ( CatchStmt::Terminate == catchStmt->get_kind() ) {
     559                        throw SemanticError("catch must have exception type");
     560                } else {
     561                        throw SemanticError("catchResume must have exception type");
     562                }
     563
     564                // Track the handler context.
     565                GuardValue( cur_context );
     566                if ( CatchStmt::Terminate == catchStmt->get_kind() ) {
     567                        cur_context = TerHandler;
     568
     569                        GuardValue( handler_except_decl );
     570                        handler_except_decl = decl;
     571                } else {
     572                        cur_context = ResHandler;
     573                }
     574        }
     575
     576        void ExceptionMutatorCore::premutate( StructDecl *structDecl ) {
     577                if ( !structDecl->has_body() ) {
     578                        // Skip children?
     579                        return;
     580                } else if ( structDecl->get_name() == "__cfaehm__base_exception_t" ) {
     581                        assert( nullptr == except_decl );
     582                        except_decl = structDecl;
     583                        init_func_types();
     584                } else if ( structDecl->get_name() == "__cfaehm__try_resume_node" ) {
     585                        assert( nullptr == node_decl );
     586                        node_decl = structDecl;
     587                } else if ( structDecl->get_name() == "__cfaehm__cleanup_hook" ) {
     588                        assert( nullptr == hook_decl );
     589                        hook_decl = structDecl;
     590                }
     591                // Later we might get the exception type as well.
     592        }
    483593
    484594        Statement * ExceptionMutatorCore::postmutate( ThrowStmt *throwStmt ) {
     595                assert( except_decl );
     596
    485597                // Ignoring throwStmt->get_target() for now.
    486598                if ( ThrowStmt::Terminate == throwStmt->get_kind() ) {
     
    510622
    511623        Statement * ExceptionMutatorCore::postmutate( TryStmt *tryStmt ) {
     624                assert( except_decl );
    512625                assert( node_decl );
    513626                assert( hook_decl );
     
    524637                        appendDeclStmt( block, finally_block );
    525638                        // Create and add the finally cleanup hook.
    526                         appendDeclStmt( block,
    527                                 create_finally_hook( hook_decl, finally_block ) );
     639                        appendDeclStmt( block, create_finally_hook( finally_block ) );
    528640                }
    529641
     
    539651                        appendDeclStmt( block, resume_handler );
    540652                        // Prepare hooks
    541                         inner = create_resume_wrapper( node_decl, inner, resume_handler );
     653                        inner = create_resume_wrapper( inner, resume_handler );
    542654                }
    543655
     
    560672                block->push_back( inner );
    561673
    562                 //free_all( termination_handlers );
    563                 //free_all( resumption_handlers );
    564 
    565674                return block;
    566675        }
    567676
    568         void ExceptionMutatorCore::premutate( CatchStmt *catchStmt ) {
    569                 GuardValue( cur_context );
    570                 if ( CatchStmt::Terminate == catchStmt->get_kind() ) {
    571                         cur_context = TerHandler;
    572                 } else {
    573                         cur_context = ResHandler;
    574                 }
    575         }
    576 
    577         void ExceptionMutatorCore::premutate( StructDecl *structDecl ) {
    578                 if ( !structDecl->has_body() ) {
    579                         // Skip children?
    580                         return;
    581                 } else if ( structDecl->get_name() == "__cfaehm__try_resume_node" ) {
    582                         assert( nullptr == node_decl );
    583                         node_decl = structDecl;
    584                 } else if ( structDecl->get_name() == "__cfaehm__cleanup_hook" ) {
    585                         assert( nullptr == hook_decl );
    586                         hook_decl = structDecl;
    587                 }
    588                 // Later we might get the exception type as well.
    589         }
    590 
    591677        void translateEHM( std::list< Declaration *> & translationUnit ) {
    592                 init_func_types();
    593 
    594678                PassVisitor<ExceptionMutatorCore> translator;
    595679                mutateAll( translationUnit, translator );
  • src/GenPoly/Box.cc

    r275f4b4 rcd7ef0b  
    2727#include "Box.h"
    2828#include "DeclMutator.h"
     29#include "Lvalue.h"
     30#include "FindFunction.h"
    2931#include "PolyMutator.h"
    30 #include "FindFunction.h"
    3132#include "ScopedSet.h"
    3233#include "ScrubTyVars.h"
     
    755756
    756757                void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) {
    757                         assert( arg->has_result() );
     758                        assertf( arg->has_result(), "arg does not have result: %s", toString( arg ).c_str() );
    758759                        if ( isPolyType( param, exprTyVars ) ) {
    759                                 if ( isPolyType( arg->get_result() ) ) {
     760                                Type * newType = arg->get_result()->clone();
     761                                if ( env ) env->apply( newType );
     762                                std::auto_ptr<Type> manager( newType );
     763                                if ( isPolyType( newType ) ) {
    760764                                        // if the argument's type is polymorphic, we don't need to box again!
    761765                                        return;
    762766                                } else if ( arg->get_result()->get_lvalue() ) {
    763                                         // VariableExpr and MemberExpr are lvalues; need to check this isn't coming from the second arg of a comma expression though (not an lvalue)
    764                                         // xxx - need to test that this code is still reachable
    765                                         if ( CommaExpr *commaArg = dynamic_cast< CommaExpr* >( arg ) ) {
    766                                                 commaArg->set_arg2( new AddressExpr( commaArg->get_arg2() ) );
    767                                         } else {
    768                                                 arg = new AddressExpr( arg );
    769                                         }
     767                                        // argument expression may be CFA lvalue, but not C lvalue -- apply generalizedLvalue transformations.
     768                                        arg =  generalizedLvalue( new AddressExpr( arg ) );
    770769                                        if ( ! ResolvExpr::typesCompatible( param, arg->get_result(), SymTab::Indexer() ) ) {
    771770                                                // silence warnings by casting boxed parameters when the actual type does not match up with the formal type.
     
    18791878                        return structDecl;
    18801879                }
    1881                
     1880
    18821881                Declaration *Pass3::mutate( UnionDecl *unionDecl ) {
    18831882                        stripGenericMembers( unionDecl );
  • src/GenPoly/Lvalue.cc

    r275f4b4 rcd7ef0b  
    2727#include "SynTree/Mutator.h"
    2828#include "SymTab/Indexer.h"
     29
    2930#include "ResolvExpr/Resolver.h"
     31#include "ResolvExpr/TypeEnvironment.h"
    3032#include "ResolvExpr/typeops.h"
     33#include "ResolvExpr/Unify.h"
    3134
    3235#include "Common/UniqueName.h"
     
    6063                        typedef Mutator Parent;
    6164
     65                        virtual Expression * mutate( MemberExpr * memExpr );
    6266                        virtual Expression * mutate( AddressExpr * addressExpr );
     67
     68                        template<typename Func>
     69                        Expression * applyTransformation( Expression * expr, Expression * arg, Func mkExpr );
    6370                };
    6471        } // namespace
     
    7178                acceptAll( translationUnit, p2 );
    7279                mutateAll( translationUnit, genLval );
     80        }
     81
     82        Expression * generalizedLvalue( Expression * expr ) {
     83                GeneralizedLvalue genLval;
     84                return expr->acceptMutator( genLval );
    7385        }
    7486
     
    163175                }
    164176
    165                 Expression * GeneralizedLvalue::mutate( AddressExpr * addrExpr ) {
    166                         addrExpr = safe_dynamic_cast< AddressExpr * >( Parent::mutate( addrExpr ) );
    167                         if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( addrExpr->get_arg() ) ) {
     177                template<typename Func>
     178                Expression * GeneralizedLvalue::applyTransformation( Expression * expr, Expression * arg, Func mkExpr ) {
     179                        if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( arg ) ) {
    168180                                Expression * arg1 = commaExpr->get_arg1()->clone();
    169181                                Expression * arg2 = commaExpr->get_arg2()->clone();
    170                                 delete addrExpr;
    171                                 return new CommaExpr( arg1, new AddressExpr( arg2 ) );
    172                         } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( addrExpr->get_arg() ) ) {
     182                                Expression * ret = new CommaExpr( arg1, mkExpr( arg2 ) );
     183                                ret->set_env( expr->get_env() );
     184                                expr->set_env( nullptr );
     185                                delete expr;
     186                                return ret->acceptMutator( *this );
     187                        } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( arg ) ) {
    173188                                Expression * arg1 = condExpr->get_arg1()->clone();
    174189                                Expression * arg2 = condExpr->get_arg2()->clone();
    175190                                Expression * arg3 = condExpr->get_arg3()->clone();
    176                                 delete addrExpr;
    177                                 return new ConditionalExpr( arg1, new AddressExpr( arg2 ), new AddressExpr( arg3 ) );
     191                                ConditionalExpr * ret = new ConditionalExpr( arg1, mkExpr( arg2 ), mkExpr( arg3 ) );
     192                                ret->set_env( expr->get_env() );
     193                                expr->set_env( nullptr );
     194                                delete expr;
     195
     196                                // conditional expr type may not be either of the argument types, need to unify
     197                                using namespace ResolvExpr;
     198                                Type* commonType = nullptr;
     199                                TypeEnvironment newEnv;
     200                                AssertionSet needAssertions, haveAssertions;
     201                                OpenVarSet openVars;
     202                                unify( ret->get_arg2()->get_result(), ret->get_arg3()->get_result(), newEnv, needAssertions, haveAssertions, openVars, SymTab::Indexer(), commonType );
     203                                ret->set_result( commonType ? commonType : ret->get_arg2()->get_result()->clone() );
     204                                return ret->acceptMutator( *this );
    178205                        }
    179                         return addrExpr;
     206                        return expr;
     207                }
     208
     209                Expression * GeneralizedLvalue::mutate( MemberExpr * memExpr ) {
     210                        Parent::mutate( memExpr );
     211                        return applyTransformation( memExpr, memExpr->get_aggregate(), [=]( Expression * aggr ) { return new MemberExpr( memExpr->get_member(), aggr ); } );
     212                }
     213
     214                Expression * GeneralizedLvalue::mutate( AddressExpr * addrExpr ) {
     215                        addrExpr = safe_dynamic_cast< AddressExpr * >( Parent::mutate( addrExpr ) );
     216                        return applyTransformation( addrExpr, addrExpr->get_arg(), []( Expression * arg ) { return new AddressExpr( arg ); } );
    180217                }
    181218        } // namespace
  • src/GenPoly/Lvalue.h

    r275f4b4 rcd7ef0b  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Lvalue.h -- 
     7// Lvalue.h --
    88//
    99// Author           : Richard C. Bilson
     
    2323        /// replaces return type of `lvalue T` with `T*`, along with appropriate address-of and dereference operators
    2424        void convertLvalue( std::list< Declaration* >& translationUnit );
     25
     26        /// applies transformations that allow GCC to accept more complicated lvalue expressions, e.g. &(a, b)
     27        Expression * generalizedLvalue( Expression * expr );
    2528} // namespace GenPoly
    2629
  • src/Makefile.am

    r275f4b4 rcd7ef0b  
    4343cfa_cpplib_PROGRAMS = driver/cfa-cpp
    4444driver_cfa_cpp_SOURCES = ${SRC}
    45 driver_cfa_cpp_LDADD = ${LEXLIB} -ldl                   # yywrap
     45driver_cfa_cpp_LDADD = -ldl                     # yywrap
    4646driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -Wextra -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14
    4747driver_cfa_cpp_LDFLAGS = -Xlinker -export-dynamic
  • src/Makefile.in

    r275f4b4 rcd7ef0b  
    262262am_driver_cfa_cpp_OBJECTS = $(am__objects_1)
    263263driver_cfa_cpp_OBJECTS = $(am_driver_cfa_cpp_OBJECTS)
    264 am__DEPENDENCIES_1 =
    265 driver_cfa_cpp_DEPENDENCIES = $(am__DEPENDENCIES_1)
     264driver_cfa_cpp_DEPENDENCIES =
    266265driver_cfa_cpp_LINK = $(CXXLD) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) \
    267266        $(driver_cfa_cpp_LDFLAGS) $(LDFLAGS) -o $@
     
    548547cfa_cpplibdir = ${CFA_LIBDIR}
    549548driver_cfa_cpp_SOURCES = ${SRC}
    550 driver_cfa_cpp_LDADD = ${LEXLIB} -ldl                   # yywrap
     549driver_cfa_cpp_LDADD = -ldl                     # yywrap
    551550driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -Wextra -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14
    552551driver_cfa_cpp_LDFLAGS = -Xlinker -export-dynamic
  • src/Parser/ExpressionNode.cc

    r275f4b4 rcd7ef0b  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jul 25 10:11:00 2017
    13 // Update Count     : 551
    14 //
    15 
    16 #include <cassert>
    17 #include <cctype>
    18 #include <climits>
    19 #include <cstdio>
    20 #include <algorithm>
     12// Last Modified On : Wed Aug  2 11:12:00 2017
     13// Update Count     : 568
     14//
     15
     16#include <climits>                                                                              // access INT_MAX, UINT_MAX, LONG_MAX, ULONG_MAX, LLONG_MAX
    2117#include <sstream>
    2218
     
    2622#include "SynTree/Expression.h"
    2723#include "SynTree/Declaration.h"
    28 #include "Common/UnimplementedError.h"
    2924#include "parserutility.h"
    30 #include "Common/utility.h"
    3125
    3226using namespace std;
     
    4640// type.
    4741
    48 Type::Qualifiers noQualifiers;                          // no qualifiers on constants
     42extern const Type::Qualifiers noQualifiers;             // no qualifiers on constants
    4943
    5044static inline bool checkU( char c ) { return c == 'u' || c == 'U'; }
     
    5549static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
    5650
    57 Expression *build_constantInteger( const std::string & str ) {
     51Expression * build_constantInteger( const std::string & str ) {
    5852        static const BasicType::Kind kind[2][3] = {
    5953                { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt },
     
    6256        bool dec = true, Unsigned = false;                                      // decimal, unsigned constant
    6357        int size;                                                                                       // 0 => int, 1 => long, 2 => long long
    64         unsigned long long int v;                                                               // converted integral value
     58        unsigned long long int v;                                                       // converted integral value
    6559        size_t last = str.length() - 1;                                         // last character of constant
    66 
     60        Expression * ret;
     61
     62        // special constants
     63        if ( str == "0" ) {
     64                ret = new ConstantExpr( Constant( (Type *)new ZeroType( noQualifiers ), str, (unsigned long long int)0 ) );
     65                goto CLEANUP;
     66        } // if
     67        if ( str == "1" ) {
     68                ret = new ConstantExpr( Constant( (Type *)new OneType( noQualifiers ), str, (unsigned long long int)1 ) );
     69                goto CLEANUP;
     70        } // if
     71       
    6772        if ( str[0] == '0' ) {                                                          // octal/hex constant ?
    6873                dec = false;
     
    118123        } // if
    119124
    120         Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) );
     125        ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) );
     126  CLEANUP:
    121127        delete &str;                                                                            // created by lex
    122128        return ret;
    123129} // build_constantInteger
    124130
    125 Expression *build_constantFloat( const std::string & str ) {
     131Expression * build_constantFloat( const std::string & str ) {
    126132        static const BasicType::Kind kind[2][3] = {
    127133                { BasicType::Float, BasicType::Double, BasicType::LongDouble },
     
    158164} // build_constantFloat
    159165
    160 Expression *build_constantChar( const std::string & str ) {
     166Expression * build_constantChar( const std::string & str ) {
    161167        Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) );
    162168        delete &str;                                                                            // created by lex
     
    164170} // build_constantChar
    165171
    166 ConstantExpr *build_constantStr( const std::string & str ) {
     172ConstantExpr * build_constantStr( const std::string & str ) {
    167173        // string should probably be a primitive type
    168         ArrayType *at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
    169                                                                    new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ),  // +1 for '\0' and -2 for '"'
     174        ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
     175                                                                   new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
    170176                                                                   false, false );
    171         // constant 0 is ignored for pure string value
    172         ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) );
     177        ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value
    173178        delete &str;                                                                            // created by lex
    174179        return ret;
    175180} // build_constantStr
    176 
    177 Expression *build_constantZeroOne( const std::string & str ) {
    178         Expression * ret = new ConstantExpr( Constant( str == "0" ? (Type *)new ZeroType( noQualifiers ) : (Type*)new OneType( noQualifiers ), str,
    179                                                                                                    str == "0" ? (unsigned long long int)0 : (unsigned long long int)1 ) );
    180         delete &str;                                                                            // created by lex
    181         return ret;
    182 } // build_constantChar
    183181
    184182Expression * build_field_name_FLOATINGconstant( const std::string & str ) {
     
    209207} // build_field_name_fraction_constants
    210208
    211 
    212 
    213209Expression * build_field_name_REALFRACTIONconstant( const std::string & str ) {
    214210        if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str );
     
    225221} // build_field_name_REALDECIMALconstant
    226222
    227 NameExpr * build_varref( const string *name ) {
    228         NameExpr *expr = new NameExpr( *name, nullptr );
     223NameExpr * build_varref( const string * name ) {
     224        NameExpr * expr = new NameExpr( *name, nullptr );
    229225        delete name;
    230226        return expr;
    231 }
    232 
    233 // Must harmonize with OperKinds.
    234 static const char *OperName[] = {
     227} // build_varref
     228
     229
     230static const char * OperName[] = {                                              // must harmonize with OperKinds
    235231        // diadic
    236232        "SizeOf", "AlignOf", "OffsetOf", "?+?", "?-?", "?\\?", "?*?", "?/?", "?%?", "||", "&&",
     
    240236        // monadic
    241237        "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", "&&"
    242 };
    243 
    244 Expression *build_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) {
    245         Type *targetType = maybeMoveBuildType( decl_node );
     238}; // OperName
     239
     240Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) {
     241        Type * targetType = maybeMoveBuildType( decl_node );
    246242        if ( dynamic_cast< VoidType * >( targetType ) ) {
    247243                delete targetType;
     
    250246                return new CastExpr( maybeMoveBuild< Expression >(expr_node), targetType );
    251247        } // if
    252 }
    253 
    254 
    255 Expression *build_virtual_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) {
    256         Type *targetType = maybeMoveBuildType( decl_node );
    257         Expression *castArg = maybeMoveBuild< Expression >( expr_node );
     248} // build_cast
     249
     250Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) {
     251        Type * targetType = maybeMoveBuildType( decl_node );
     252        Expression * castArg = maybeMoveBuild< Expression >( expr_node );
    258253        return new VirtualCastExpr( castArg, targetType );
    259 }
    260 
    261 Expression *build_fieldSel( ExpressionNode *expr_node, Expression *member ) {
    262         UntypedMemberExpr *ret = new UntypedMemberExpr( member, maybeMoveBuild< Expression >(expr_node) );
    263         return ret;
    264 }
    265 
    266 Expression *build_pfieldSel( ExpressionNode *expr_node, Expression *member ) {
    267         UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
     254} // build_virtual_cast
     255
     256Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member ) {
     257        UntypedMemberExpr * ret = new UntypedMemberExpr( member, maybeMoveBuild< Expression >(expr_node) );
     258        return ret;
     259} // build_fieldSel
     260
     261Expression * build_pfieldSel( ExpressionNode * expr_node, Expression * member ) {
     262        UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) );
    268263        deref->location = expr_node->location;
    269264        deref->get_args().push_back( maybeMoveBuild< Expression >(expr_node) );
    270         UntypedMemberExpr *ret = new UntypedMemberExpr( member, deref );
    271         return ret;
    272 }
    273 
    274 Expression *build_addressOf( ExpressionNode *expr_node ) {
     265        UntypedMemberExpr * ret = new UntypedMemberExpr( member, deref );
     266        return ret;
     267} // build_pfieldSel
     268
     269Expression * build_addressOf( ExpressionNode * expr_node ) {
    275270                return new AddressExpr( maybeMoveBuild< Expression >(expr_node) );
    276 }
    277 Expression *build_sizeOfexpr( ExpressionNode *expr_node ) {
     271} // build_addressOf
     272
     273Expression * build_sizeOfexpr( ExpressionNode * expr_node ) {
    278274        return new SizeofExpr( maybeMoveBuild< Expression >(expr_node) );
    279 }
    280 Expression *build_sizeOftype( DeclarationNode *decl_node ) {
     275} // build_sizeOfexpr
     276
     277Expression * build_sizeOftype( DeclarationNode * decl_node ) {
    281278        return new SizeofExpr( maybeMoveBuildType( decl_node ) );
    282 }
    283 Expression *build_alignOfexpr( ExpressionNode *expr_node ) {
     279} // build_sizeOftype
     280
     281Expression * build_alignOfexpr( ExpressionNode * expr_node ) {
    284282        return new AlignofExpr( maybeMoveBuild< Expression >(expr_node) );
    285 }
    286 Expression *build_alignOftype( DeclarationNode *decl_node ) {
     283} // build_alignOfexpr
     284
     285Expression * build_alignOftype( DeclarationNode * decl_node ) {
    287286        return new AlignofExpr( maybeMoveBuildType( decl_node) );
    288 }
    289 Expression *build_offsetOf( DeclarationNode *decl_node, NameExpr *member ) {
     287} // build_alignOftype
     288
     289Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr * member ) {
    290290        Expression * ret = new UntypedOffsetofExpr( maybeMoveBuildType( decl_node ), member->get_name() );
    291291        delete member;
    292292        return ret;
    293 }
    294 
    295 Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ) {
     293} // build_offsetOf
     294
     295Expression * build_and_or( ExpressionNode * expr_node1, ExpressionNode * expr_node2, bool kind ) {
    296296        return new LogicalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), notZeroExpr( maybeMoveBuild< Expression >(expr_node2) ), kind );
    297 }
    298 
    299 Expression *build_unary_val( OperKinds op, ExpressionNode *expr_node ) {
     297} // build_and_or
     298
     299Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node ) {
    300300        std::list< Expression * > args;
    301301        args.push_back( maybeMoveBuild< Expression >(expr_node) );
    302302        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    303 }
    304 Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node ) {
     303} // build_unary_val
     304
     305Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) {
    305306        std::list< Expression * > args;
    306307        args.push_back( new AddressExpr( maybeMoveBuild< Expression >(expr_node) ) );
    307308        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    308 }
    309 Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
     309} // build_unary_ptr
     310
     311Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
    310312        std::list< Expression * > args;
    311313        args.push_back( maybeMoveBuild< Expression >(expr_node1) );
    312314        args.push_back( maybeMoveBuild< Expression >(expr_node2) );
    313315        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    314 }
    315 Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
     316} // build_binary_val
     317
     318Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
    316319        std::list< Expression * > args;
    317320        args.push_back( new AddressExpr( maybeMoveBuild< Expression >(expr_node1) ) );
    318321        args.push_back( maybeMoveBuild< Expression >(expr_node2) );
    319322        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    320 }
    321 
    322 Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ) {
     323} // build_binary_ptr
     324
     325Expression * build_cond( ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 ) {
    323326        return new ConditionalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), maybeMoveBuild< Expression >(expr_node2), maybeMoveBuild< Expression >(expr_node3) );
    324 }
    325 
    326 Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
     327} // build_cond
     328
     329Expression * build_comma( ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
    327330        return new CommaExpr( maybeMoveBuild< Expression >(expr_node1), maybeMoveBuild< Expression >(expr_node2) );
    328 }
    329 
    330 Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node ) {
     331} // build_comma
     332
     333Expression * build_attrexpr( NameExpr * var, ExpressionNode * expr_node ) {
    331334        return new AttrExpr( var, maybeMoveBuild< Expression >(expr_node) );
    332 }
    333 Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ) {
     335} // build_attrexpr
     336
     337Expression * build_attrtype( NameExpr * var, DeclarationNode * decl_node ) {
    334338        return new AttrExpr( var, maybeMoveBuildType( decl_node ) );
    335 }
    336 
    337 Expression *build_tuple( ExpressionNode * expr_node ) {
     339} // build_attrtype
     340
     341Expression * build_tuple( ExpressionNode * expr_node ) {
    338342        std::list< Expression * > exprs;
    339343        buildMoveList( expr_node, exprs );
    340344        return new UntypedTupleExpr( exprs );;
    341 }
    342 
    343 Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node ) {
     345} // build_tuple
     346
     347Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ) {
    344348        std::list< Expression * > args;
    345349        buildMoveList( expr_node, args );
    346350        return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr );
    347 }
    348 
    349 Expression *build_range( ExpressionNode * low, ExpressionNode *high ) {
     351} // build_func
     352
     353Expression * build_range( ExpressionNode * low, ExpressionNode * high ) {
    350354        return new RangeExpr( maybeMoveBuild< Expression >( low ), maybeMoveBuild< Expression >( high ) );
    351 }
    352 
    353 Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ) {
     355} // build_range
     356
     357Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr * constraint, ExpressionNode * operand ) {
    354358        return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) );
    355 }
    356 
    357 Expression *build_valexpr( StatementNode *s ) {
     359} // build_asmexpr
     360
     361Expression * build_valexpr( StatementNode * s ) {
    358362        return new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(s) ) );
    359 }
    360 Expression *build_typevalue( DeclarationNode *decl ) {
     363} // build_valexpr
     364
     365Expression * build_typevalue( DeclarationNode * decl ) {
    361366        return new TypeExpr( maybeMoveBuildType( decl ) );
    362 }
    363 
    364 Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ) {
     367} // build_typevalue
     368
     369Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids ) {
    365370        Declaration * newDecl = maybeBuild< Declaration >(decl_node); // compound literal type
    366371        if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type
     
    388393                assert( false );
    389394        } // if
    390 }
     395} // build_compoundLiteral
    391396
    392397// Local Variables: //
  • src/Parser/InitializerNode.cc

    r275f4b4 rcd7ef0b  
    1010// Created On       : Sat May 16 13:20:24 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Oct  1 23:09:51 2016
    13 // Update Count     : 21
     12// Last Modified On : Fri Jul 28 23:27:20 2017
     13// Update Count     : 26
    1414//
    1515
     
    2222#include "SynTree/Initializer.h"
    2323
    24 InitializerNode::InitializerNode( ExpressionNode *_expr, bool aggrp, ExpressionNode *des )
    25                 : expr( _expr ), aggregate( aggrp ), designator( des ), kids( 0 ), maybeConstructed( true ) {
     24InitializerNode::InitializerNode( ExpressionNode * _expr, bool aggrp, ExpressionNode * des )
     25                : expr( _expr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ) {
    2626        if ( aggrp )
    2727                kids = dynamic_cast< InitializerNode * >( get_next() );
    2828
    29         if ( kids != 0 )
    30                 set_last( 0 );
    31 }
     29        if ( kids )
     30                set_last( nullptr );
     31} // InitializerNode::InitializerNode
    3232
    33 InitializerNode::InitializerNode( InitializerNode *init, bool aggrp, ExpressionNode *des )
    34                 : expr( 0 ), aggregate( aggrp ), designator( des ), kids( 0 ), maybeConstructed( true ) {
    35         if ( init != 0 )
     33InitializerNode::InitializerNode( InitializerNode * init, bool aggrp, ExpressionNode * des )
     34                : expr( nullptr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ) {
     35        if ( init )
    3636                set_last( init );
    3737
     
    3939                kids = dynamic_cast< InitializerNode * >( get_next() );
    4040
    41         if ( kids != 0 )
    42                 set_next( 0 );
    43 }
     41        if ( kids )
     42                set_next( nullptr );
     43} // InitializerNode::InitializerNode
    4444
    4545InitializerNode::~InitializerNode() {
     
    4747        delete designator;
    4848        delete kids;
    49 }
     49} // InitializerNode::~InitializerNode
    5050
    5151void InitializerNode::print( std::ostream &os, int indent ) const {
    5252        os << std::string( indent, ' ' ) << "Initializer expression" << std::endl;
    53 }
     53} // InitializerNode::print
    5454
    5555void InitializerNode::printOneLine( std::ostream &os ) const {
    5656        if ( ! aggregate ) {
    57                 if ( designator != 0 ) {
     57                if ( designator ) {
    5858                        os << "designated by: (";
    5959                        ExpressionNode *curdes = designator;
    60                         while ( curdes != 0) {
     60                        while ( curdes != nullptr) {
    6161                                curdes->printOneLine(os);
    6262                                curdes = (ExpressionNode *)(curdes->get_next());
     
    6565                        os << ")";
    6666                } // if
    67                 if ( expr ) expr->printOneLine(os);
     67                if ( expr ) expr->printOneLine( os );
    6868        } else {  // It's an aggregate
    6969                os << "[--";
    70                 if ( next_init() != 0 )
    71                         next_init()->printOneLine(os);
     70                if ( next_init() != nullptr )
     71                        next_init()->printOneLine( os );
    7272                if (aggregate) os << "--]";
    7373        } // if
     
    7676        if ( (moreInit = dynamic_cast< InitializerNode * >( get_next() ) ) ) {
    7777                moreInit->printOneLine( os );
    78         }
    79 }
     78        } // if
     79} // InitializerNode::printOneLine
    8080
    81 Initializer *InitializerNode::build() const {
     81Initializer * InitializerNode::build() const {
    8282        if ( aggregate ) {
    8383                // steal designators from children
     
    9393                return new ListInit( initlist, designlist, maybeConstructed );
    9494        } else {
    95                 if ( get_expression() != 0) {
     95                if ( get_expression() ) {
    9696                        return new SingleInit( maybeBuild< Expression >( get_expression() ), maybeConstructed );
    97                 }
     97                } // if
    9898        } // if
    99         return 0;
    100 }
     99        return nullptr;
     100} // InitializerNode::build
    101101
    102102// Local Variables: //
  • src/Parser/ParseNode.h

    r275f4b4 rcd7ef0b  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:28:16 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jul 25 10:09:00 2017
    13 // Update Count     : 787
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Jul 27 12:08:08 2017
     13// Update Count     : 788
    1414//
    1515
     
    159159Expression * build_constantFloat( const std::string &str );
    160160Expression * build_constantChar( const std::string &str );
    161 Expression * build_constantZeroOne( const std::string &str );
    162161ConstantExpr * build_constantStr( const std::string &str );
    163162Expression * build_field_name_FLOATINGconstant( const std::string & str );
  • src/Parser/TypeData.cc

    r275f4b4 rcd7ef0b  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jul 18 10:10:00 2017
    13 // Update Count     : 566
     12// Last Modified On : Wed Aug  9 13:50:00 2017
     13// Update Count     : 567
    1414//
    1515
     
    748748} // buildAggInst
    749749
    750 NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, Type::StorageClasses scs ) {
     750NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage ) {
    751751        assert( td->kind == TypeData::Symbolic );
    752752        NamedTypeDecl * ret;
    753753        assert( td->base );
    754754        if ( td->symbolic.isTypedef ) {
    755                 ret = new TypedefDecl( name, scs, typebuild( td->base ) );
     755                ret = new TypedefDecl( name, scs, typebuild( td->base ), linkage );
    756756        } else {
    757757                ret = new TypeDecl( name, scs, typebuild( td->base ), TypeDecl::Any );
     
    817817                return buildEnum( td, attributes );
    818818        } else if ( td->kind == TypeData::Symbolic ) {
    819                 return buildSymbolic( td, name, scs );
     819                return buildSymbolic( td, name, scs, linkage );
    820820        } else {
    821821                return (new ObjectDecl( name, scs, linkage, bitfieldWidth, typebuild( td ), init, attributes ))->set_asmName( asmName );
  • src/Parser/lex.ll

    r275f4b4 rcd7ef0b  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Mon Jul 24 08:27:23 2017
    13  * Update Count     : 545
     12 * Last Modified On : Thu Jul 27 21:46:06 2017
     13 * Update Count     : 550
    1414 */
    1515
    1616%option yylineno
     17%option noyywrap
    1718%option nounput
    1819
     
    288289
    289290                                /* numeric constants */
    290 "0"                             { NUMERIC_RETURN(ZERO); }                               // CFA
    291 "1"                             { NUMERIC_RETURN(ONE); }                                // CFA
    292291{decimal_constant} { NUMERIC_RETURN(INTEGERconstant); }
    293292{octal_constant} { NUMERIC_RETURN(INTEGERconstant); }
     
    420419
    421420                                /* unknown characters */
    422 .                       { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }
     421.                               { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }
    423422
    424423%%
  • src/Parser/parser.yy

    r275f4b4 rcd7ef0b  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jul 25 10:07:00 2017
    13 // Update Count     : 2464
     12// Last Modified On : Wed Aug  4 13:33:00 2017
     13// Update Count     : 2475
    1414//
    1515
     
    142142// converted into the tuple index (.)(1). e.g., 3.x
    143143%token<tok>     REALDECIMALconstant     REALFRACTIONconstant    FLOATINGconstant
    144 %token<tok> ZERO                                ONE                                             // CFA
    145144
    146145// multi-character operators
     
    159158%token ATassign                                                                                 // @=
    160159
    161 %type<tok> identifier  no_attr_identifier  zero_one
     160%type<tok> identifier  no_attr_identifier
    162161%type<tok> identifier_or_type_name  no_attr_identifier_or_type_name  attr_name
    163162%type<constant> string_literal
     
    183182%type<en> asm_clobbers_list_opt
    184183%type<flag> asm_volatile_opt
     184%type<en> handler_predicate_opt
    185185
    186186// statements
     
    360360        ;
    361361
    362 zero_one:                                                                                               // CFA
    363         ZERO
    364         | ONE
    365         ;
    366 
    367362string_literal:
    368363        string_literal_list                                                     { $$ = build_constantStr( *$1 ); }
     
    384379        IDENTIFIER                                                                                      // typedef name cannot be used as a variable name
    385380                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    386         | zero_one
    387                 { $$ = new ExpressionNode( build_constantZeroOne( *$1 ) ); }
    388381        | tuple
    389382        | '(' comma_expression ')'
     
    485478                        $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) );
    486479                }
    487         | zero_one fraction_constants
    488                 {
    489                         $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantZeroOne( *$1 ), $2 ) );
    490                 }
    491480        ;
    492481
     
    539528        | ALIGNOF unary_expression                                                      // GCC, variable alignment
    540529                { $$ = new ExpressionNode( build_alignOfexpr( $2 ) ); }
    541         | ALIGNOF '(' type_no_function ')'                              // GCC, type alignment
     530        | ALIGNOF '(' type_no_function ')'                                      // GCC, type alignment
    542531                { $$ = new ExpressionNode( build_alignOftype( $3 ) ); }
    543532        | OFFSETOF '(' type_no_function ',' no_attr_identifier ')'
     
    980969
    981970handler_clause:
    982         // TEMPORARY, TEST EXCEPTIONS
    983         handler_key '(' push push INTEGERconstant pop ')' compound_statement pop
    984                 { $$ = new StatementNode( build_catch( $1, nullptr, new ExpressionNode( build_constantInteger( *$5 ) ), $8 ) ); }
    985         | handler_clause handler_key '(' push push INTEGERconstant pop ')' compound_statement pop
    986                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, nullptr, new ExpressionNode( build_constantInteger( *$6 ) ), $9 ) ) ); }
    987 
    988         | handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    989                 { $$ = new StatementNode( build_catch( $1, $5, nullptr, $9 ) ); }
     971        handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
     972                { $$ = new StatementNode( build_catch( $1, $5, $7, $9 ) ); }
    990973        | handler_clause handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    991                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, nullptr, $10 ) ) ); }
     974                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, $8, $10 ) ) ); }
    992975        ;
    993976
    994977handler_predicate_opt:
    995978        //empty
     979                { $$ = nullptr; }
    996980        | ';' conditional_expression
     981                { $$ = $2; }
    997982        ;
    998983
     
    16861671        | aggregate_key attribute_list_opt typegen_name         // CFA
    16871672                { $$ = $3->addQualifiers( $2 ); }
    1688 
    1689 // Temp, testing TreeStruct
    1690     | STRUCT TRY attribute_list_opt no_attr_identifier_or_type_name
    1691         {
    1692             typedefTable.makeTypedef( *$4 );            // create typedef
    1693             if ( forall ) typedefTable.changeKind( *$4, TypedefTable::TG ); // $
    1694             forall = false;                             // reset
    1695         }
    1696       '{' field_declaration_list '}'
    1697         {
    1698             $$ = DeclarationNode::newTreeStruct( DeclarationNode::Struct,
    1699                 $4, nullptr, nullptr, $7, true )->addQualifiers( $3 );
    1700         }
    1701     | STRUCT TRY attribute_list_opt no_attr_identifier_or_type_name TYPEDEFname
    1702         {
    1703             typedefTable.makeTypedef( *$4 );            // create typedef
    1704             if ( forall ) typedefTable.changeKind( *$4, TypedefTable::TG ); // $
    1705             forall = false;                             // reset
    1706         }
    1707       '{' field_declaration_list '}'
    1708         {
    1709             $$ = DeclarationNode::newTreeStruct( DeclarationNode::Struct,
    1710                 $4, $5, nullptr, $8, true )->addQualifiers( $3 );
    1711         }
    17121673        ;
    17131674
     
    19691930        | '=' initializer
    19701931                { $$ = $2; }
     1932        | '=' VOID
     1933                { $$ = nullptr; }
    19711934        | ATassign initializer
    19721935                { $$ = $2->set_maybeConstructed( false ); }
  • src/ResolvExpr/CurrentObject.cc

    r275f4b4 rcd7ef0b  
    3636                                return constExpr->get_constant()->get_ival();
    3737                        } else {
    38                                 assertf( false, "Non-integer constant expression in getConstValue", toString( constExpr ).c_str() ); // xxx - might be semantic error
     38                                assertf( false, "Non-integer constant expression in getConstValue %s", toString( constExpr ).c_str() ); // xxx - might be semantic error
    3939                        }
    4040                } else if ( dynamic_cast< OneType * >( constExpr->get_result() ) ) {
     
    176176                                setPosition( castExpr->get_arg() );
    177177                        } else if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( expr ) ) {
    178                                 assertf( dynamic_cast<EnumInstType *> ( varExpr->get_result() ), "ArrayIterator given variable that isn't an enum constant", toString( expr ).c_str() );
     178                                assertf( dynamic_cast<EnumInstType *> ( varExpr->get_result() ), "ArrayIterator given variable that isn't an enum constant : %s", toString( expr ).c_str() );
    179179                                index = 0; // xxx - get actual value of enum constant
    180180                        } else if ( dynamic_cast< SizeofExpr * >( expr ) || dynamic_cast< AlignofExpr * >( expr ) ) {
     
    518518                        curTypes = newTypes;
    519519                        newTypes.clear();
    520                         assertf( desigAlts.size() == curTypes.size(), "Designator alternatives (%d) and current types (%d) out of sync", desigAlts.size(), curTypes.size() );
     520                        assertf( desigAlts.size() == curTypes.size(), "Designator alternatives (%zu) and current types (%zu) out of sync", desigAlts.size(), curTypes.size() );
    521521                } // for
    522522                if ( desigAlts.size() > 1 ) {
  • src/ResolvExpr/Resolver.cc

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 12:17:01 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 23 17:23:14 2017
    13 // Update Count     : 211
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tus Aug  8 16:06:00 2017
     13// Update Count     : 212
    1414//
    1515
     
    7171                virtual void visit( ReturnStmt *returnStmt ) override;
    7272                virtual void visit( ThrowStmt *throwStmt ) override;
     73                virtual void visit( CatchStmt *catchStmt ) override;
    7374
    7475                virtual void visit( SingleInit *singleInit ) override;
     
    368369
    369370        void Resolver::visit( ThrowStmt *throwStmt ) {
     371                // TODO: Replace *exception type with &exception type.
    370372                if ( throwStmt->get_expr() ) {
    371                         Expression * wrapped = new CastExpr( throwStmt->get_expr(), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
     373                        StructDecl * exception_decl =
     374                                lookupStruct( "__cfaehm__base_exception_t" );
     375                        assert( exception_decl );
     376                        Expression * wrapped = new CastExpr(
     377                                throwStmt->get_expr(),
     378                                new PointerType(
     379                                        noQualifiers,
     380                                        new StructInstType(
     381                                                noQualifiers,
     382                                                exception_decl
     383                                                )
     384                                        )
     385                                );
    372386                        Expression * newExpr = findSingleExpression( wrapped, *this );
    373387                        throwStmt->set_expr( newExpr );
     388                }
     389        }
     390
     391        void Resolver::visit( CatchStmt *catchStmt ) {
     392                if ( catchStmt->get_cond() ) {
     393                        Expression * wrapped = new CastExpr(
     394                                catchStmt->get_cond(),
     395                                new BasicType( noQualifiers, BasicType::Bool )
     396                                );
     397                        catchStmt->set_cond( findSingleExpression( wrapped, *this ) );
    374398                }
    375399        }
  • src/SymTab/Validate.cc

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:50:04 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 30 16:50:13 2017
    13 // Update Count     : 357
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tus Aug  8 13:27:00 2017
     13// Update Count     : 358
    1414//
    1515
     
    686686                Type *designatorType = tyDecl->get_base()->stripDeclarator();
    687687                if ( StructInstType *aggDecl = dynamic_cast< StructInstType * >( designatorType ) ) {
    688                         return new StructDecl( aggDecl->get_name() );
     688                        return new StructDecl( aggDecl->get_name(), DeclarationNode::Struct, noAttributes, tyDecl->get_linkage() );
    689689                } else if ( UnionInstType *aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) {
    690                         return new UnionDecl( aggDecl->get_name() );
     690                        return new UnionDecl( aggDecl->get_name(), noAttributes, tyDecl->get_linkage() );
    691691                } else if ( EnumInstType *enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) {
    692                         return new EnumDecl( enumDecl->get_name() );
     692                        return new EnumDecl( enumDecl->get_name(), noAttributes, tyDecl->get_linkage() );
    693693                } else {
    694694                        return ret->clone();
     
    783783                                type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() );
    784784                        } // if
    785                         TypedefDeclPtr tyDecl( new TypedefDecl( aggDecl->get_name(), Type::StorageClasses(), type ) );
     785                        TypedefDeclPtr tyDecl( new TypedefDecl( aggDecl->get_name(), Type::StorageClasses(), type, aggDecl->get_linkage() ) );
    786786                        typedefNames[ aggDecl->get_name() ] = std::make_pair( std::move( tyDecl ), scopeLevel );
    787787                } // if
     
    903903                FunctionType * ftype = functionDecl->get_functionType();
    904904                std::list< DeclarationWithType * > & retVals = ftype->get_returnVals();
    905                 assertf( retVals.size() == 0 || retVals.size() == 1, "Function %s has too many return values: %d", functionDecl->get_name().c_str(), retVals.size() );
     905                assertf( retVals.size() == 0 || retVals.size() == 1, "Function %s has too many return values: %zu", functionDecl->get_name().c_str(), retVals.size() );
    906906                if ( retVals.size() == 1 ) {
    907907                        // ensure all function return values have a name - use the name of the function to disambiguate (this also provides a nice bit of help for debugging).
  • src/SynTree/AggregateDecl.cc

    r275f4b4 rcd7ef0b  
    1010// Created On       : Sun May 17 23:56:39 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jun 27 15:30:00 2017
    13 // Update Count     : 21
     12// Last Modified On : Fri Aug  4 14:22:00 2017
     13// Update Count     : 22
    1414//
    1515
     
    4040        using std::endl;
    4141
    42         os << typeString() << " " << get_name();
    43         os << string( indent+2, ' ' ) << "with body " << has_body() << endl;
     42        os << typeString() << " " << get_name() << ":";
     43        if ( get_linkage() != LinkageSpec::Cforall ) {
     44                os << " " << LinkageSpec::linkageName( get_linkage() );
     45        } // if
     46        os << " with body " << has_body() << endl;
    4447
    4548        if ( ! parameters.empty() ) {
  • src/SynTree/Declaration.cc

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 07:49:18 2017
    13 // Update Count     : 24
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug  9 14:38:00 2017
     13// Update Count     : 25
    1414//
    1515
     
    2828
    2929Declaration::Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage )
    30                 : name( name ), storageClasses( scs ), linkage( linkage ), uniqueId( 0 ) {
     30                : name( name ), linkage( linkage ), storageClasses( scs ), uniqueId( 0 ) {
    3131}
    3232
    3333Declaration::Declaration( const Declaration &other )
    34         : BaseSyntaxNode( other ), name( other.name ), storageClasses( other.storageClasses ), linkage( other.linkage ), uniqueId( other.uniqueId ) {
     34        : BaseSyntaxNode( other ), name( other.name ), linkage( other.linkage ), extension( other.extension ), storageClasses( other.storageClasses ), uniqueId( other.uniqueId ) {
    3535}
    3636
  • src/SynTree/Declaration.h

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:52:59 2017
    13 // Update Count     : 124
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug  9 14:45:00 2017
     13// Update Count     : 126
    1414//
    1515
     
    2727class Declaration : public BaseSyntaxNode {
    2828  public:
     29        std::string name;
     30        LinkageSpec::Spec linkage;
     31        bool extension = false;
     32
    2933        Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage );
    3034        Declaration( const Declaration &other );
     
    5357        static void dumpIds( std::ostream &os );
    5458        static Declaration *declFromId( UniqueId id );
    55   private:
    56         std::string name;
     59
     60  private:
    5761        Type::StorageClasses storageClasses;
    58         LinkageSpec::Spec linkage;
    5962        UniqueId uniqueId;
    60         bool extension = false;
    6163};
    6264
    6365class DeclarationWithType : public Declaration {
    6466  public:
    65         DeclarationWithType( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs );
    66         DeclarationWithType( const DeclarationWithType &other );
    67         virtual ~DeclarationWithType();
    68 
    69         std::string get_mangleName() const { return mangleName; }
    70         DeclarationWithType * set_mangleName( std::string newValue ) { mangleName = newValue; return this; }
    71 
    72         std::string get_scopedMangleName() const { return mangleName + "_" + std::to_string(scopeLevel); }
    73 
    74         int get_scopeLevel() const { return scopeLevel; }
    75         DeclarationWithType * set_scopeLevel( int newValue ) { scopeLevel = newValue; return this; }
    76 
    77         ConstantExpr *get_asmName() const { return asmName; }
    78         DeclarationWithType * set_asmName( ConstantExpr *newValue ) { asmName = newValue; return this; }
    79 
    80         std::list< Attribute * >& get_attributes() { return attributes; }
    81         const std::list< Attribute * >& get_attributes() const { return attributes; }
    82 
    83         Type::FuncSpecifiers get_funcSpec() const { return fs; }
    84         //void set_functionSpecifiers( Type::FuncSpecifiers newValue ) { fs = newValue; }
    85 
    86         virtual DeclarationWithType *clone() const = 0;
    87         virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
    88 
    89         virtual Type *get_type() const = 0;
    90         virtual void set_type(Type *) = 0;
    91   private:
    9267        // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2
    9368        std::string mangleName;
     
    9772        ConstantExpr *asmName;
    9873        std::list< Attribute * > attributes;
     74
     75        DeclarationWithType( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs );
     76        DeclarationWithType( const DeclarationWithType &other );
     77        virtual ~DeclarationWithType();
     78
     79        std::string get_mangleName() const { return mangleName; }
     80        DeclarationWithType * set_mangleName( std::string newValue ) { mangleName = newValue; return this; }
     81
     82        std::string get_scopedMangleName() const { return mangleName + "_" + std::to_string(scopeLevel); }
     83
     84        int get_scopeLevel() const { return scopeLevel; }
     85        DeclarationWithType * set_scopeLevel( int newValue ) { scopeLevel = newValue; return this; }
     86
     87        ConstantExpr *get_asmName() const { return asmName; }
     88        DeclarationWithType * set_asmName( ConstantExpr *newValue ) { asmName = newValue; return this; }
     89
     90        std::list< Attribute * >& get_attributes() { return attributes; }
     91        const std::list< Attribute * >& get_attributes() const { return attributes; }
     92
     93        Type::FuncSpecifiers get_funcSpec() const { return fs; }
     94        //void set_functionSpecifiers( Type::FuncSpecifiers newValue ) { fs = newValue; }
     95
     96        virtual DeclarationWithType *clone() const = 0;
     97        virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
     98
     99        virtual Type *get_type() const = 0;
     100        virtual void set_type(Type *) = 0;
     101
     102  private:
    99103        Type::FuncSpecifiers fs;
    100104};
     
    103107        typedef DeclarationWithType Parent;
    104108  public:
     109        Type *type;
     110        Initializer *init;
     111        Expression *bitfieldWidth;
     112
    105113        ObjectDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Expression *bitfieldWidth, Type *type, Initializer *init,
    106114                                const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() );
     
    122130        virtual void print( std::ostream &os, int indent = 0 ) const;
    123131        virtual void printShort( std::ostream &os, int indent = 0 ) const;
    124   private:
    125         Type *type;
    126         Initializer *init;
    127         Expression *bitfieldWidth;
    128132};
    129133
     
    131135        typedef DeclarationWithType Parent;
    132136  public:
     137        FunctionType *type;
     138        CompoundStmt *statements;
     139
    133140        FunctionDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements,
    134141                                  const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() );
     
    149156        virtual void print( std::ostream &os, int indent = 0 ) const;
    150157        virtual void printShort( std::ostream &os, int indent = 0 ) const;
    151   private:
    152         FunctionType *type;
    153         CompoundStmt *statements;
    154158};
    155159
     
    157161        typedef Declaration Parent;
    158162  public:
     163        Type *base;
     164        std::list< TypeDecl* > parameters;
     165        std::list< DeclarationWithType* > assertions;
     166
    159167        NamedTypeDecl( const std::string &name, Type::StorageClasses scs, Type *type );
    160168        NamedTypeDecl( const NamedTypeDecl &other );
     
    171179        virtual void print( std::ostream &os, int indent = 0 ) const;
    172180        virtual void printShort( std::ostream &os, int indent = 0 ) const;
    173   protected:
    174   private:
    175         Type *base;
    176         std::list< TypeDecl* > parameters;
    177         std::list< DeclarationWithType* > assertions;
    178181};
    179182
     
    182185  public:
    183186        enum Kind { Any, Dtype, Ftype, Ttype };
     187
     188        Type * init;
     189        bool sized;
     190
    184191        /// Data extracted from a type decl
    185192        struct Data {
     
    216223  private:
    217224        Kind kind;
    218         Type * init;
    219         bool sized;
    220225};
    221226
     
    223228        typedef NamedTypeDecl Parent;
    224229  public:
    225         TypedefDecl( const std::string &name, Type::StorageClasses scs, Type *type ) : Parent( name, scs, type ) {}
     230        TypedefDecl( const std::string &name, Type::StorageClasses scs, Type *type, LinkageSpec::Spec spec = LinkageSpec::Cforall ) : Parent( name, scs, type ) { set_linkage( spec ); }
    226231        TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
    227232
     
    237242        typedef Declaration Parent;
    238243  public:
    239         AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall );
    240         AggregateDecl( const AggregateDecl &other );
    241         virtual ~AggregateDecl();
    242 
    243         std::list<Declaration*>& get_members() { return members; }
    244         std::list<TypeDecl*>& get_parameters() { return parameters; }
    245 
    246         std::list< Attribute * >& get_attributes() { return attributes; }
    247         const std::list< Attribute * >& get_attributes() const { return attributes; }
    248 
    249         bool has_body() const { return body; }
    250         AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
    251 
    252         virtual void print( std::ostream &os, int indent = 0 ) const;
    253         virtual void printShort( std::ostream &os, int indent = 0 ) const;
    254   protected:
    255         virtual std::string typeString() const = 0;
    256 
    257   private:
    258244        std::list<Declaration*> members;
    259245        std::list<TypeDecl*> parameters;
    260246        bool body;
    261247        std::list< Attribute * > attributes;
     248
     249        AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall );
     250        AggregateDecl( const AggregateDecl &other );
     251        virtual ~AggregateDecl();
     252
     253        std::list<Declaration*>& get_members() { return members; }
     254        std::list<TypeDecl*>& get_parameters() { return parameters; }
     255
     256        std::list< Attribute * >& get_attributes() { return attributes; }
     257        const std::list< Attribute * >& get_attributes() const { return attributes; }
     258
     259        bool has_body() const { return body; }
     260        AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
     261
     262        virtual void print( std::ostream &os, int indent = 0 ) const;
     263        virtual void printShort( std::ostream &os, int indent = 0 ) const;
     264  protected:
     265        virtual std::string typeString() const = 0;
    262266};
    263267
     
    333337class AsmDecl : public Declaration {
    334338  public:
     339        AsmStmt *stmt;
     340
    335341        AsmDecl( AsmStmt *stmt );
    336342        AsmDecl( const AsmDecl &other );
     
    345351        virtual void print( std::ostream &os, int indent = 0 ) const;
    346352        virtual void printShort( std::ostream &os, int indent = 0 ) const;
    347   private:
    348         AsmStmt *stmt;
    349353};
    350354
  • src/SynTree/Expression.h

    r275f4b4 rcd7ef0b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Jul 24 16:27:00 2017
    13 // Update Count     : 43
     12// Last Modified On : Fri Aug  8 11:54:00 2017
     13// Update Count     : 44
    1414//
    1515
     
    2929class Expression : public BaseSyntaxNode{
    3030  public:
     31        Type * result;
     32        TypeSubstitution * env;
     33        Expression * argName; // if expression is used as an argument, it can be "designated" by this name
     34        bool extension = false;
     35
    3136        Expression( Expression * _aname = nullptr );
    3237        Expression( const Expression & other );
     
    4954        virtual Expression * acceptMutator( Mutator & m ) = 0;
    5055        virtual void print( std::ostream & os, int indent = 0 ) const;
    51   protected:
    52         Type * result;
    53         TypeSubstitution * env;
    54         Expression * argName; // if expression is used as an argument, it can be "designated" by this name
    55         bool extension = false;
    5656};
    5757
     
    7979class ApplicationExpr : public Expression {
    8080  public:
     81        Expression * function;
     82
    8183        ApplicationExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() );
    8284        ApplicationExpr( const ApplicationExpr & other );
     
    9294        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    9395        virtual void print( std::ostream & os, int indent = 0 ) const;
     96
    9497  private:
    95         Expression * function;
    9698        std::list<Expression *> args;
    9799        InferredParams inferParams;
     
    103105class UntypedExpr : public Expression {
    104106  public:
     107        Expression * function;
     108        std::list<Expression*> args;
     109
    105110        UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >(), Expression *_aname = nullptr );
    106111        UntypedExpr( const UntypedExpr & other );
     
    123128        virtual void print( std::ostream & os, int indent = 0 ) const;
    124129        virtual void printArgs(std::ostream & os, int indent = 0) const;
    125   private:
    126         Expression * function;
    127         std::list<Expression*> args;
    128130};
    129131
     
    131133class NameExpr : public Expression {
    132134  public:
     135        std::string name;
     136
    133137        NameExpr( std::string name, Expression *_aname = nullptr );
    134138        NameExpr( const NameExpr & other );
     
    142146        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    143147        virtual void print( std::ostream & os, int indent = 0 ) const;
    144   private:
    145         std::string name;
    146148};
    147149
     
    152154class AddressExpr : public Expression {
    153155  public:
     156        Expression * arg;
     157
    154158        AddressExpr( Expression * arg, Expression *_aname = nullptr );
    155159        AddressExpr( const AddressExpr & other );
     
    163167        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    164168        virtual void print( std::ostream & os, int indent = 0 ) const;
    165   private:
    166         Expression * arg;
    167169};
    168170
     
    170172class LabelAddressExpr : public Expression {
    171173  public:
     174        Expression * arg;
     175
    172176        LabelAddressExpr( Expression * arg );
    173177        LabelAddressExpr( const LabelAddressExpr & other );
     
    181185        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    182186        virtual void print( std::ostream & os, int indent = 0 ) const;
    183   private:
    184         Expression * arg;
    185187};
    186188
     
    188190class CastExpr : public Expression {
    189191  public:
     192        Expression * arg;
     193
    190194        CastExpr( Expression * arg, Expression *_aname = nullptr );
    191195        CastExpr( Expression * arg, Type * toType, Expression *_aname = nullptr );
     
    200204        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    201205        virtual void print( std::ostream & os, int indent = 0 ) const;
    202   private:
    203         Expression * arg;
    204206};
    205207
     
    207209class VirtualCastExpr : public Expression {
    208210  public:
     211        Expression * arg;
     212
    209213        VirtualCastExpr( Expression * arg, Type * toType );
    210214        VirtualCastExpr( const VirtualCastExpr & other );
     
    218222        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    219223        virtual void print( std::ostream & os, int indent = 0 ) const;
    220   private:
    221         Expression * arg;
    222224};
    223225
     
    225227class UntypedMemberExpr : public Expression {
    226228  public:
     229        Expression * member;
     230        Expression * aggregate;
     231
    227232        UntypedMemberExpr( Expression * member, Expression * aggregate, Expression *_aname = nullptr );
    228233        UntypedMemberExpr( const UntypedMemberExpr & other );
     
    238243        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    239244        virtual void print( std::ostream & os, int indent = 0 ) const;
    240   private:
    241         Expression * member;
    242         Expression * aggregate;
    243245};
    244246
     
    247249class MemberExpr : public Expression {
    248250  public:
     251        DeclarationWithType * member;
     252        Expression * aggregate;
     253
    249254        MemberExpr( DeclarationWithType * member, Expression * aggregate, Expression *_aname = nullptr );
    250255        MemberExpr( const MemberExpr & other );
     
    260265        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    261266        virtual void print( std::ostream & os, int indent = 0 ) const;
    262   private:
    263         DeclarationWithType * member;
    264         Expression * aggregate;
    265267};
    266268
     
    269271class VariableExpr : public Expression {
    270272  public:
     273        DeclarationWithType * var;
     274
    271275        VariableExpr( DeclarationWithType * var, Expression *_aname = nullptr );
    272276        VariableExpr( const VariableExpr & other );
     
    280284        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    281285        virtual void print( std::ostream & os, int indent = 0 ) const;
    282   private:
    283         DeclarationWithType * var;
    284286};
    285287
     
    287289class ConstantExpr : public Expression {
    288290  public:
     291        Constant constant;
     292
    289293        ConstantExpr( Constant constant, Expression *_aname = nullptr );
    290294        ConstantExpr( const ConstantExpr & other );
     
    298302        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    299303        virtual void print( std::ostream & os, int indent = 0 ) const;
    300   private:
    301         Constant constant;
    302304};
    303305
     
    305307class SizeofExpr : public Expression {
    306308  public:
     309        Expression * expr;
     310        Type * type;
     311        bool isType;
     312
    307313        SizeofExpr( Expression * expr, Expression *_aname = nullptr );
    308314        SizeofExpr( const SizeofExpr & other );
     
    321327        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    322328        virtual void print( std::ostream & os, int indent = 0 ) const;
    323   private:
     329};
     330
     331/// AlignofExpr represents an alignof expression
     332class AlignofExpr : public Expression {
     333  public:
    324334        Expression * expr;
    325335        Type * type;
    326336        bool isType;
    327 };
    328 
    329 /// AlignofExpr represents an alignof expression
    330 class AlignofExpr : public Expression {
    331   public:
     337
    332338        AlignofExpr( Expression * expr, Expression *_aname = nullptr );
    333339        AlignofExpr( const AlignofExpr & other );
     
    346352        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    347353        virtual void print( std::ostream & os, int indent = 0 ) const;
    348   private:
    349         Expression * expr;
    350         Type * type;
    351         bool isType;
    352354};
    353355
     
    355357class UntypedOffsetofExpr : public Expression {
    356358  public:
     359        Type * type;
     360        std::string member;
     361
    357362        UntypedOffsetofExpr( Type * type, const std::string & member, Expression *_aname = nullptr );
    358363        UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
     
    368373        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    369374        virtual void print( std::ostream & os, int indent = 0 ) const;
    370   private:
    371         Type * type;
    372         std::string member;
    373375};
    374376
     
    376378class OffsetofExpr : public Expression {
    377379  public:
     380        Type * type;
     381        DeclarationWithType * member;
     382
    378383        OffsetofExpr( Type * type, DeclarationWithType * member, Expression *_aname = nullptr );
    379384        OffsetofExpr( const OffsetofExpr & other );
     
    389394        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    390395        virtual void print( std::ostream & os, int indent = 0 ) const;
    391   private:
    392         Type * type;
    393         DeclarationWithType * member;
    394396};
    395397
     
    397399class OffsetPackExpr : public Expression {
    398400public:
     401        StructInstType * type;
     402
    399403        OffsetPackExpr( StructInstType * type_, Expression * aname_ = 0 );
    400404        OffsetPackExpr( const OffsetPackExpr & other );
     
    407411        virtual void accept( Visitor & v ) { v.visit( this ); }
    408412        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    409 
    410         virtual void print( std::ostream & os, int indent = 0 ) const;
    411 
    412 private:
    413         StructInstType * type;
     413        virtual void print( std::ostream & os, int indent = 0 ) const;
    414414};
    415415
     
    417417class AttrExpr : public Expression {
    418418  public:
     419        Expression * attr;
     420        Expression * expr;
     421        Type * type;
     422        bool isType;
     423
    419424        AttrExpr(Expression * attr, Expression * expr, Expression *_aname = nullptr );
    420425        AttrExpr( const AttrExpr & other );
     
    435440        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    436441        virtual void print( std::ostream & os, int indent = 0 ) const;
    437   private:
    438         Expression * attr;
    439         Expression * expr;
    440         Type * type;
    441         bool isType;
    442442};
    443443
     
    445445class LogicalExpr : public Expression {
    446446  public:
     447        Expression * arg1;
     448        Expression * arg2;
     449
    447450        LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true, Expression *_aname = nullptr );
    448451        LogicalExpr( const LogicalExpr & other );
     
    459462        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    460463        virtual void print( std::ostream & os, int indent = 0 ) const;
     464
    461465  private:
     466        bool isAnd;
     467};
     468
     469/// ConditionalExpr represents the three-argument conditional ( p ? a : b )
     470class ConditionalExpr : public Expression {
     471  public:
    462472        Expression * arg1;
    463473        Expression * arg2;
    464         bool isAnd;
    465 };
    466 
    467 /// ConditionalExpr represents the three-argument conditional ( p ? a : b )
    468 class ConditionalExpr : public Expression {
    469   public:
     474        Expression * arg3;
     475
    470476        ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3, Expression *_aname = nullptr );
    471477        ConditionalExpr( const ConditionalExpr & other );
     
    483489        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    484490        virtual void print( std::ostream & os, int indent = 0 ) const;
    485   private:
     491};
     492
     493/// CommaExpr represents the sequence operator ( a, b )
     494class CommaExpr : public Expression {
     495  public:
    486496        Expression * arg1;
    487497        Expression * arg2;
    488         Expression * arg3;
    489 };
    490 
    491 /// CommaExpr represents the sequence operator ( a, b )
    492 class CommaExpr : public Expression {
    493   public:
     498
    494499        CommaExpr( Expression * arg1, Expression * arg2, Expression *_aname = nullptr );
    495500        CommaExpr( const CommaExpr & other );
     
    505510        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    506511        virtual void print( std::ostream & os, int indent = 0 ) const;
    507   private:
    508         Expression * arg1;
    509         Expression * arg2;
    510512};
    511513
     
    513515class TypeExpr : public Expression {
    514516  public:
     517        Type * type;
     518
    515519        TypeExpr( Type * type );
    516520        TypeExpr( const TypeExpr & other );
     
    524528        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    525529        virtual void print( std::ostream & os, int indent = 0 ) const;
    526   private:
    527         Type * type;
    528530};
    529531
     
    531533class AsmExpr : public Expression {
    532534  public:
     535        Expression * inout;
     536        ConstantExpr * constraint;
     537        Expression * operand;
     538
    533539        AsmExpr( Expression * inout, ConstantExpr * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
    534540        AsmExpr( const AsmExpr & other );
     
    548554        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    549555        virtual void print( std::ostream & os, int indent = 0 ) const;
    550   private:
     556
    551557        // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
    552         Expression * inout;
    553         ConstantExpr * constraint;
    554         Expression * operand;
    555558};
    556559
     
    559562class ImplicitCopyCtorExpr : public Expression {
    560563public:
    561         ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
    562         ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
    563         virtual ~ImplicitCopyCtorExpr();
    564 
    565         ApplicationExpr * get_callExpr() const { return callExpr; }
    566         void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
    567 
    568         std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
    569         std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
    570         std::list< Expression * > & get_dtors() { return dtors; }
    571 
    572         virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
    573         virtual void accept( Visitor & v ) { v.visit( this ); }
    574         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    575         virtual void print( std::ostream & os, int indent = 0 ) const;
    576   private:
    577564        ApplicationExpr * callExpr;
    578565        std::list< ObjectDecl * > tempDecls;
    579566        std::list< ObjectDecl * > returnDecls;
    580567        std::list< Expression * > dtors;
     568
     569        ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
     570        ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
     571        virtual ~ImplicitCopyCtorExpr();
     572
     573        ApplicationExpr * get_callExpr() const { return callExpr; }
     574        void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
     575
     576        std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
     577        std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
     578        std::list< Expression * > & get_dtors() { return dtors; }
     579
     580        virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
     581        virtual void accept( Visitor & v ) { v.visit( this ); }
     582        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
     583        virtual void print( std::ostream & os, int indent = 0 ) const;
    581584};
    582585
     
    584587class ConstructorExpr : public Expression {
    585588public:
     589        Expression * callExpr;
     590
    586591        ConstructorExpr( Expression * callExpr );
    587592        ConstructorExpr( const ConstructorExpr & other );
     
    595600        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    596601        virtual void print( std::ostream & os, int indent = 0 ) const;
    597 private:
    598         Expression * callExpr;
    599602};
    600603
     
    602605class CompoundLiteralExpr : public Expression {
    603606  public:
     607        Initializer * initializer;
     608
    604609        CompoundLiteralExpr( Type * type, Initializer * initializer );
    605610        CompoundLiteralExpr( const CompoundLiteralExpr & other );
     
    613618        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    614619        virtual void print( std::ostream & os, int indent = 0 ) const;
    615   private:
    616         Initializer * initializer;
    617620};
    618621
     
    620623class RangeExpr : public Expression {
    621624  public:
     625        Expression * low, * high;
     626
    622627        RangeExpr( Expression * low, Expression * high );
    623628        RangeExpr( const RangeExpr & other );
     
    632637        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    633638        virtual void print( std::ostream & os, int indent = 0 ) const;
    634   private:
    635         Expression * low, * high;
    636639};
    637640
     
    639642class UntypedTupleExpr : public Expression {
    640643  public:
     644        std::list<Expression*> exprs;
     645
    641646        UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
    642647        UntypedTupleExpr( const UntypedTupleExpr & other );
     
    649654        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    650655        virtual void print( std::ostream & os, int indent = 0 ) const;
    651   private:
    652         std::list<Expression*> exprs;
    653656};
    654657
     
    656659class TupleExpr : public Expression {
    657660  public:
     661        std::list<Expression*> exprs;
     662
    658663        TupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
    659664        TupleExpr( const TupleExpr & other );
     
    666671        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    667672        virtual void print( std::ostream & os, int indent = 0 ) const;
    668   private:
    669         std::list<Expression*> exprs;
    670673};
    671674
     
    673676class TupleIndexExpr : public Expression {
    674677  public:
     678        Expression * tuple;
     679        unsigned int index;
     680
    675681        TupleIndexExpr( Expression * tuple, unsigned int index );
    676682        TupleIndexExpr( const TupleIndexExpr & other );
     
    686692        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    687693        virtual void print( std::ostream & os, int indent = 0 ) const;
    688   private:
    689         Expression * tuple;
    690         unsigned int index;
    691694};
    692695
     
    694697class TupleAssignExpr : public Expression {
    695698  public:
     699        StmtExpr * stmtExpr = nullptr;
     700
    696701        TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr );
    697702        TupleAssignExpr( const TupleAssignExpr & other );
     
    705710        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    706711        virtual void print( std::ostream & os, int indent = 0 ) const;
    707   private:
    708         StmtExpr * stmtExpr = nullptr;
    709712};
    710713
     
    712715class StmtExpr : public Expression {
    713716public:
     717        CompoundStmt * statements;
     718        std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
     719        std::list< Expression * > dtors; // destructor(s) for return variable(s)
     720
    714721        StmtExpr( CompoundStmt * statements );
    715722        StmtExpr( const StmtExpr & other );
     
    726733        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    727734        virtual void print( std::ostream & os, int indent = 0 ) const;
    728 private:
    729         CompoundStmt * statements;
    730         std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
    731         std::list< Expression * > dtors; // destructor(s) for return variable(s)
    732735};
    733736
    734737class UniqueExpr : public Expression {
    735738public:
     739        Expression * expr;
     740        ObjectDecl * object;
     741        VariableExpr * var;
     742
    736743        UniqueExpr( Expression * expr, long long idVal = -1 );
    737744        UniqueExpr( const UniqueExpr & other );
     
    753760        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    754761        virtual void print( std::ostream & os, int indent = 0 ) const;
     762
    755763private:
    756         Expression * expr;
    757         ObjectDecl * object;
    758         VariableExpr * var;
    759764        int id;
    760765        static long long count;
     
    773778class UntypedInitExpr : public Expression {
    774779public:
     780        Expression * expr;
     781        std::list<InitAlternative> initAlts;
     782
    775783        UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts );
    776784        UntypedInitExpr( const UntypedInitExpr & other );
     
    786794        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    787795        virtual void print( std::ostream & os, int indent = 0 ) const;
    788 private:
    789         Expression * expr;
    790         std::list<InitAlternative> initAlts;
    791796};
    792797
    793798class InitExpr : public Expression {
    794799public:
     800        Expression * expr;
     801        Designation * designation;
     802
    795803        InitExpr( Expression * expr, Designation * designation );
    796804        InitExpr( const InitExpr & other );
     
    807815        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    808816        virtual void print( std::ostream & os, int indent = 0 ) const;
    809 private:
    810         Expression * expr;
    811         Designation * designation;
    812817};
    813818
  • src/SynTree/Initializer.cc

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri May 13 13:23:03 2016
    13 // Update Count     : 28
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Aug  3 11:33:00 2016
     13// Update Count     : 29
    1414//
    1515
     
    7474                        }
    7575                }
    76                 assertf( initializers.size() == designations.size(), "Created ListInit with mismatching initializers (%d) and designations (%d)", initializers.size(), designations.size() );
     76                assertf( initializers.size() == designations.size(), "Created ListInit with mismatching initializers (%lu) and designations (%lu)", initializers.size(), designations.size() );
    7777}
    7878
  • src/SynTree/Initializer.h

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:52:02 2017
    13 // Update Count     : 21
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug  9 10:19:00 2017
     13// Update Count     : 22
    1414//
    1515
     
    2727class Designation : public BaseSyntaxNode {
    2828public:
     29        std::list< Expression * > designators;
     30
    2931        Designation( const std::list< Expression * > & designators );
    3032        Designation( const Designation & other );
     
    3739        virtual Designation * acceptMutator( Mutator &m ) { return m.mutate( this ); }
    3840        virtual void print( std::ostream &os, int indent = 0 ) const;
    39 private:
    40         std::list< Expression * > designators;
    4141};
    4242
     
    6363class SingleInit : public Initializer {
    6464  public:
     65        //Constant *value;
     66        Expression *value;      // has to be a compile-time constant
     67
    6568        SingleInit( Expression *value, bool maybeConstructed = false );
    6669        SingleInit( const SingleInit &other );
     
    7477        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    7578        virtual void print( std::ostream &os, int indent = 0 ) const;
    76   private:
    77         //Constant *value;
    78         Expression *value;      // has to be a compile-time constant
    7979};
    8080
     
    8383class ListInit : public Initializer {
    8484  public:
     85        std::list<Initializer *> initializers;  // order *is* important
     86        std::list<Designation *> designations;  // order/length is consistent with initializers
     87
    8588        ListInit( const std::list<Initializer*> &initializers,
    8689                          const std::list<Designation *> &designators = {}, bool maybeConstructed = false );
     
    102105        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    103106        virtual void print( std::ostream &os, int indent = 0 ) const;
    104   private:
    105         std::list<Initializer *> initializers;  // order *is* important
    106         std::list<Designation *> designations;  // order/length is consistent with initializers
    107107};
    108108
     
    113113class ConstructorInit : public Initializer {
    114114  public:
     115        Statement * ctor;
     116        Statement * dtor;
     117
    115118        ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init );
    116119        ConstructorInit( const ConstructorInit &other );
     
    130133
    131134  private:
    132         Statement * ctor;
    133         Statement * dtor;
    134135        // C-style initializer made up of SingleInit and ListInit nodes to use as a fallback
    135136        // if an appropriate constructor definition is not found by the resolver
  • src/SynTree/NamedTypeDecl.cc

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 07:49:44 2017
    13 // Update Count     : 13
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug  9 13:28:00 2017
     13// Update Count     : 14
    1414//
    1515
     
    3838        if ( get_name() != "" ) {
    3939                os << get_name() << ": ";
     40        } // if
     41        if ( get_linkage() != LinkageSpec::Cforall ) {
     42                os << LinkageSpec::linkageName( get_linkage() ) << " ";
    4043        } // if
    4144        get_storageClasses().print( os );
  • src/SynTree/Statement.h

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:54:32 2017
    13 // Update Count     : 68
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Aug  3 14:08:00 2017
     13// Update Count     : 69
    1414//
    1515
     
    2626class Statement : public BaseSyntaxNode {
    2727  public:
     28        std::list<Label> labels;
     29
    2830        Statement( std::list<Label> labels );
    2931        virtual ~Statement();
     
    3638        virtual Statement *acceptMutator( Mutator &m ) = 0;
    3739        virtual void print( std::ostream &os, int indent = 0 ) const;
    38   protected:
    39         std::list<Label> labels;
    4040};
    4141
    4242class CompoundStmt : public Statement {
    4343  public:
     44        std::list<Statement*> kids;
     45
    4446        CompoundStmt( std::list<Label> labels );
    4547        CompoundStmt( const CompoundStmt &other );
     
    5456        virtual CompoundStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    5557        virtual void print( std::ostream &os, int indent = 0 ) const;
    56   private:
    57         std::list<Statement*> kids;
    5858};
    5959
     
    6767        virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    6868        virtual void print( std::ostream &os, int indent = 0 ) const;
    69 
    70   private:
    7169};
    7270
    7371class ExprStmt : public Statement {
    7472  public:
     73        Expression *expr;
     74
    7575        ExprStmt( std::list<Label> labels, Expression *expr );
    7676        ExprStmt( const ExprStmt &other );
     
    8484        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    8585        virtual void print( std::ostream &os, int indent = 0 ) const;
    86   private:
    87         Expression *expr;
    8886};
    8987
    9088class AsmStmt : public Statement {
    9189  public:
     90        bool voltile;
     91        ConstantExpr *instruction;
     92        std::list<Expression *> output, input;
     93        std::list<ConstantExpr *> clobber;
     94        std::list<Label> gotolabels;
     95
    9296        AsmStmt( std::list<Label> labels, bool voltile, ConstantExpr *instruction, std::list<Expression *> input, std::list<Expression *> output, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );
    9397        AsmStmt( const AsmStmt &other );
     
    111115        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    112116        virtual void print( std::ostream &os, int indent = 0 ) const;
    113   private:
    114         bool voltile;
    115         ConstantExpr *instruction;
    116         std::list<Expression *> output, input;
    117         std::list<ConstantExpr *> clobber;
    118         std::list<Label> gotolabels;
    119117};
    120118
    121119class IfStmt : public Statement {
    122120  public:
     121        Expression *condition;
     122        Statement *thenPart;
     123        Statement *elsePart;
     124
    123125        IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart );
    124126        IfStmt( const IfStmt &other );
     
    136138        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    137139        virtual void print( std::ostream &os, int indent = 0 ) const;
    138   private:
    139         Expression *condition;
    140         Statement *thenPart;
    141         Statement *elsePart;
    142140};
    143141
    144142class SwitchStmt : public Statement {
    145143  public:
     144        Expression * condition;
     145
    146146        SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements );
    147147        SwitchStmt( const SwitchStmt &other );
     
    159159        virtual void print( std::ostream &os, int indent = 0 ) const;
    160160  private:
     161        std::list<Statement *> statements;
     162};
     163
     164class CaseStmt : public Statement {
     165  public:
    161166        Expression * condition;
    162         std::list<Statement *> statements;
    163 };
    164 
    165 class CaseStmt : public Statement {
    166   public:
     167        std::list<Statement *> stmts;
     168
    167169        CaseStmt( std::list<Label> labels, Expression *conditions, std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError);
    168170        CaseStmt( const CaseStmt &other );
     
    186188        virtual void print( std::ostream &os, int indent = 0 ) const;
    187189  private:
    188         Expression * condition;
    189         std::list<Statement *> stmts;
    190190        bool _isDefault;
    191191};
     
    193193class WhileStmt : public Statement {
    194194  public:
     195        Expression *condition;
     196        Statement *body;
     197        bool isDoWhile;
     198
    195199        WhileStmt( std::list<Label> labels, Expression *condition,
    196200               Statement *body, bool isDoWhile = false );
     
    209213        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    210214        virtual void print( std::ostream &os, int indent = 0 ) const;
    211   private:
     215};
     216
     217class ForStmt : public Statement {
     218  public:
     219        std::list<Statement *> initialization;
    212220        Expression *condition;
     221        Expression *increment;
    213222        Statement *body;
    214         bool isDoWhile;
    215 };
    216 
    217 class ForStmt : public Statement {
    218   public:
     223
    219224        ForStmt( std::list<Label> labels, std::list<Statement *> initialization,
    220225             Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
     
    235240        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    236241        virtual void print( std::ostream &os, int indent = 0 ) const;
    237   private:
    238         std::list<Statement *> initialization;
    239         Expression *condition;
    240         Expression *increment;
    241         Statement *body;
    242242};
    243243
     
    245245  public:
    246246        enum Type { Goto = 0, Break, Continue };
     247
     248        // originalTarget kept for error messages.
     249        const Label originalTarget;
     250        Label target;
     251        Expression *computedTarget;
     252        Type type;
    247253
    248254        BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError);
     
    265271  private:
    266272        static const char *brType[];
    267         Label originalTarget;  // can give better error messages if we remember the label name that the user entered
    268         Label target;
    269         Expression *computedTarget;
    270         Type type;
    271273};
    272274
    273275class ReturnStmt : public Statement {
    274276  public:
     277        Expression *expr;
     278
    275279        ReturnStmt( std::list<Label> labels, Expression *expr );
    276280        ReturnStmt( const ReturnStmt &other );
     
    284288        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    285289        virtual void print( std::ostream &os, int indent = 0 ) const;
    286   private:
    287         Expression *expr;
    288290};
    289291
     
    291293  public:
    292294        enum Kind { Terminate, Resume };
     295
     296        const Kind kind;
     297        Expression * expr;
     298        Expression * target;
    293299
    294300        ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target = nullptr );
     
    306312        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    307313        virtual void print( std::ostream &os, int indent = 0 ) const;
    308   private:
    309         Kind kind;
    310         Expression * expr;
    311         Expression * target;
    312314};
    313315
    314316class TryStmt : public Statement {
    315317  public:
     318        CompoundStmt *block;
     319        std::list<CatchStmt *> handlers;
     320        FinallyStmt *finallyBlock;
     321
    316322        TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );
    317323        TryStmt( const TryStmt &other );
     
    329335        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    330336        virtual void print( std::ostream &os, int indent = 0 ) const;
    331 
    332   private:
    333         CompoundStmt *block;
    334         std::list<CatchStmt *> handlers;
    335         FinallyStmt *finallyBlock;
    336337};
    337338
     
    339340  public:
    340341        enum Kind { Terminate, Resume };
     342
     343        const Kind kind;
     344        Declaration *decl;
     345        Expression *cond;
     346        Statement *body;
    341347
    342348        CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl,
     
    357363        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    358364        virtual void print( std::ostream &os, int indent = 0 ) const;
    359 
    360   private:
    361         Kind kind;
    362         Declaration *decl;
    363         Expression *cond;
    364         Statement *body;
    365365};
    366366
    367367class FinallyStmt : public Statement {
    368368  public:
     369        CompoundStmt *block;
     370
    369371        FinallyStmt( std::list<Label> labels, CompoundStmt *block );
    370372        FinallyStmt( const FinallyStmt &other );
     
    378380        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    379381        virtual void print( std::ostream &os, int indent = 0 ) const;
    380   private:
    381         CompoundStmt *block;
    382382};
    383383
     
    386386class DeclStmt : public Statement {
    387387  public:
     388        Declaration *decl;
     389
    388390        DeclStmt( std::list<Label> labels, Declaration *decl );
    389391        DeclStmt( const DeclStmt &other );
     
    397399        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    398400        virtual void print( std::ostream &os, int indent = 0 ) const;
    399   private:
    400         Declaration *decl;
    401401};
    402402
     
    407407class ImplicitCtorDtorStmt : public Statement {
    408408  public:
     409        // Non-owned pointer to the constructor/destructor statement
     410        Statement * callStmt;
     411
    409412        ImplicitCtorDtorStmt( Statement * callStmt );
    410413        ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other );
     
    418421        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    419422        virtual void print( std::ostream &os, int indent = 0 ) const;
    420 
    421   private:
    422         // Non-owned pointer to the constructor/destructor statement
    423         Statement * callStmt;
    424423};
    425424
  • src/SynTree/Type.cc

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 17 08:42:47 2017
    13 // Update Count     : 28
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug  2 11:11:00 2017
     13// Update Count     : 29
    1414//
    1515
     
    8888}
    8989
     90// Empty Variable declarations:
     91const Type::FuncSpecifiers noFuncSpecifiers;
     92const Type::StorageClasses noStorageClasses;
     93const Type::Qualifiers noQualifiers;
     94
    9095std::ostream & operator<<( std::ostream & out, const Type * type ) {
    9196        if ( type ) {
  • src/SynTree/Type.h

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:53:29 2017
    13 // Update Count     : 151
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug  9 14:25:00 2017
     13// Update Count     : 152
    1414//
    1515
     
    127127        }; // Qualifiers
    128128
     129        typedef std::list<TypeDecl *> ForallList;
     130
     131        Qualifiers tq;
     132        ForallList forall;
     133        std::list< Attribute * > attributes;
     134
    129135        Type( const Qualifiers & tq, const std::list< Attribute * > & attributes );
    130136        Type( const Type & other );
     
    145151        void set_atomic( bool newValue ) { tq.is_atomic = newValue; }
    146152
    147         typedef std::list<TypeDecl *> ForallList;
    148153        ForallList& get_forall() { return forall; }
    149154
     
    165170        virtual Type *acceptMutator( Mutator & m ) = 0;
    166171        virtual void print( std::ostream & os, int indent = 0 ) const;
    167   private:
    168         Qualifiers tq;
    169         ForallList forall;
    170         std::list< Attribute * > attributes;
    171 };
    172 
    173 extern Type::Qualifiers noQualifiers;                           // no qualifiers on constants
     172};
     173
     174extern const Type::FuncSpecifiers noFuncSpecifiers;
     175extern const Type::StorageClasses noStorageClasses;
     176extern const Type::Qualifiers noQualifiers;                     // no qualifiers on constants
    174177
    175178class VoidType : public Type {
     
    211214                LongDoubleImaginary,
    212215                NUMBER_OF_BASIC_TYPES
    213         };
     216        } kind;
    214217
    215218        static const char *typeNames[];                                         // string names for basic types, MUST MATCH with Kind
     
    226229
    227230        bool isInteger() const;
    228   private:
    229         Kind kind;
    230231};
    231232
    232233class PointerType : public Type {
    233234  public:
     235        Type *base;
     236
     237        // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
     238        Expression *dimension;
     239        bool isVarLen;
     240        bool isStatic;
     241
    234242        PointerType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    235243        PointerType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
     
    252260        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
    253261        virtual void print( std::ostream & os, int indent = 0 ) const;
    254   private:
     262};
     263
     264class ArrayType : public Type {
     265  public:
    255266        Type *base;
    256 
    257         // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
    258267        Expression *dimension;
    259268        bool isVarLen;
    260269        bool isStatic;
    261 };
    262 
    263 class ArrayType : public Type {
    264   public:
     270
    265271        ArrayType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    266272        ArrayType( const ArrayType& );
     
    282288        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
    283289        virtual void print( std::ostream & os, int indent = 0 ) const;
    284   private:
    285         Type *base;
    286         Expression *dimension;
    287         bool isVarLen;
    288         bool isStatic;
    289290};
    290291
    291292class FunctionType : public Type {
    292293  public:
     294        std::list<DeclarationWithType*> returnVals;
     295        std::list<DeclarationWithType*> parameters;
     296
     297        // Does the function accept a variable number of arguments following the arguments specified in the parameters list.
     298        // This could be because of
     299        // - an ellipsis in a prototype declaration
     300        // - an unprototyped declaration
     301        bool isVarArgs;
     302
    293303        FunctionType( const Type::Qualifiers & tq, bool isVarArgs, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    294304        FunctionType( const FunctionType& );
     
    305315        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
    306316        virtual void print( std::ostream & os, int indent = 0 ) const;
    307   private:
    308         std::list<DeclarationWithType*> returnVals;
    309         std::list<DeclarationWithType*> parameters;
    310 
    311         // Does the function accept a variable number of arguments following the arguments specified in the parameters list.
    312         // This could be because of
    313         // - an ellipsis in a prototype declaration
    314         // - an unprototyped declaration
    315         bool isVarArgs;
    316317};
    317318
    318319class ReferenceToType : public Type {
    319320  public:
     321        std::list< Expression* > parameters;
     322        std::string name;
     323        bool hoistType;
     324
    320325        ReferenceToType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes );
    321326        ReferenceToType( const ReferenceToType & other );
     
    336341  protected:
    337342        virtual std::string typeString() const = 0;
    338         std::list< Expression* > parameters;
    339         std::string name;
    340   private:
    341         bool hoistType;
    342343};
    343344
     
    345346        typedef ReferenceToType Parent;
    346347  public:
     348        // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
     349        // where the structure used in this type is actually defined
     350        StructDecl *baseStruct;
     351
    347352        StructInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ), baseStruct( 0 ) {}
    348353        StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
     
    368373  private:
    369374        virtual std::string typeString() const;
    370 
    371         // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
    372         // where the structure used in this type is actually defined
    373         StructDecl *baseStruct;
    374375};
    375376
     
    377378        typedef ReferenceToType Parent;
    378379  public:
     380        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
     381        // where the union used in this type is actually defined
     382        UnionDecl *baseUnion;
     383
    379384        UnionInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ), baseUnion( 0 ) {}
    380385        UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
     
    400405  private:
    401406        virtual std::string typeString() const;
    402 
     407};
     408
     409class EnumInstType : public ReferenceToType {
     410        typedef ReferenceToType Parent;
     411  public:
    403412        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
    404413        // where the union used in this type is actually defined
    405         UnionDecl *baseUnion;
    406 };
    407 
    408 class EnumInstType : public ReferenceToType {
    409         typedef ReferenceToType Parent;
    410   public:
     414        EnumDecl *baseEnum = nullptr;
     415
    411416        EnumInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ) {}
    412417        EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
     
    423428  private:
    424429        virtual std::string typeString() const;
    425 
    426         // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
    427         // where the union used in this type is actually defined
    428         EnumDecl *baseEnum = nullptr;
    429430};
    430431
     
    432433        typedef ReferenceToType Parent;
    433434  public:
     435        // this member is filled in by the validate pass, which instantiates the members of the correponding
     436        // aggregate with the actual type parameters specified for this use of the context
     437        std::list< Declaration* > members;
     438
    434439        TraitInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ) {}
    435440        TraitInstType( const TraitInstType & other );
     
    445450  private:
    446451        virtual std::string typeString() const;
    447 
    448         // this member is filled in by the validate pass, which instantiates the members of the correponding
    449         // aggregate with the actual type parameters specified for this use of the context
    450         std::list< Declaration* > members;
    451452};
    452453
     
    454455        typedef ReferenceToType Parent;
    455456  public:
     457        // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
     458        // where the type used here is actually defined
     459        TypeDecl *baseType;
     460        bool isFtype;
     461
    456462        TypeInstType( const Type::Qualifiers & tq, const std::string & name, TypeDecl *baseType, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
    457463        TypeInstType( const Type::Qualifiers & tq, const std::string & name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
     
    472478  private:
    473479        virtual std::string typeString() const;
    474         // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
    475         // where the type used here is actually defined
    476         TypeDecl *baseType;
    477         bool isFtype;
    478480};
    479481
    480482class TupleType : public Type {
    481483  public:
     484        std::list<Type *> types;
     485        std::list<Declaration *> members;
     486
    482487        TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
    483488        TupleType( const TupleType& );
     
    508513        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
    509514        virtual void print( std::ostream & os, int indent = 0 ) const;
    510   private:
    511         std::list<Type *> types;
    512         std::list<Declaration *> members;
    513515};
    514516
    515517class TypeofType : public Type {
    516518  public:
     519        Expression *expr;
     520
    517521        TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
    518522        TypeofType( const TypeofType& );
     
    528532        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
    529533        virtual void print( std::ostream & os, int indent = 0 ) const;
    530   private:
     534};
     535
     536class AttrType : public Type {
     537  public:
     538        std::string name;
    531539        Expression *expr;
    532 };
    533 
    534 class AttrType : public Type {
    535   public:
     540        Type *type;
     541        bool isType;
     542
    536543        AttrType( const Type::Qualifiers & tq, const std::string & name, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    537544        AttrType( const Type::Qualifiers & tq, const std::string & name, Type *type, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
     
    554561        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
    555562        virtual void print( std::ostream & os, int indent = 0 ) const;
    556   private:
    557         std::string name;
    558         Expression *expr;
    559         Type *type;
    560         bool isType;
    561563};
    562564
  • src/SynTree/TypeDecl.cc

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 07:49:58 2017
    13 // Update Count     : 5
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug  9 14:35:00 2017
     13// Update Count     : 6
    1414//
    1515
     
    1818#include "Common/utility.h"
    1919
    20 TypeDecl::TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, Type * init ) : Parent( name, scs, type ), kind( kind ), init( init ), sized( kind == Any || kind == Ttype ) {
     20TypeDecl::TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, Type * init ) : Parent( name, scs, type ), init( init ), sized( kind == Any || kind == Ttype ), kind( kind ) {
    2121}
    2222
    23 TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), kind( other.kind ), init( maybeClone( other.init ) ), sized( other.sized ) {
     23TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), init( maybeClone( other.init ) ), sized( other.sized ), kind( other.kind ) {
    2424}
    2525
  • src/SynTree/TypeExpr.cc

    r275f4b4 rcd7ef0b  
    2121}
    2222
    23 TypeExpr::TypeExpr( const TypeExpr &other ) : type( maybeClone( other.type ) ) {
     23TypeExpr::TypeExpr( const TypeExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {
    2424}
    2525
  • src/Tuples/TupleExpansion.cc

    r275f4b4 rcd7ef0b  
    6666                };
    6767
    68                 class TupleTypeReplacer : public GenPoly::DeclMutator {
    69                   public:
    70                         typedef GenPoly::DeclMutator Parent;
    71                         using Parent::mutate;
    72 
    73                         virtual Type * mutate( TupleType * tupleType ) override;
    74 
    75                         virtual CompoundStmt * mutate( CompoundStmt * stmt ) override {
    76                                 typeMap.beginScope();
    77                                 stmt = Parent::mutate( stmt );
    78                                 typeMap.endScope();
    79                                 return stmt;
     68                struct TupleTypeReplacer : public WithDeclsToAdd, public WithGuards, public WithTypeSubstitution {
     69                        Type * postmutate( TupleType * tupleType );
     70
     71                        void premutate( CompoundStmt * ) {
     72                                GuardScope( typeMap );
    8073                        }
    8174                  private:
     
    111104                mutateAll( translationUnit, assnExpander );
    112105
    113                 TupleTypeReplacer replacer;
    114                 replacer.mutateDeclarationList( translationUnit );
     106                PassVisitor<TupleTypeReplacer> replacer;
     107                mutateAll( translationUnit, replacer );
    115108
    116109                PassVisitor<TupleIndexExpander> idxExpander;
     
    218211        }
    219212
    220         Type * TupleTypeReplacer::mutate( TupleType * tupleType ) {
    221                 tupleType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) );
     213        Type * TupleTypeReplacer::postmutate( TupleType * tupleType ) {
    222214                unsigned tupleSize = tupleType->size();
    223215                if ( ! typeMap.count( tupleSize ) ) {
     
    226218                        decl->set_body( true );
    227219                        for ( size_t i = 0; i < tupleSize; ++i ) {
    228                                 TypeDecl * tyParam = new TypeDecl( toString( "tuple_param_", i ), Type::StorageClasses(), nullptr, TypeDecl::Any );
     220                                TypeDecl * tyParam = new TypeDecl( toString( "tuple_param_", tupleSize, "_", i ), Type::StorageClasses(), nullptr, TypeDecl::Any );
    229221                                decl->get_members().push_back( new ObjectDecl( toString("field_", i ), Type::StorageClasses(), LinkageSpec::C, nullptr, new TypeInstType( Type::Qualifiers(), tyParam->get_name(), tyParam ), nullptr ) );
    230222                                decl->get_parameters().push_back( tyParam );
     
    235227                        }
    236228                        typeMap[tupleSize] = decl;
    237                         addDeclaration( decl );
     229                        declsToAddBefore.push_back( decl );
    238230                }
    239231                Type::Qualifiers qualifiers = tupleType->get_qualifiers();
     
    241233                StructDecl * decl = typeMap[tupleSize];
    242234                StructInstType * newType = new StructInstType( qualifiers, decl );
    243                 for ( Type * t : *tupleType ) {
     235                for ( auto p : group_iterate( tupleType->get_types(), decl->get_parameters() ) ) {
     236                        Type * t = std::get<0>(p);
     237                        TypeDecl * td = std::get<1>(p);
    244238                        newType->get_parameters().push_back( new TypeExpr( t->clone() ) );
     239                        if ( env ) {
     240                                // add bindings to the type environment.
     241                                // xxx - This may not be sufficient, it may be necessary to rename type variables on StructInstType?
     242                                env->add( td->get_name(), t->clone() );
     243                        }
    245244                }
    246245                delete tupleType;
  • src/Virtual/ExpandCasts.cc

    r275f4b4 rcd7ef0b  
    1010// Created On       : Mon Jul 24 13:59:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Jul 26 14:16:00 2017
    13 // Update Count     : 0
     12// Last Modified On : Tus Aug  2 14:59:00 2017
     13// Update Count     : 1
    1414//
    1515
     
    7878
    7979        void VirtualCastCore::premutate( FunctionDecl * functionDecl ) {
    80                 if ( (! vcast_decl) && functionDecl->get_statements() &&
     80                if ( (! vcast_decl) &&
    8181                     functionDecl->get_name() == "__cfa__virtual_cast" ) {
    8282                        vcast_decl = functionDecl;
     
    101101                assertf( castExpr->get_result(), "Virtual Cast target not found before expansion." );
    102102
    103                 //assert( vcast_decl );
     103                assert( vcast_decl );
    104104                assert( pvt_decl );
    105105
    106106                // May only cast to a pointer or reference type.
    107107                // A earlier validation should give a syntax error, this is
    108                 // just to make sure errors don't creep in.
     108                // just to make sure errors don't creep during translation.
     109                // Move to helper with more detailed error messages.
    109110                PointerType * target_type =
    110111                        dynamic_cast<PointerType *>( castExpr->get_result() );
    111         assert( target_type );
     112                assert( target_type );
    112113
    113114                StructInstType * target_struct =
    114115                        dynamic_cast<StructInstType *>( target_type->get_base() );
     116                assert( target_struct );
     117
    115118                StructDecl * target_decl = target_struct->get_baseStruct();
    116119
     
    124127
    125128                Expression * result = new CastExpr(
    126                         //new ApplicationExpr( new VariableExpr( vcast_decl ), {
     129                        //new ApplicationExpr(
     130                                //new AddressExpr( new VariableExpr( vcast_decl ) ),
     131                                //new CastExpr( new VariableExpr( vcast_decl ),
     132                                //      new PointerType( noQualifiers,
     133                                //              vcast_decl->get_type()->clone()
     134                                //              )
     135                                //      ),
    127136                        new UntypedExpr( new NameExpr( "__cfa__virtual_cast" ), {
    128                                 new CastExpr(
    129                                         new AddressExpr( new VariableExpr( table ) ),
    130                                         pointer_to_pvt(1)
    131                                         ),
    132                                 new CastExpr(
    133                                         castExpr->get_arg(),
    134                                         pointer_to_pvt(2)
    135                                         ) }
    136                                 ),
    137                         castExpr->get_result()
     137                                        new CastExpr(
     138                                                new AddressExpr( new VariableExpr( table ) ),
     139                                                pointer_to_pvt(1)
     140                                                ),
     141                                        new CastExpr(
     142                                                castExpr->get_arg(),
     143                                                pointer_to_pvt(2)
     144                                                )
     145                                } ),
     146                        castExpr->get_result()->clone()
    138147                        );
    139148
  • src/driver/cfa.cc

    r275f4b4 rcd7ef0b  
    1010// Created On       : Tue Aug 20 13:44:49 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 20 15:54:45 2017
    13 // Update Count     : 156
     12// Last Modified On : Fri Jan 20 14:38:45 2017
     13// Update Count     : 155
    1414//
    1515
     
    7676        bool cpp_flag = false;                                                          // -E or -M flag, preprocessor only
    7777        bool std_flag = false;                                                          // -std= flag
     78        bool noincstd_flag = false;                                                     // -no-include-stdhdr= flag
    7879        bool debugging __attribute(( unused )) = false;         // -g flag
    7980
     
    133134                        } else if ( arg == "-nohelp" ) {
    134135                                help = false;                                                   // strip the nohelp flag
     136                        } else if ( arg == "-no-include-stdhdr" ) {
     137                                noincstd_flag = true;                                   // strip the no-include-stdhdr flag
    135138                        } else if ( arg == "-compiler" ) {
    136139                                // use the user specified compiler
     
    231234        args[nargs] = "-I" CFA_INCDIR;
    232235        nargs += 1;
    233         args[nargs] = "-I" CFA_INCDIR "/stdhdr";
    234         nargs += 1;
     236        if ( ! noincstd_flag ) {                                                        // do not use during build
     237                args[nargs] = "-I" CFA_INCDIR "/stdhdr";
     238                nargs += 1;
     239        } // if
    235240        args[nargs] = "-I" CFA_INCDIR "/concurrency";
    236241        nargs += 1;
  • src/include/cassert

    r275f4b4 rcd7ef0b  
    1010// Created On       : Thu Aug 18 13:19:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 18 13:25:55 2016
    13 // Update Count     : 4
     12// Last Modified On : Tue Aug  1 11:56:01 2017
     13// Update Count     : 16
    1414//
    1515
     
    1818// IWYU pragma: private, include <cassert>
    1919
    20 #include_next <assert.h>
     20#include_next <cassert>
    2121
    22 #define __STRINGIFY__(str) #str
    23 #define __VSTRINGIFY__(str) __STRINGIFY__(str)
    24 #define assertf(expr, fmt, ...) ((expr) ? static_cast<void>(0) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ ))
     22#ifdef NDEBUG
    2523
    26 void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) __attribute__((noreturn));
     24#define assertf(expr, fmt, ...) (__ASSERT_VOID_ASSERT (0))
     25
     26#else
     27
     28#define assertf(expr, fmt, ...) ((expr) \
     29        ? (__ASSERT_VOID_CAST (0)) \
     30        : __assert_fail_f( #expr, __FILE__, __LINE__, \
     31        __ASSERT_FUNCTION, fmt, ## __VA_ARGS__ ))
     32
     33void __assert_fail_f(   const char *assertion, const char *file,
     34                                                unsigned int line, const char *function,
     35                                                const char *fmt, ...
     36        ) __attribute__((noreturn, format(printf, 5, 6)));
     37
     38#endif
    2739
    2840template<typename T, typename U>
    29 static inline T safe_dynamic_cast(const U& src) {
     41static inline T safe_dynamic_cast( const U & src ) {
    3042        T ret = dynamic_cast<T>(src);
    3143        assert(ret);
  • src/libcfa/Makefile.am

    r275f4b4 rcd7ef0b  
    3939
    4040AM_CCASFLAGS = @CFA_FLAGS@
    41 CFLAGS = -quiet -I${abs_top_srcdir}/src/libcfa/stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver ${EXTRA_FLAGS}
     41
     42#CFLAGS for most libcfa src
     43#use -no-include-stdhdr to prevent rebuild cycles
     44#The built sources must not depend on the installed headers
     45CFLAGS = -quiet -no-include-stdhdr -I${abs_top_srcdir}/src/libcfa/stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver ${EXTRA_FLAGS}
    4246CC = ${abs_top_srcdir}/src/driver/cfa
    4347
  • src/libcfa/Makefile.in

    r275f4b4 rcd7ef0b  
    308308CFA_NAME = @CFA_NAME@
    309309CFA_PREFIX = @CFA_PREFIX@
    310 CFLAGS = -quiet -I${abs_top_srcdir}/src/libcfa/stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver ${EXTRA_FLAGS}
     310
     311#CFLAGS for most libcfa src
     312#use -no-include-stdhdr to prevent rebuild cycles
     313#The built sources must not depend on the installed headers
     314CFLAGS = -quiet -no-include-stdhdr -I${abs_top_srcdir}/src/libcfa/stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver ${EXTRA_FLAGS}
    311315CPP = @CPP@
    312316CPPFLAGS = @CPPFLAGS@
  • src/libcfa/concurrency/monitor.c

    r275f4b4 rcd7ef0b  
    1010// Created On       : Thd Feb 23 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:37:11 2017
    13 // Update Count     : 1
     12// Last Modified On : Mon Jul 31 14:59:05 2017
     13// Update Count     : 3
    1414//
    1515
     
    484484        if( !this->monitors ) {
    485485                // LIB_DEBUG_PRINT_SAFE("Branding\n");
    486                 assertf( thrd->current_monitors != NULL, "No current monitor to brand condition", thrd->current_monitors );
     486                assertf( thrd->current_monitors != NULL, "No current monitor to brand condition %p", thrd->current_monitors );
    487487                this->monitor_count = thrd->current_monitor_count;
    488488
  • src/libcfa/exception.c

    r275f4b4 rcd7ef0b  
    99// Author           : Andrew Beach
    1010// Created On       : Mon Jun 26 15:13:00 2017
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 26 10:37:51 2017
    13 // Update Count     : 2
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Aug  4 15:20:00 2017
     13// Update Count     : 6
    1414//
     15
     16#include <stddef.h> // for size_t
    1517
    1618#include "exception.h"
     
    3234#include "lsda.h"
    3335
     36
     37// Base exception vtable is abstract, you should not have base exceptions.
     38struct __cfaehm__base_exception_t_vtable
     39                ___cfaehm__base_exception_t_vtable_instance = {
     40        .parent = NULL,
     41        .size = 0,
     42        .copy = NULL,
     43        .free = NULL,
     44        .msg = NULL
     45};
     46
     47
    3448// Temperary global exception context. Does not work with concurency.
    35 struct shared_stack_t {
     49struct exception_context_t {
    3650    struct __cfaehm__try_resume_node * top_resume;
    3751    struct __cfaehm__try_resume_node * current_resume;
    3852
    39     exception current_exception;
     53    exception * current_exception;
    4054    int current_handler_index;
    4155} shared_stack = {NULL, NULL, 0, 0};
    4256
     57// Get the current exception context.
     58// There can be a single global until multithreading occurs, then each stack
     59// needs its own. It will have to be updated to handle that.
     60struct exception_context_t * this_exception_context() {
     61        return &shared_stack;
     62}
     63//#define SAVE_EXCEPTION_CONTEXT(to_name)
     64//struct exception_context_t * to_name = this_exception_context();
     65//exception * this_exception() {
     66//    return this_exception_context()->current_exception;
     67//}
    4368
    4469
     
    5580
    5681        // DEBUG
    57         printf("Throwing resumption exception %d\n", *except);
     82        printf("Throwing resumption exception\n");
    5883
    5984        struct __cfaehm__try_resume_node * original_head = shared_stack.current_resume;
     
    6994        }
    7095
    71         printf("Unhandled exception %d\n", *except);
     96        printf("Unhandled exception\n");
    7297        shared_stack.current_resume = original_head;
    7398
     
    94119// TERMINATION ===============================================================
    95120
    96 // Requires -fexceptions to work.
    97 
    98 // Global which defines the current exception.  Currently an int just to make matching easier.
    99 //int this_exception; (became shared_stack.current_exception)
     121// MEMORY MANAGEMENT (still for integers)
     122// May have to move to cfa for constructors and destructors (references).
     123
     124struct __cfaehm__node {
     125        struct __cfaehm__node * next;
     126};
     127
     128#define NODE_TO_EXCEPT(node) ((exception *)(1 + (node)))
     129#define EXCEPT_TO_NODE(except) ((struct __cfaehm__node *)(except) - 1)
     130
     131// Creates a copy of the indicated exception and sets current_exception to it.
     132static void __cfaehm__allocate_exception( exception * except ) {
     133        struct exception_context_t * context = this_exception_context();
     134
     135        // Allocate memory for the exception.
     136        struct __cfaehm__node * store = malloc(
     137                sizeof( struct __cfaehm__node ) + except->virtual_table->size );
     138
     139        if ( ! store ) {
     140                // Failure: cannot allocate exception. Terminate thread.
     141                abort(); // <- Although I think it might be the process.
     142        }
     143
     144        // Add the node to the list:
     145        store->next = EXCEPT_TO_NODE(context->current_exception);
     146        context->current_exception = NODE_TO_EXCEPT(store);
     147
     148        // Copy the exception to storage.
     149        except->virtual_table->copy( context->current_exception, except );
     150}
     151
     152// Delete the provided exception, unsetting current_exception if relivant.
     153static void __cfaehm__delete_exception( exception * except ) {
     154        struct exception_context_t * context = this_exception_context();
     155
     156        // DEBUG
     157        printf( "Deleting Exception\n");
     158
     159        // Remove the exception from the list.
     160        struct __cfaehm__node * to_free = EXCEPT_TO_NODE(except);
     161        struct __cfaehm__node * node;
     162
     163        if ( context->current_exception == except ) {
     164                node = to_free->next;
     165                context->current_exception = (node) ? NODE_TO_EXCEPT(node) : 0;
     166        } else {
     167                node = EXCEPT_TO_NODE(context->current_exception);
     168                // It may always be in the first or second position.
     169                while( to_free != node->next ) {
     170                        node = node->next;
     171                }
     172                node->next = to_free->next;
     173        }
     174
     175        // Free the old exception node.
     176        except->virtual_table->free( except );
     177        free( to_free );
     178}
     179
     180// If this isn't a rethrow (*except==0), delete the provided exception.
     181void __cfaehm__cleanup_terminate( void * except ) {
     182        if ( *(void**)except ) __cfaehm__delete_exception( *(exception**)except );
     183}
     184
    100185
    101186// We need a piece of storage to raise the exception
     
    117202}
    118203
    119 void __cfaehm__throw_terminate( exception * val ) {
    120         // Store the current exception
    121         shared_stack.current_exception = *val;
    122 
    123         // DEBUG
    124         printf("Throwing termination exception %d\n", *val);
     204// The exception that is being thrown must already be stored.
     205__attribute__((noreturn)) void __cfaehm__begin_unwind(void) {
     206        if ( ! this_exception_context()->current_exception ) {
     207                printf("UNWIND ERROR missing exception in begin unwind\n");
     208                abort();
     209        }
     210
    125211
    126212        // Call stdlibc to raise the exception
     
    148234}
    149235
    150 // Nesting this the other way would probably be faster.
     236void __cfaehm__throw_terminate( exception * val ) {
     237        // DEBUG
     238        printf("Throwing termination exception\n");
     239
     240        __cfaehm__allocate_exception( val );
     241        __cfaehm__begin_unwind();
     242}
     243
    151244void __cfaehm__rethrow_terminate(void) {
    152245        // DEBUG
    153246        printf("Rethrowing termination exception\n");
    154247
    155         __cfaehm__throw_terminate(&shared_stack.current_exception);
     248        __cfaehm__begin_unwind();
    156249}
    157250
     
    263356                                        _Unwind_Reason_Code (*matcher)(exception *) =
    264357                                                MATCHER_FROM_CONTEXT(context);
    265                                         int index = matcher(&shared_stack.current_exception);
     358                                        int index = matcher(shared_stack.current_exception);
    266359                                        _Unwind_Reason_Code ret = (0 == index)
    267360                                                ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
     
    359452        // Exception handler
    360453        catch_block( shared_stack.current_handler_index,
    361                     &shared_stack.current_exception );
     454                     shared_stack.current_exception );
    362455}
    363456
  • src/libcfa/exception.h

    r275f4b4 rcd7ef0b  
    99// Author           : Andrew Beach
    1010// Created On       : Mon Jun 26 15:11:00 2017
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:57:02 2017
    13 // Update Count     : 3
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Aug  4 15:20:00 2017
     13// Update Count     : 5
    1414//
    1515
    1616#pragma once
    1717
    18 // Later to be a special structure type.
    19 typedef int exception;
    2018
    2119#ifdef __CFORALL__
    2220extern "C" {
    2321#endif
     22
     23struct __cfaehm__base_exception_t;
     24typedef struct __cfaehm__base_exception_t exception;
     25struct __cfaehm__base_exception_t_vtable {
     26        const struct __cfaehm__base_exception_t_vtable * parent;
     27        size_t size;
     28        void (*copy)(struct __cfaehm__base_exception_t *this,
     29                     struct __cfaehm__base_exception_t * other);
     30        void (*free)(struct __cfaehm__base_exception_t *this);
     31        const char (*msg)(struct __cfaehm__base_exception_t *this);
     32};
     33struct __cfaehm__base_exception_t {
     34        struct __cfaehm__base_exception_t_vtable const * virtual_table;
     35};
     36extern struct __cfaehm__base_exception_t_vtable
     37        ___cfaehm__base_exception_t_vtable_instance;
     38
    2439
    2540// Used in throw statement translation.
     
    3449    int (*match_block)(exception * except));
    3550
     51// Clean-up the exception in catch blocks.
     52void __cfaehm__cleanup_terminate(void * except);
     53
    3654// Data structure creates a list of resume handlers.
    3755struct __cfaehm__try_resume_node {
     
    4058};
    4159
     60// These act as constructor and destructor for the resume node.
    4261void __cfaehm__try_resume_setup(
    4362    struct __cfaehm__try_resume_node * node,
     
    4766
    4867// Check for a standard way to call fake deconstructors.
    49 struct __cfaehm__cleanup_hook {
    50 };
     68struct __cfaehm__cleanup_hook {};
    5169
    5270#ifdef __CFORALL__
  • src/libcfa/iostream

    r275f4b4 rcd7ef0b  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul  7 08:35:59 2017
    13 // Update Count     : 118
     12// Last Modified On : Wed Aug  9 16:42:47 2017
     13// Update Count     : 131
    1414//
    1515
     
    4646}; // ostream
    4747
    48 trait writeable( otype T ) {
    49         forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T );
     48// trait writeable( otype T ) {
     49//      forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T );
     50// }; // writeable
     51
     52trait writeable( otype T, dtype ostype | ostream( ostype ) ) {
     53        ostype * ?|?( ostype *, T );
    5054}; // writeable
    5155
     
    7781
    7882// tuples
    79 forall( dtype ostype, otype T, ttype Params | ostream( ostype ) | writeable( T ) | { ostype * ?|?( ostype *, Params ); } ) ostype * ?|?( ostype * os, T arg, Params rest );
     83forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype * ?|?( ostype *, Params ); } )
     84ostype * ?|?( ostype * os, T arg, Params rest );
    8085
    8186// manipulators
     
    9095
    9196// writes the range [begin, end) to the given stream
    92 forall( otype elt_type | writeable( elt_type ), otype iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )
    93 void write( iterator_type begin, iterator_type end, os_type *os );
     97forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) )
     98void write( iterator_type begin, iterator_type end, ostype * os );
    9499
    95 forall( otype elt_type | writeable( elt_type ), otype iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )
    96 void write_reverse( iterator_type begin, iterator_type end, os_type *os );
     100forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) )
     101void write_reverse( iterator_type begin, iterator_type end, ostype * os );
    97102
    98103//---------------------------------------
  • src/libcfa/iostream.c

    r275f4b4 rcd7ef0b  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jul 16 21:12:03 2017
    13 // Update Count     : 398
     12// Last Modified On : Wed Aug  9 16:46:51 2017
     13// Update Count     : 401
    1414//
    1515
     
    193193
    194194// tuples
    195 forall( dtype ostype, otype T, ttype Params | ostream( ostype ) | writeable( T ) | { ostype * ?|?( ostype *, Params ); } )
     195forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype * ?|?( ostype *, Params ); } )
    196196ostype * ?|?( ostype * os, T arg, Params rest ) {
    197197        os | arg;                                                                                       // print first argument
     
    256256//---------------------------------------
    257257
    258 forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) )
    259 void write( iteratortype begin, iteratortype end, ostype * os ) {
    260         void print( elttype i ) { os | i; }
     258forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) )
     259void write( iterator_type begin, iterator_type end, ostype * os ) {
     260        void print( elt_type i ) { os | i; }
    261261        for_each( begin, end, print );
    262262} // ?|?
    263263
    264 forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) )
    265 void write_reverse( iteratortype begin, iteratortype end, ostype * os ) {
    266         void print( elttype i ) { os | i; }
     264forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) )
     265void write_reverse( iterator_type begin, iterator_type end, ostype * os ) {
     266        void print( elt_type i ) { os | i; }
    267267        for_each_reverse( begin, end, print );
    268268} // ?|?
  • src/libcfa/math

    r275f4b4 rcd7ef0b  
    1010// Created On       : Mon Apr 18 23:37:04 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 17:03:13 2017
    13 // Update Count     : 101
     12// Last Modified On : Mon Aug  7 07:51:15 2017
     13// Update Count     : 108
    1414//
    1515
     
    1818#include <math.h>
    1919#include <complex.h>
     20
     21//---------------------- General ----------------------
    2022
    2123static inline float ?%?( float x, float y ) { return fmodf( x, y ); }
     
    3739static inline [ int, long double ] remquo( long double x, long double y ) { int quo; x = remquol( x, y, &quo ); return [ quo, x ]; }
    3840
    39 // alternative name for remquo
    40 static inline float div( float x, float y, int * quo ) { return remquof( x, y, quo ); }
    41 static inline double div( double x, double y, int * quo ) { return remquo( x, y, quo ); }
    42 static inline long double div( long double x, long double y, int * quo ) { return remquol( x, y, quo ); }
    43 static inline [ int, float ] div( float x, float y ) { int quo; x = remquof( x, y, &quo ); return [ quo, x ]; }
    44 static inline [ int, double ] div( double x, double y ) { int quo; x = remquo( x, y, &quo ); return [ quo, x ]; }
    45 static inline [ int, long double ] div( long double x, long double y ) { int quo; x = remquol( x, y, &quo ); return [ quo, x ]; }
     41static inline [ float, float ] div( float x, float y ) { y = modff( x / y, &x ); return [ x, y ]; }
     42static inline [ double, double ] div( double x, double y ) { y = modf( x / y, &x ); return [ x, y ]; }
     43static inline [ long double, long double ] div( long double x, long double y ) { y = modfl( x / y, &x ); return [ x, y ]; }
    4644
    4745static inline float fma( float x, float y, float z ) { return fmaf( x, y, z ); }
  • src/libcfa/stdhdr/assert.h

    r275f4b4 rcd7ef0b  
    1010// Created On       : Mon Jul  4 23:25:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 20 21:06:48 2017
    13 // Update Count     : 11
     12// Last Modified On : Mon Jul 31 23:09:32 2017
     13// Update Count     : 13
    1414//
    1515
     
    2525        #define __STRINGIFY__(str) #str
    2626        #define __VSTRINGIFY__(str) __STRINGIFY__(str)
    27         #define assertf(expr, fmt, ...) ((expr) ? ((void)0) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ ))
    28         void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) __attribute__((noreturn));
     27        #define assertf( expr, fmt, ... ) ((expr) ? ((void)0) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ ))
     28
     29        void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) __attribute__((noreturn, format( printf, 5, 6) ));
    2930#endif
    3031
  • src/libcfa/stdlib

    r275f4b4 rcd7ef0b  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 20 14:32:37 2017
    13 // Update Count     : 220
     12// Last Modified On : Mon Aug  7 11:19:07 2017
     13// Update Count     : 223
    1414//
    1515
     
    183183//---------------------------------------
    184184
     185[ int, int ] div( int num, int denom );
     186[ long int, long int ] div( long int num, long int denom );
     187[ long long int, long long int ] div( long long int num, long long int denom );
    185188forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
    186 [ T, T ] div( T t1, T t2 );
     189[ T, T ] div( T num, T demon );
    187190
    188191//---------------------------------------
  • src/libcfa/stdlib.c

    r275f4b4 rcd7ef0b  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 20 16:01:40 2017
    13 // Update Count     : 282
     12// Last Modified On : Tue Aug  8 17:31:13 2017
     13// Update Count     : 291
    1414//
    1515
     
    255255//---------------------------------------
    256256
     257[ int, int ] div( int num, int denom ) { div_t qr = div( num, denom ); return [ qr.quot, qr.rem ]; }
     258[ long int, long int ] div( long int num, long int denom ) { ldiv_t qr = ldiv( num, denom ); return [ qr.quot, qr.rem ]; }
     259[ long long int, long long int ] div( long long int num, long long int denom ) { lldiv_t qr = lldiv( num, denom ); return [ qr.quot, qr.rem ]; }
    257260forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
    258 [ T, T ] div( T t1, T t2 ) { return [ t1 / t2, t1 % t2 ]; }
     261[ T, T ] div( T num, T denom ) { return [ num / denom, num % denom ]; }
    259262
    260263//---------------------------------------
  • src/tests/.expect/32/math.txt

    r275f4b4 rcd7ef0b  
    22remainder:-1 -1 -1
    33remquo:7 0.0999999 7 0.1 7 0.0999999999999999999
    4 div:7 0.0999999 7 0.1 7 0.0999999999999999999
     4div:7, 0.2 7, 0.2 7, 0.2
    55fma:-2 -2 -2
    66fdim:2 2 2
     
    5555frexp:0.5 3 0.5 3 0.5 3
    5656ldexp:8 8 8
    57 modf:2 0.3 2 0.3 2 0.3 nextafter:2 2 2
     57modf:2 0.3 2 0.3 2 0.3
     58modf:2, 0.3 2, 0.3 2, 0.3
     59nextafter:2 2 2
    5860nexttoward:2 2 2
    5961scalbn:16 16 16
  • src/tests/.expect/64/math.txt

    r275f4b4 rcd7ef0b  
    22remainder:-1 -1 -1
    33remquo:7 0.0999999 7 0.1 7 0.0999999999999999999
    4 div:7 0.0999999 7 0.1 7 0.0999999999999999999
     4div:7, 0.2 7, 0.2 7, 0.2
    55fma:-2 -2 -2
    66fdim:2 2 2
     
    5555frexp:0.5 3 0.5 3 0.5 3
    5656ldexp:8 8 8
    57 modf:2 0.3 2 0.3 2 0.3 nextafter:2 2 2
     57modf:2 0.3 2 0.3 2 0.3
     58modf:2, 0.3 2, 0.3 2, 0.3
     59nextafter:2 2 2
    5860nexttoward:2 2 2
    5961scalbn:16 16 16
  • src/tests/designations.c

    r275f4b4 rcd7ef0b  
    99// Author           : Rob Schluntz
    1010// Created On       : Thu Jun 29 15:26:36 2017
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jun 29 15:27:05 2017
    13 // Update Count     : 2
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Jul 27 11:46:35 2017
     13// Update Count     : 3
    1414//
    1515
     
    8989};
    9090
     91struct Fred {
     92    double i[3];
     93    int j;
     94    struct Mary {
     95        struct Jane {
     96            double j;
     97        } j;
     98        double i;
     99    } m;
     100};
     101struct Fred s1 @= { .m.j : 3 };
     102struct Fred s2 @= { .i : { [2] : 2 } };
     103
    91104int main() {
    92105        // simple designation case - starting from beginning of structure, leaves ptr default-initialized (zero)
     
    199212        };
    200213#endif
    201 
     214        // array designation
     215        int i[2] = { [1] : 3 };
    202216        // allowed to have 'too many' initialized lists - essentially they are ignored.
    203217        int i1 = { 3 };
     
    240254        const char * str0 = "hello";
    241255        char str1[] = "hello";
     256        const char c1[] = "abc";
     257        const char c2[] = { 'a', 'b', 'c' };
     258        const char c3[][2] = { { 'a', 'b' }, { 'c', 'd'}, { 'c', 'd'} };
    242259}
    243260
  • src/tests/except-0.c

    r275f4b4 rcd7ef0b  
    66#include <stdbool.h>
    77
     8// Local type to mark exits from scopes. (see ERROR)
    89struct signal_exit {
    910        const char * area;
     
    1920}
    2021
    21 void terminate(int except_value) {
     22
     23// Local Exception Types and manual vtable types.
     24//#define TRIVIAL_EXCEPTION(name) //TRIVAL_EXCEPTION(yin)
     25struct yin;
     26struct yin_vtable {
     27        struct exception_t_vtable const * parent;
     28        size_t size;
     29    void (*copy)(yin *this, yin * other);
     30    void (*free)(yin *this);
     31    const char (*msg)(yin *this);
     32};
     33struct yin {
     34        struct yin_vtable const * parent;
     35};
     36void yin_msg(yin) {
     37        return "in";
     38}
     39yin_vtable _yin_vtable_instance = {
     40        &_exception_t_vtable_instance, sizeof(yin), ?{}, ^?{}, yin_msg
     41}
     42
     43
     44void terminate(exception * except_value) {
    2245        signal_exit a = {"terminate function"};
    2346        throw except_value;
     
    2548}
    2649
    27 void resume(int except_value) {
     50void resume(exception * except_value) {
    2851        signal_exit a = {"resume function"};
    2952        throwResume except_value;
  • src/tests/math.c

    r275f4b4 rcd7ef0b  
    1010// Created On       : Fri Apr 22 14:59:21 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 10:32:04 2017
    13 // Update Count     : 73
     12// Last Modified On : Wed Aug  9 07:20:49 2017
     13// Update Count     : 77
    1414//
    1515
     
    3131        l = remquo( 3.6L, 0.5L, &quot );
    3232        sout | quot | l | endl;
    33         f = div( 3.6F, 0.5F, &quot );
    34         sout | "div:" | quot | f;
    35         d = div( 3.6D, 0.5F, &quot );
    36         sout | quot | d;
    37         l = div( 3.6L, 0.5L, &quot );
    38         sout | quot | l | endl;
     33        sout | "div:" | div( 3.6F, 0.5F ) | div( 3.6D, 0.5D ) | div( 3.6L, 0.5L ) | endl;
    3934        sout | "fma:" | fma( 3.0F, -1.0F, 1.0F ) | fma( 3.0D, -1.0D, 1.0D ) | fma( 3.0L, -1.0L, , 1.0L ) | endl;
    4035        sout | "fdim:" | fdim( 1.0F, -1.0F ) | fdim( 1.0D, -1.0D ) | fdim( 1.0L, -1.0L ) | endl;
     
    137132        sout | di | d;
    138133        l = modf( 2.3L, &ldi );
    139         sout | ldi | l;
     134        sout | ldi | l | endl;
     135        sout | "modf:" | modf( 2.3F ) | modf( 2.3D ) | modf( 2.3L ) | endl;
    140136        sout | "nextafter:" | nextafter( 2.0F, 3.0F ) | nextafter( 2.0D, 3.0D ) | nextafter( 2.0L, 3.0L ) | endl;
    141137        sout | "nexttoward:" | nexttoward( 2.0F, 3.0F ) | nexttoward( 2.0D, 3.0D ) | nexttoward( 2.0L, 3.0L ) | endl;
Note: See TracChangeset for help on using the changeset viewer.