Tcl Source Code

Hex Artifact Content
Login

Artifact 1eaf4c692bac903d8dc6e79cd393971a59323cd0:

Attachment "Resolver.3" to ticket [218101ffff] added by andreas_kupries 2006-03-17 23:40:25.
0000: 27 5c 22 0a 27 5c 22 20 43 6f 70 79 72 69 67 68  '\".'\" Copyrigh
0010: 74 20 28 63 29 20 32 30 30 35 20 47 65 6f 72 67  t (c) 2005 Georg
0020: 65 20 50 65 74 65 72 20 53 74 61 70 6c 69 6e 0a  e Peter Staplin.
0030: 27 5c 22 0a 27 5c 22 20 53 65 65 20 74 68 65 20  '\".'\" See the 
0040: 66 69 6c 65 20 22 6c 69 63 65 6e 73 65 2e 74 65  file "license.te
0050: 72 6d 73 22 20 66 6f 72 20 69 6e 66 6f 72 6d 61  rms" for informa
0060: 74 69 6f 6e 20 6f 6e 20 75 73 61 67 65 20 61 6e  tion on usage an
0070: 64 20 72 65 64 69 73 74 72 69 62 75 74 69 6f 6e  d redistribution
0080: 0a 27 5c 22 20 6f 66 20 74 68 69 73 20 66 69 6c  .'\" of this fil
0090: 65 2c 20 61 6e 64 20 66 6f 72 20 61 20 44 49 53  e, and for a DIS
00a0: 43 4c 41 49 4d 45 52 20 4f 46 20 41 4c 4c 20 57  CLAIMER OF ALL W
00b0: 41 52 52 41 4e 54 49 45 53 2e 0a 27 5c 22 20 0a  ARRANTIES..'\" .
00c0: 27 5c 22 20 52 43 53 3a 20 40 28 23 29 20 24 49  '\" RCS: @(#) $I
00d0: 64 24 0a 27 5c 22 20 0a 2e 73 6f 20 6d 61 6e 2e  d$.'\" ..so man.
00e0: 6d 61 63 72 6f 73 0a 2e 54 48 20 54 63 6c 5f 41  macros..TH Tcl_A
00f0: 64 64 49 6e 74 65 72 70 52 65 73 6f 6c 76 65 72  ddInterpResolver
0100: 73 20 33 20 38 2e 35 20 54 63 6c 20 22 54 63 6c  s 3 8.5 Tcl "Tcl
0110: 20 4c 69 62 72 61 72 79 20 50 72 6f 63 65 64 75   Library Procedu
0120: 72 65 73 22 0a 2e 42 53 0a 2e 53 48 20 4e 41 4d  res"..BS..SH NAM
0130: 45 0a 54 63 6c 5f 41 64 64 49 6e 74 65 72 70 52  E.Tcl_AddInterpR
0140: 65 73 6f 6c 76 65 72 73 2c 20 54 63 6c 5f 47 65  esolvers, Tcl_Ge
0150: 74 49 6e 74 65 72 70 52 65 73 6f 6c 76 65 72 73  tInterpResolvers
0160: 2c 20 54 63 6c 5f 52 65 6d 6f 76 65 49 6e 74 65  , Tcl_RemoveInte
0170: 72 70 52 65 73 6f 6c 76 65 72 73 2c 20 54 63 6c  rpResolvers, Tcl
0180: 5f 53 65 74 4e 61 6d 65 73 70 61 63 65 52 65 73  _SetNamespaceRes
0190: 6f 6c 76 65 72 73 2c 20 54 63 6c 5f 47 65 74 4e  olvers, Tcl_GetN
01a0: 61 6d 65 73 70 61 63 65 52 65 73 6f 6c 76 65 72  amespaceResolver
01b0: 73 20 5c 2d 20 4d 61 6e 69 70 75 6c 61 74 65 20  s \- Manipulate 
01c0: 63 6f 6d 6d 61 6e 64 2f 76 61 72 69 61 62 6c 65  command/variable
01d0: 20 72 65 73 6f 6c 75 74 69 6f 6e 20 66 75 6e 63   resolution func
01e0: 74 69 6f 6e 73 20 66 6f 72 20 61 6e 20 69 6e 74  tions for an int
01f0: 65 72 70 72 65 74 65 72 20 6f 72 20 6e 61 6d 65  erpreter or name
0200: 73 70 61 63 65 2e 0a 2e 53 48 20 53 59 4e 4f 50  space...SH SYNOP
0210: 53 49 53 0a 2e 6e 66 0a 5c 66 42 23 69 6e 63 6c  SIS..nf.\fB#incl
0220: 75 64 65 20 3c 74 63 6c 49 6e 74 2e 68 3e 5c 66  ude <tclInt.h>\f
0230: 52 0a 2e 73 70 0a 76 6f 69 64 0a 5c 66 42 54 63  R..sp.void.\fBTc
0240: 6c 5f 41 64 64 49 6e 74 65 72 70 52 65 73 6f 6c  l_AddInterpResol
0250: 76 65 72 73 5c 66 52 28 5c 66 49 69 6e 74 65 72  vers\fR(\fIinter
0260: 70 2c 20 6e 61 6d 65 2c 20 63 6d 64 50 72 6f 63  p, name, cmdProc
0270: 2c 20 76 61 72 50 72 6f 63 2c 20 63 6f 6d 70 69  , varProc, compi
0280: 6c 65 64 56 61 72 50 72 6f 63 5c 66 52 29 0a 2e  ledVarProc\fR)..
0290: 73 70 0a 69 6e 74 0a 5c 66 42 54 63 6c 5f 47 65  sp.int.\fBTcl_Ge
02a0: 74 49 6e 74 65 72 70 52 65 73 6f 6c 76 65 72 73  tInterpResolvers
02b0: 5c 66 52 28 5c 66 49 69 6e 74 65 72 70 2c 20 6e  \fR(\fIinterp, n
02c0: 61 6d 65 2c 20 72 65 73 49 6e 66 6f 50 74 72 5c  ame, resInfoPtr\
02d0: 66 52 29 0a 2e 73 70 0a 69 6e 74 0a 5c 66 42 54  fR)..sp.int.\fBT
02e0: 63 6c 5f 52 65 6d 6f 76 65 49 6e 74 65 72 70 52  cl_RemoveInterpR
02f0: 65 73 6f 6c 76 65 72 73 5c 66 52 28 5c 66 49 69  esolvers\fR(\fIi
0300: 6e 74 65 72 70 2c 20 6e 61 6d 65 5c 66 52 29 0a  nterp, name\fR).
0310: 2e 73 70 0a 76 6f 69 64 0a 5c 66 42 54 63 6c 5f  .sp.void.\fBTcl_
0320: 53 65 74 4e 61 6d 65 73 70 61 63 65 52 65 73 6f  SetNamespaceReso
0330: 6c 76 65 72 73 5c 66 52 28 5c 66 49 6e 61 6d 65  lvers\fR(\fIname
0340: 73 70 61 63 65 50 74 72 2c 20 63 6d 64 50 72 6f  spacePtr, cmdPro
0350: 63 2c 20 76 61 72 50 72 6f 63 2c 20 63 6f 6d 70  c, varProc, comp
0360: 69 6c 65 64 56 61 72 50 72 6f 63 5c 66 52 29 0a  iledVarProc\fR).
0370: 2e 73 70 0a 69 6e 74 0a 5c 66 42 54 63 6c 5f 47  .sp.int.\fBTcl_G
0380: 65 74 4e 61 6d 65 73 70 61 63 65 52 65 73 6f 6c  etNamespaceResol
0390: 76 65 72 73 5c 66 52 28 5c 66 49 6e 61 6d 65 73  vers\fR(\fInames
03a0: 70 61 63 65 50 74 72 2c 20 72 65 73 49 6e 66 6f  pacePtr, resInfo
03b0: 50 74 72 5c 66 52 29 0a 0a 2e 53 48 20 41 52 47  Ptr\fR)...SH ARG
03c0: 55 4d 45 4e 54 53 0a 2e 41 53 20 54 63 6c 5f 49  UMENTS..AS Tcl_I
03d0: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 20 69 6e  nterp *interp in
03e0: 0a 2e 41 50 20 22 63 6f 6e 73 74 20 63 68 61 72  ..AP "const char
03f0: 22 20 2a 6e 61 6d 65 20 69 6e 20 0a 6e 61 6d 65  " *name in .name
0400: 20 6f 66 20 74 68 65 20 72 65 73 6f 6c 75 74 69   of the resoluti
0410: 6f 6e 20 73 63 68 65 6d 65 2e 0a 2e 41 50 20 54  on scheme...AP T
0420: 63 6c 5f 52 65 73 6f 6c 76 65 43 6d 64 50 72 6f  cl_ResolveCmdPro
0430: 63 20 2a 63 6d 64 50 72 6f 63 20 69 6e 0a 6e 65  c *cmdProc in.ne
0440: 77 20 66 75 6e 63 74 69 6f 6e 20 66 6f 72 20 63  w function for c
0450: 6f 6d 6d 61 6e 64 20 72 65 73 6f 6c 75 74 69 6f  ommand resolutio
0460: 6e 2e 0a 2e 41 50 20 54 63 6c 5f 52 65 73 6f 6c  n...AP Tcl_Resol
0470: 76 65 56 61 72 50 72 6f 63 20 2a 76 61 72 50 72  veVarProc *varPr
0480: 6f 63 20 69 6e 0a 66 75 6e 63 74 69 6f 6e 20 66  oc in.function f
0490: 6f 72 20 76 61 72 69 61 62 6c 65 20 72 65 73 6f  or variable reso
04a0: 6c 75 74 69 6f 6e 20 61 74 20 72 75 6e 74 69 6d  lution at runtim
04b0: 65 2e 0a 2e 41 50 20 54 63 6c 5f 52 65 73 6f 6c  e...AP Tcl_Resol
04c0: 76 65 43 6f 6d 70 69 6c 65 64 56 61 72 50 72 6f  veCompiledVarPro
04d0: 63 20 2a 63 6f 6d 70 69 6c 65 64 56 61 72 50 72  c *compiledVarPr
04e0: 6f 63 20 69 6e 0a 66 75 6e 63 74 69 6f 6e 20 66  oc in.function f
04f0: 6f 72 20 76 61 72 69 61 62 6c 65 20 72 65 73 6f  or variable reso
0500: 6c 75 74 69 6f 6e 20 61 74 20 63 6f 6d 70 69 6c  lution at compil
0510: 65 20 74 69 6d 65 2e 0a 2e 41 50 20 54 63 6c 5f  e time...AP Tcl_
0520: 52 65 73 6f 6c 76 65 72 49 6e 66 6f 20 2a 72 65  ResolverInfo *re
0530: 73 49 6e 66 6f 50 74 72 20 6f 75 74 20 0a 70 6f  sInfoPtr out .po
0540: 69 6e 74 65 72 20 74 6f 20 61 20 73 74 72 75 63  inter to a struc
0550: 74 75 72 65 20 77 69 74 68 20 74 68 65 20 63 6f  ture with the co
0560: 6d 6d 61 6e 64 2c 20 76 61 72 2c 20 61 6e 64 20  mmand, var, and 
0570: 63 6f 6d 70 69 6c 65 64 20 76 61 72 20 72 65 73  compiled var res
0580: 6f 6c 75 74 69 6f 6e 20 70 72 6f 63 65 64 75 72  olution procedur
0590: 65 20 70 6f 69 6e 74 65 72 73 2e 0a 2e 42 45 0a  e pointers...BE.
05a0: 0a 2e 53 48 20 44 45 53 43 52 49 50 54 49 4f 4e  ..SH DESCRIPTION
05b0: 0a 2e 50 50 0a 54 68 65 73 65 20 72 6f 75 74 69  ..PP.These routi
05c0: 6e 65 73 20 61 72 65 20 75 73 65 64 20 74 6f 20  nes are used to 
05d0: 63 72 65 61 74 65 20 6e 61 6d 65 64 20 72 65 73  create named res
05e0: 6f 6c 75 74 69 6f 6e 20 73 63 68 65 6d 65 73 2e  olution schemes.
05f0: 20 20 52 65 73 6f 6c 75 74 69 6f 6e 20 73 63 68    Resolution sch
0600: 65 6d 65 73 20 63 61 6e 20 62 65 20 63 72 65 61  emes can be crea
0610: 74 65 64 20 74 68 61 74 20 68 6f 6f 6b 20 69 6e  ted that hook in
0620: 74 6f 20 74 68 65 20 54 63 6c 20 69 6e 74 65 72  to the Tcl inter
0630: 6e 61 6c 73 20 74 6f 20 61 6c 6c 6f 77 20 66 6f  nals to allow fo
0640: 72 20 6d 6f 64 69 66 69 63 61 74 69 6f 6e 20 6f  r modification o
0650: 66 20 62 65 68 61 76 69 6f 72 2e 20 20 54 68 65  f behavior.  The
0660: 20 6e 61 6d 65 20 72 65 73 6f 6c 75 74 69 6f 6e   name resolution
0670: 20 68 6f 6f 6b 73 20 63 61 6e 20 62 65 20 75 73   hooks can be us
0680: 65 64 20 66 6f 72 20 72 75 6e 74 69 6d 65 20 76  ed for runtime v
0690: 61 72 69 61 62 6c 65 73 2c 20 63 6f 6d 6d 61 6e  ariables, comman
06a0: 64 73 2c 20 61 6e 64 20 63 6f 6d 70 69 6c 61 74  ds, and compilat
06b0: 69 6f 6e 2d 74 69 6d 65 20 76 61 72 69 61 62 6c  ion-time variabl
06c0: 65 73 2e 0a 0a 2e 50 50 0a 5c 66 42 54 63 6c 5f  es....PP.\fBTcl_
06d0: 41 64 64 49 6e 74 65 72 70 52 65 73 6f 6c 76 65  AddInterpResolve
06e0: 72 73 5c 66 52 20 61 63 63 65 70 74 73 20 70 61  rs\fR accepts pa
06f0: 72 61 6d 65 74 65 72 73 20 66 6f 72 20 74 68 65  rameters for the
0700: 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 72 65 73   name of the res
0710: 6f 6c 75 74 69 6f 6e 20 73 63 68 65 6d 65 2c 20  olution scheme, 
0720: 74 68 65 20 63 6d 64 50 72 6f 63 20 28 77 68 69  the cmdProc (whi
0730: 63 68 20 6d 61 79 20 62 65 20 4e 55 4c 4c 20 3f  ch may be NULL ?
0740: 29 2c 20 74 68 65 20 76 61 72 50 72 6f 63 20 28  ), the varProc (
0750: 77 68 69 63 68 20 6d 61 79 20 62 65 20 4e 55 4c  which may be NUL
0760: 4c 20 3f 29 2c 20 61 6e 64 20 74 68 65 20 63 6f  L ?), and the co
0770: 6d 70 69 6c 65 64 56 61 72 50 72 6f 63 20 28 5b  mpiledVarProc ([
0780: 6d 61 79 20 69 74 20 61 6c 73 6f 20 62 65 20 4e  may it also be N
0790: 55 4c 4c 3f 5d 29 2e 20 20 4e 61 6d 65 73 70 61  ULL?]).  Namespa
07a0: 63 65 20 72 65 73 6f 6c 76 65 72 73 20 74 61 6b  ce resolvers tak
07b0: 65 20 70 72 65 63 65 64 65 6e 63 65 20 6f 76 65  e precedence ove
07c0: 72 20 72 65 73 6f 6c 76 65 72 73 20 61 64 64 65  r resolvers adde
07d0: 64 20 77 69 74 68 20 74 68 69 73 20 66 75 6e 63  d with this func
07e0: 74 69 6f 6e 2e 20 20 53 65 65 20 61 6c 73 6f 20  tion.  See also 
07f0: 5c 66 42 54 63 6c 5f 53 65 74 4e 61 6d 65 73 70  \fBTcl_SetNamesp
0800: 61 63 65 52 65 73 6f 6c 76 65 72 73 5c 66 52 20  aceResolvers\fR 
0810: 62 65 6c 6f 77 2e 0a 2e 50 50 0a 5c 66 42 54 63  below...PP.\fBTc
0820: 6c 5f 47 65 74 49 6e 74 65 72 70 52 65 73 6f 6c  l_GetInterpResol
0830: 76 65 72 73 5c 66 52 20 61 63 63 65 70 74 73 20  vers\fR accepts 
0840: 70 61 72 61 6d 65 74 65 72 73 20 66 6f 72 20 74  parameters for t
0850: 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 72  he name of the r
0860: 65 73 6f 6c 75 74 69 6f 6e 20 73 63 68 65 6d 65  esolution scheme
0870: 2e 20 20 49 66 20 73 75 63 63 65 73 73 66 75 6c  .  If successful
0880: 20 69 74 20 72 65 74 75 72 6e 73 20 74 68 65 20   it returns the 
0890: 63 6d 64 50 72 6f 63 2c 20 76 61 72 52 65 73 50  cmdProc, varResP
08a0: 72 6f 63 2c 20 61 6e 64 20 63 6f 6d 70 69 6c 65  roc, and compile
08b0: 64 56 61 72 52 65 73 50 72 6f 63 20 76 69 61 20  dVarResProc via 
08c0: 61 20 70 61 73 73 65 64 20 70 6f 69 6e 74 65 72  a passed pointer
08d0: 20 74 6f 20 61 20 70 72 65 76 69 6f 75 73 6c 79   to a previously
08e0: 20 61 6c 6c 6f 63 61 74 65 64 20 54 63 6c 5f 52   allocated Tcl_R
08f0: 65 73 6f 6c 76 65 72 49 6e 66 6f 20 73 74 72 75  esolverInfo stru
0900: 63 74 2e 20 20 31 20 69 73 20 72 65 74 75 72 6e  ct.  1 is return
0910: 65 64 20 69 66 20 74 68 65 20 72 65 73 6f 6c 76  ed if the resolv
0920: 65 72 20 73 63 68 65 6d 65 20 69 73 20 66 6f 75  er scheme is fou
0930: 6e 64 2e 20 20 30 20 69 73 20 72 65 74 75 72 6e  nd.  0 is return
0940: 65 64 20 69 66 20 74 68 65 20 72 65 73 6f 6c 76  ed if the resolv
0950: 65 72 20 73 63 68 65 6d 65 20 63 6f 75 6c 64 20  er scheme could 
0960: 6e 6f 74 20 62 65 20 66 6f 75 6e 64 2e 0a 2e 50  not be found...P
0970: 50 0a 5c 66 42 54 63 6c 5f 52 65 6d 6f 76 65 49  P.\fBTcl_RemoveI
0980: 6e 74 65 72 70 52 65 73 6f 6c 76 65 72 73 5c 66  nterpResolvers\f
0990: 52 20 61 63 63 65 70 74 73 20 74 68 65 20 6e 61  R accepts the na
09a0: 6d 65 20 6f 66 20 61 20 72 65 73 6f 6c 75 74 69  me of a resoluti
09b0: 6f 6e 20 73 63 68 65 6d 65 2e 20 20 31 20 69 73  on scheme.  1 is
09c0: 20 72 65 74 75 72 6e 65 64 20 77 68 65 6e 20 74   returned when t
09d0: 68 65 20 72 65 73 6f 6c 76 65 72 20 73 63 68 65  he resolver sche
09e0: 6d 65 20 77 61 73 20 66 6f 75 6e 64 20 61 6e 64  me was found and
09f0: 20 72 65 6d 6f 76 65 64 2e 20 20 30 20 69 73 20   removed.  0 is 
0a00: 72 65 74 75 72 6e 65 64 20 77 68 65 6e 20 74 68  returned when th
0a10: 65 20 72 65 73 6f 6c 76 65 72 20 73 63 68 65 6d  e resolver schem
0a20: 65 20 77 61 73 20 6e 6f 74 20 66 6f 75 6e 64 2e  e was not found.
0a30: 0a 2e 50 50 0a 5c 66 42 54 63 6c 5f 53 65 74 4e  ..PP.\fBTcl_SetN
0a40: 61 6d 65 73 70 61 63 65 52 65 73 6f 6c 76 65 72  amespaceResolver
0a50: 73 5c 66 52 20 68 61 73 20 62 65 68 61 76 69 6f  s\fR has behavio
0a60: 72 20 73 69 6d 69 6c 61 72 20 74 6f 20 5c 66 42  r similar to \fB
0a70: 54 63 6c 5f 41 64 64 49 6e 74 65 72 70 52 65 73  Tcl_AddInterpRes
0a80: 6f 6c 76 65 72 73 5c 66 52 2c 20 77 69 74 68 20  olvers\fR, with 
0a90: 74 68 65 20 65 78 63 65 70 74 69 6f 6e 20 62 65  the exception be
0aa0: 69 6e 67 20 74 68 61 74 20 69 74 20 74 61 6b 65  ing that it take
0ab0: 73 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 61  s a pointer to a
0ac0: 20 54 63 6c 5f 4e 61 6d 65 73 70 61 63 65 2c 20   Tcl_Namespace, 
0ad0: 72 61 74 68 65 72 20 74 68 61 6e 20 61 20 54 63  rather than a Tc
0ae0: 6c 5f 49 6e 74 65 72 70 2e 0a 2e 50 50 0a 5c 66  l_Interp...PP.\f
0af0: 42 54 63 6c 5f 47 65 74 4e 61 6d 65 73 70 61 63  BTcl_GetNamespac
0b00: 65 52 65 73 6f 6c 76 65 72 73 5c 66 52 20 68 61  eResolvers\fR ha
0b10: 73 20 62 65 68 61 76 69 6f 72 20 73 69 6d 69 6c  s behavior simil
0b20: 61 72 20 74 6f 20 5c 66 42 54 63 6c 5f 47 65 74  ar to \fBTcl_Get
0b30: 49 6e 74 65 72 70 52 65 73 6f 6c 76 65 72 73 5c  InterpResolvers\
0b40: 66 52 2c 20 77 69 74 68 20 74 68 65 20 65 78 63  fR, with the exc
0b50: 65 70 74 69 6f 6e 20 74 68 61 74 20 69 74 20 74  eption that it t
0b60: 61 6b 65 73 20 61 20 70 6f 69 6e 74 65 72 20 74  akes a pointer t
0b70: 6f 20 61 20 54 63 6c 5f 4e 61 6d 65 73 70 61 63  o a Tcl_Namespac
0b80: 65 2c 20 72 61 74 68 65 72 20 74 68 61 6e 20 61  e, rather than a
0b90: 20 54 63 6c 5f 49 6e 74 65 72 70 2e 0a 0a 2e 53   Tcl_Interp....S
0ba0: 48 20 42 55 47 53 0a 2e 50 50 0a 54 68 65 72 65  H BUGS..PP.There
0bb0: 20 69 73 20 6e 6f 74 20 63 75 72 72 65 6e 74 6c   is not currentl
0bc0: 79 20 61 20 77 61 79 20 74 6f 20 72 65 6d 6f 76  y a way to remov
0bd0: 65 20 61 20 6e 61 6d 65 73 70 61 63 65 20 72 65  e a namespace re
0be0: 73 6f 6c 76 65 72 2e 0a 0a 2e 53 48 20 4b 45 59  solver....SH KEY
0bf0: 57 4f 52 44 53 0a 72 65 73 6f 6c 76 69 6e 67 2c  WORDS.resolving,
0c00: 20 72 65 73 6f 6c 76 65 2c 20 72 65 73 6f 6c 76   resolve, resolv
0c10: 65 72 2c 20 6e 61 6d 65 73 70 61 63 65 2c 20 63  er, namespace, c
0c20: 6f 6d 6d 61 6e 64 20 72 65 73 6f 6c 75 74 69 6f  ommand resolutio
0c30: 6e 2c 20 72 65 73 6f 6c 75 74 69 6f 6e 0a        n, resolution.