Provide uniform isXxx functions in the standard modules.

With this patch, the following param functions are provided that test
whether the argument is or is of the corresponding type:

  isVoid
  isBool
  isInt
  isUint
  isReal
  isImag
  isComplex
  isString

  isEnum
  isTuple
  isHomogeneousTuple

  isClass
  isRecord
  isUnion

  isRange
  isDomain
  isArray
  isDmap    // a dmap-wrapped distribution

  isSync
  isSingle
  isAtomic

The following aggregate queries are also provided:

  isFloat       // real, imag
  isIntegral    // int, uint
  isNumeric     // int, uint, real, imag, complex

  isPrimitive   // primitive type as defined by the spec:
                // void, bool, int, uint, real, imag, complex, string

Each function has a version that takes a 'type' argument
and a version that takes a non-type argument, typically by blank intent.
There are also the corresponding isXxxType() and isXxxValue varieties.
For example:

  proc isRecord(type t)     param  return isRecordType(t);
  proc isRecord(e)          param  return isRecordValue(e);
  proc isRecordType(type t) param ...
  proc isRecordValue(e)     param ...

isHomogeneousTupleValue() is defined on tuples only,
to preserve the existing behavior of isHomogeneousTuple().

Also added the following queries:

  isType  - true when the argument is a type,  false otherwise
  isParam - true when the argument is a param, false otherwise

I inlined (then deleted) a couple of _isXxx functions that had single uses.

I replaced chpl__isRange() with isRange(), and analogously
for a couple of others.

There are a few other functions whose names start with _
that I did not address in this commit.

TODO: handle _isPrimitiveType - Brad has a patch for it.


DETAILED NOTES

The above functions on types have all been there already, so this
patch renames some of them -- see the script below for details -- plus
reorganizes them somewhat.

The above functions on values were mostly missing, so this patch
adds them, plus reorganizes and/or renames a couple of them.

I added the pragma "no instantiation limit" to the type-oriented queries
for consistency with what has been in Types.chpl already.
We might need to add it to the value-oriented queries.

I needed to change chpl__isType -> isType in the compiler.
The other subdirs, e.g. spec or runtime, did not seem to need it.

Most diffs in this commit are due to uses of the above functions.
The diffs due to definition changes are mostly in:

modules/internal/ChapelBase.chpl  (at the bottom of the diffs)
modules/internal/ChapelSyncvar.chpl
modules/internal/ChapelTuple.chpl
modules/standard/Types.chpl  (most def changes are here)


For archiving purposes - I used this script to do the renaming:

---------------------------------
```python
#!/usr/bin/env python

import sys, os, shutil, subprocess, string, signal
import re

verbose = True
vv = False
vrepl = True

# Pairs "from name", "to name".
# Ordered by the "to name". Aggregate queries are all at the bottom.
#
replspec = [
#  ("isArrayType",       "isArray"),
#  ("isAtomicType",      "isAtomic"),
  ("_isBooleanType",    "isBoolType"),
#  ("isClassType",       "isClass"),
  ("_isComplexType",    "isComplexType"),
#  ("isDmapType",        "isDmap"),
#  ("isDomainType",      "isDomain"),
  ("_isEnumeratedType", "isEnumType"),
  ("_isImagType",       "isImagType"),
  ("_isSignedType",     "isIntType"),
#  ("isRangeType",       "isRange"),
  ("_isRealType",       "isRealType"),
#  ("isRecordType",      "isRecord"),
  ("_isSingleType",     "isSingleType"),
  ("_isSingle",         "isSingle"),
  ("_isSyncType",       "isSyncType"),
  ("_isSync",           "isSync"),
#  ("isTupleType",       "isTuple"),
  ("_isUnsignedType",   "isUintType"),
#  ("isUnionType",       "isUnion"),
#
  ("_isIntegralType",   "isIntegralType"),
  ("_isFloatType",      "isFloatType"),
  ("_isNumericType",    "isNumericType"),
#
  ("chpl__isType",      "isType"),
  ("chpl__isRange",  "isRange"),
  ("chpl__isDomain", "isDomain"),
  ("chpl__isArray",  "isArray"),
  ("chpl__isDmap",   "isDmap"),
]

if vv:
  print replspec

def REPL(sfrom, sto):
  sfromW = '\\b' + sfrom + '\\b'
  global srcContents
  (srcContents, cnt) = re.subn(sfromW, sto, srcContents)
  if cnt > 0 and vrepl:
    sys.stdout.write("%4d  %20s -> %10s\n"%(cnt, sfrom, sto))
  return cnt

print "starting", "\n"

# invoke from CHPL_HOME
# I also ran similar incantations on subdirs: compiler runtime spec
sourcesStream = os.popen("find modules* test -name \\*.chpl")
for srcName in sourcesStream:
  srcName = srcName.rstrip()
  if os.path.isdir(srcName):
    print "=== ", srcName, " ===  directory"
    continue
  print "=== ", srcName, " ==="
  srcFile = open(srcName)
  srcContents = srcFile.read()
  srcFile.close()
  if vv:
    print srcContents
  cnt = 0
  for replPair in replspec:
    cnt += REPL(replPair[0], replPair[1])

  if vv:
    print "totalreplaced: ", cnt
    print srcContents

  if cnt > 0:
    sys.stdout.write("updating%5d  repls  %s\n"%(cnt, srcName))
    shutil.move(srcName, srcName+".bak")
    srcRepl = open(srcName, 'w')
    srcRepl.write(srcContents)
    srcRepl.close()
    

print "done"
sourcesStream.close()
```
---------------------------------


The change looks good to me however it gets in (assuming it passes 
testing).  The one other cleanup that it appears to me (belatedly)
that could probably be done is to remove the cast to :t in the
default real/imag cases (since the literals themselves are, by definition, 
of the default size) -- unless I'm missing something.

I'm unclear whether Vass is still trying to get is*Type in for the feature 
freeze or not.  I think this change could go in for either feature or code 
freeze and suggest we do apply it even if is*Type does not get in (though 
I'd like to see it go in given that it's pretty low-hanging fruit and has 
been outstanding for a long time now).

-Brad


On Fri, 5 Sep 2014, Lydia Duncan wrote:

>>  // TODO: In order to make _defaultOf param for reals and imags we had to split
>>  // the cases into their default size and a non-param case.  It is hoped that
>>  // in the future, floating point numbers may be castable whilst param.  In that
>>  // world, we can again shrink these calls into the size-ignorant case.
>>  inline proc _defaultOf(type t) param where t == real(64) return 0.0:t;
>> -inline proc _defaultOf(type t) where (_isRealType(t) && t != real(64)) return 0.0:t;
>> +inline proc _defaultOf(type t) where (isRealType(t) && t != real(64)) return 0.0:t;
>
> Just remembered I had that tab open.  I have a branch on my fork related to that change: https://github.com/lydia-duncan/chapel/tree/defaultOfRealDefault.  It's pretty trivial to do.  @vasslitvinov, would you like me to merge it into master or would you want to resolve the conflict by putting it in yourself?
>
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/chapel-lang/chapel/pull/212/files#r17183538
>