types.sh revision 7c2fbfb345896881c631598ee3852ce9ce33fb07
########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2008 AT&T Intellectual Property #
# and is licensed under the #
# Common Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# David Korn <dgk@research.att.com> #
# #
########################################################################
function err_exit
{
print -u2 -n "\t"
}
alias err_exit='err_exit $LINENO'
integer Errors=0
integer n=2
typeset -T Type_t=(
typeset -i z=5
)
for ((i=0; i < 10; i++))
do
Type_t r s
typeset -C x=r.x
typeset -C z=y
typeset -C s.y=z
.sh.q=$y
function foo
{
nameref x=$1 y=$2
typeset z=$x
y=$x
}
typeset -C y=z
typeset -C y=z
(
q=${z}
z=abc
)
done
[[ $(typeset -p frame) == 'Frame_t frame=(typeset file;typeset lineno;)' ]] || err_exit 'empty fields in type not displayed'
typeset -C y=x
for ((i=0; i < 1; i++))
do typeset -m zzz=x
typeset -m x=zzz
typeset -m r=t
typeset -m t=r
done
unset x y zzz
x=(a b c)
typeset -m x[1]=x[2]
typeset -T Pt_t=(float x=1. y=0.)
Pt_t p=(y=2)
print -r -- ${p.y}
+++
expected=2
[[ "$got" == "$expected" ]] || err_exit "typedefs in dot script failed -- expected '$expected', got '$got'"
typeset -T X_t=(
typeset s=${_.x}
create()
{
}
)
X_t x
Y_t z
typeset -T X_t=(
f()
{
print ok
}
)
+++
typeset -T X_t=(
x=1
f()
{
print ok
}
)
X_t z=(
function f
{
print override f
}
)
+++
typeset -T X_t=(
x=1
f()
{
print ok
}
)
X_t z=(
function g
{
print override f
}
)
+++
# compound variables containing type variables
Type_t r
var=(
typeset x=foobar
Type_t r
integer z=5
)
typeset -T A_t=(
typeset x=aha
typeset b=${_.x}
)
unset x
A_t x
[[ "$got" == "$expected" ]] || err_exit "type '_' reference failed -- expected '$expected', got '$got'"
typeset -T Tst_t=(
function f
{
A_t a
}
function g
{
print foo
}
)
[[ "$got" == "$expected" ]] || err_exit "_.g where g is a function in type discipline method failed -- expected '$expected', got '$got'"
typeset -T B_t=(
integer -a arr
function f
{
print ${_.arr[*]}
}
)
unset x
B_t x
expected='0 1'
[[ "$got" == "$expected" ]] || err_exit "array assignment of subscripts in type discipline arithmetic failed -- expected '$expected', got '$got'"
typeset -T Fileinfo_t=(
size=-1
typeset -a text=()
integer mtime=-1
)
function bar
{
finfo.size=${#finfo.text[@]}
}
expected='Fileinfo_t -A _Dbg_filenames=([foo]=(size=2;typeset -C -a text=([0]=line1 [1]=line2 [2]=line3);typeset -l -i mtime=-1;))'
got=$(typeset -p _Dbg_filenames)
err_exit "copy to associative array of types in function failed -- expected '$expected', got '$got'"
}
function f1
{
typeset -n v=$1
print -r -- "$v"
}
typeset -T A_t=(
function f { f1 _ ;}
)
A_t a
+++++
exit $Errors