FoxFingerPrinter.Mod 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387
  1. MODULE FoxFingerPrinter; (** AUTHOR "fof"; PURPOSE "FingerPrinting"; *)
  2. (* literature for the fingerprinting: Dissertation Crelier *)
  3. IMPORT SyntaxTree := FoxSyntaxTree, Basic := FoxBasic, SYSTEM, Global := FoxGlobal,Scanner := FoxScanner,
  4. D := Debugging, Streams;
  5. (** FingerPrinting
  6. FP(TypeDeclaration) = 0 <*> fpModeType -> Name -> Visibility <*> FP(Type).
  7. FP(ConstantDeclaration) = 0 <*> fpModeConstant -> Name -> Visibility <*> FP(Type) -> Basic -> Value.
  8. FP(VariableDeclaration) = 0 <*> fpModePar -> Name -> Visibility <*> FP(Type).
  9. FP(ProcedureDeclaration) = 0 <*> fpModeInlineProcedure -> Name -> Visibility <*> FP(Type) -> Code.
  10. | 0 <*> fpModeExportedProcedure -> Name -> Visibility <*> FP(Type)
  11. Name(fp,name) = fp <*> name[0] <*> ... <*> name[n].
  12. Visibility(fp,vis) = fp <*> fpExtern | fp <*> fpExternR | fp <*> fpOther <*> vis.
  13. Value(fp) = fp <*> fpTrue | fp <*> fpFalse | fp <*> integer | fp <*> intlow <*> inthigh | fp -> Name
  14. FP(Type) = FP(BasicType) | FP(RecordType) | FP(PointerType)
  15. | FP(ArrayType) | FP(MathArrayType) | FP(ProcedurType)
  16. FP(BasicType) = fpTypeChar8 | fpTypeChar16 | fpTypeChar32
  17. | fpTypeShortint | fpTypeInteger | fpTypeLongint | fpTypeHugeint
  18. | fpTypeReal | fpTypeLongreal
  19. | fpTypeSet | fpTypePointer |fpTypeString
  20. | fpTypeByte | fpTypeAll | fpTypeSame | fpTypeRange | fpTypeBoolean.
  21. PublicFP(BasicType) = FP(basicType).
  22. PrivateFP(BasicType) = sizeof(basicType).
  23. FP(RecordType) = fpTypeComposite <*> fptypeRecord
  24. [ -> Name(moduleName) -> Name(typeName)] [<*> FP(baseType)]
  25. PublicFP(RecordType) = FP(recordType) [<*> PublicFP(baseType)] {<*> FP(method) <*> methodNumber }
  26. {<*> PublicFP(fieldType) <*> offset(field) <*> FP(field)} <*> flags.
  27. PrivateFP(RecordType) = FP(recordType) [<*> PrivateFP(baseType)] {<*> FP(method) <*> methodNumber }
  28. {<*> PrivateFP(fieldType) <*> offset(field) <*> FP(field)}
  29. FP(Method) = 0 <*> fpModeMethod -> Name(methodName) -> Signature(method).
  30. FP(Field) = 0 <*> fpModeField -> Name(fieldName) -> Visibility [<*> fpUntraced] <*> FP(type).
  31. FP(PointerType) = fpTypePointer <*> fpTypeBasic -> Name <*> FP(baseType).
  32. PublicFP(PointerType) = 0.
  33. PrivateFP(PointerType) = 0.
  34. FP(ArrayType) = fpTypeComposite <*> (fpTypeOpenArray | fpTypeStaticArray)
  35. -> Name <*> FP(baseType) [<*> length].
  36. PublicFP(ArrayType) = FP(arrayType).
  37. PrivateFP(ArrayType) = FP(arrayType).
  38. FP(MathArrayType) = fpTypeComposite <*> (fpTypeOpenArray | fpTypeStaticArray)
  39. -> Name <*> FP(baseType) [<*> length].
  40. PublicFP(MathArrayType) = FP(arrayType).
  41. PrivateFP(MathArrayType) = FP(arrayType).
  42. FP(ProcedureType) = fpTypeProcedure <*> fpTypeBasic [<*> fpDelegate]-> Name.
  43. PublicFP(ProcedureType) = FP(arrayType) -> Signature(procedureType)
  44. PrivateFP(ProcedureType) = FP(arrayType)-> Signature(procedureType).
  45. Signature(f) = f <*> FP(returnType)
  46. { <*> (fpModeVarParameter | fpModeConstParameter | fpModePar)
  47. <*> FP(parameterType) [-> Name(parameterName)] }
  48. **)
  49. CONST
  50. (*FingerPrints/Obj Modes*)
  51. fpModeVar=1;
  52. fpModePar=1;
  53. fpModeVarPar=2;
  54. fpModeConstPar=fpModeVarPar; (*! for compatibility, must be changed *)
  55. fpModeConst=3;
  56. fpModeField=4;
  57. fpModeType=5;
  58. fpModeExportedProcedure=7;
  59. fpModeInlineProcedure=9;
  60. fpModeMethod=13;
  61. (*FingerPrints/Type Forms*)
  62. fpTypeByte = 1;
  63. fpTypeBoolean=2;
  64. fpTypeChar8=3;
  65. fpTypeShortint=4;
  66. fpTypeInteger=5;
  67. fpTypeLongint=6;
  68. fpTypeReal=7;
  69. fpTypeLongreal=8;
  70. fpTypeSet=9;
  71. fpTypeString=10;
  72. fpTypeNone = 12;
  73. fpTypePointer=13;
  74. fpTypeProcedure=14;
  75. fpTypeComposite=15;
  76. fpTypeHugeint=16;
  77. fpTypeChar16 = 17;
  78. fpTypeChar32 = 18;
  79. fpTypeAll = 19;
  80. fpTypeSame = 20;
  81. fpTypeRange = 21;
  82. fpTypeEnum = 22;
  83. fpTypePort = 23;
  84. fpTypeChannel = 23;
  85. fpTypeComplex = 24;
  86. fpTypeLongcomplex = 25;
  87. fpTypeModule=26;
  88. fpTypeSize=27;
  89. fpTypeAddress=28;
  90. fpTypeBasic=1;
  91. fpTypeStaticArray=2;
  92. fpTypeDynamicArray=4;
  93. fpTypeOpenArray=5;
  94. fpTypeRecord=6;
  95. fpIntern=0;
  96. fpExtern=1;
  97. fpExternR=2;
  98. fpOther =3;
  99. fpFalse=0;
  100. fpTrue=1;
  101. fpHasBody = 1;
  102. fpProtected =4;
  103. fpActive = 5;
  104. fpDelegate = 5;
  105. fpSystemType = 6;
  106. fpUntraced = 4;
  107. Trace=FALSE;
  108. TYPE
  109. FingerPrint = SyntaxTree.FingerPrint;
  110. FingerPrinter*= OBJECT (SyntaxTree.Visitor)
  111. VAR
  112. fp-: LONGINT; (* temporary fingerprint for values etc. *)
  113. fingerprint: FingerPrint;
  114. deep: BOOLEAN; (* public / private field of FP needed ? *)
  115. traceLevel: LONGINT;
  116. level: LONGINT;
  117. PROCEDURE & InitFingerPrinter*();
  118. BEGIN fp:= 0; deep := FALSE; traceLevel := 0;
  119. END InitFingerPrinter;
  120. (** types *)
  121. (*
  122. FP(BasicType) = | fpTypeByte | fpTypeAll | fpTypeSame | fpTypeRange | fpTypeBoolean.
  123. | fpTypeSet | fpTypePointer
  124. PublicFP(BasicType) = FP(basicType).
  125. PrivateFP(BasicType) = sizeof(basicType).
  126. *)
  127. PROCEDURE VisitBasicType*(x: SyntaxTree.BasicType);
  128. BEGIN
  129. END VisitBasicType;
  130. PROCEDURE SetTypeFingerprint(x: SyntaxTree.Type; fp: LONGINT);
  131. VAR fingerprint: FingerPrint;
  132. BEGIN
  133. fingerprint := x.fingerprint;
  134. IF ~fingerprint.shallowAvailable THEN
  135. fingerprint.shallow := fp;
  136. fingerprint.public := fp;
  137. fingerprint.private := fp;
  138. fingerprint.shallowAvailable := TRUE;
  139. fingerprint.deepAvailable := TRUE; (* no distinction between deep and shallow fp necessary *)
  140. x.SetFingerPrint(fingerprint);
  141. END;
  142. SELF.fingerprint := fingerprint;
  143. END SetTypeFingerprint;
  144. PROCEDURE VisitRangeType*(x: SyntaxTree.RangeType);
  145. BEGIN
  146. SetTypeFingerprint(x,fpTypeRange);
  147. END VisitRangeType;
  148. PROCEDURE VisitBooleanType*(x: SyntaxTree.BooleanType);
  149. BEGIN
  150. SetTypeFingerprint(x,fpTypeBoolean);
  151. END VisitBooleanType;
  152. PROCEDURE VisitByteType*(x: SyntaxTree.ByteType);
  153. BEGIN
  154. SetTypeFingerprint(x,fpTypeByte)
  155. END VisitByteType;
  156. PROCEDURE VisitSetType*(x: SyntaxTree.SetType);
  157. BEGIN
  158. SetTypeFingerprint(x,fpTypeSet)
  159. END VisitSetType;
  160. PROCEDURE VisitNilType*(x: SyntaxTree.NilType);
  161. BEGIN
  162. SetTypeFingerprint(x,fpTypePointer)
  163. END VisitNilType;
  164. PROCEDURE VisitAnyType*(x: SyntaxTree.AnyType);
  165. BEGIN
  166. SetTypeFingerprint(x,fpTypePointer)
  167. END VisitAnyType;
  168. PROCEDURE VisitAddressType*(x: SyntaxTree.AddressType);
  169. BEGIN
  170. SetTypeFingerprint(x,fpTypeAddress)
  171. END VisitAddressType;
  172. PROCEDURE VisitSizeType*(x: SyntaxTree.SizeType);
  173. BEGIN
  174. SetTypeFingerprint(x, fpTypeSize);
  175. END VisitSizeType;
  176. PROCEDURE VisitObjectType*(x: SyntaxTree.ObjectType);
  177. BEGIN
  178. SetTypeFingerprint(x,fpTypePointer)
  179. END VisitObjectType;
  180. (*
  181. FP(BasicType) = fpTypeChar8 | fpTypeChar16 | fpTypeChar32
  182. PublicFP(BasicType) = FP(basicType).
  183. PrivateFP(BasicType) = sizeof(basicType).
  184. *)
  185. PROCEDURE VisitCharacterType*(x: SyntaxTree.CharacterType);
  186. BEGIN
  187. IF x.sizeInBits = 8 THEN SetTypeFingerprint(x,fpTypeChar8)
  188. ELSIF x.sizeInBits = 16 THEN SetTypeFingerprint(x,fpTypeChar16)
  189. ELSIF x.sizeInBits =32 THEN SetTypeFingerprint(x,fpTypeChar32)
  190. ELSE HALT(100)
  191. END;
  192. END VisitCharacterType;
  193. (*
  194. FP(BasicType) = fpTypeShortint | fpTypeInteger | fpTypeLongint | fpTypeLongint
  195. PublicFP(BasicType) = FP(basicType).
  196. PrivateFP(BasicType) = sizeof(basicType).
  197. *)
  198. PROCEDURE VisitIntegerType*(x: SyntaxTree.IntegerType);
  199. BEGIN
  200. IF x.sizeInBits=8 THEN SetTypeFingerprint(x,fpTypeShortint)
  201. ELSIF x.sizeInBits = 16 THEN SetTypeFingerprint(x,fpTypeInteger)
  202. ELSIF x.sizeInBits = 32 THEN SetTypeFingerprint(x,fpTypeLongint)
  203. ELSIF x.sizeInBits = 64 THEN SetTypeFingerprint(x,fpTypeHugeint)
  204. ELSE HALT(100)
  205. END;
  206. END VisitIntegerType;
  207. (*
  208. FP(BasicType) = fpTypeReal | fpTypeLongreal
  209. PublicFP(BasicType) = FP(basicType).
  210. PrivateFP(BasicType) = sizeof(basicType).
  211. *)
  212. PROCEDURE VisitFloatType*(x: SyntaxTree.FloatType);
  213. BEGIN
  214. IF x.sizeInBits = 32 THEN SetTypeFingerprint(x,fpTypeReal)
  215. ELSIF x.sizeInBits = 64 THEN SetTypeFingerprint(x,fpTypeLongreal)
  216. ELSE HALT(100)
  217. END;
  218. END VisitFloatType;
  219. PROCEDURE VisitComplexType*(x: SyntaxTree.ComplexType);
  220. BEGIN
  221. ASSERT(x.componentType # NIL);
  222. IF x.componentType.sizeInBits = 32 THEN SetTypeFingerprint(x,fpTypeComplex)
  223. ELSIF x.componentType.sizeInBits = 64 THEN SetTypeFingerprint(x,fpTypeLongcomplex)
  224. ELSE HALT(100)
  225. END
  226. END VisitComplexType;
  227. (*
  228. FP(BasicType) = fpStringType
  229. PublicFP(BasicType) = FP(basicType).
  230. PrivateFP(BasicType) = sizeof(basicType).
  231. *)
  232. PROCEDURE VisitStringType*(x: SyntaxTree.StringType);
  233. BEGIN
  234. SetTypeFingerprint(x,fpTypeString);
  235. END VisitStringType;
  236. (**
  237. fp enumeration type
  238. **)
  239. PROCEDURE VisitEnumerationType*(x: SyntaxTree.EnumerationType);
  240. VAR fingerprint: FingerPrint; enumerator: SyntaxTree.Constant; fp: LONGINT;
  241. BEGIN
  242. fingerprint := x.fingerprint;
  243. IF ~fingerprint.shallowAvailable THEN
  244. fp := fpTypeEnum;
  245. IF x.enumerationBase # NIL THEN
  246. FPType(fp,x.enumerationBase);
  247. END;
  248. enumerator := x.enumerationScope.firstConstant;
  249. WHILE enumerator # NIL DO
  250. IF enumerator.access * SyntaxTree.Public # {} THEN
  251. FPName(fp,enumerator.name);
  252. END;
  253. FPValue(fp,enumerator.value);
  254. enumerator := enumerator.nextConstant;
  255. END;
  256. fingerprint.shallow := fp;
  257. fingerprint.public := fingerprint.shallow;
  258. fingerprint.private := fingerprint.shallow;
  259. fingerprint.shallowAvailable := TRUE;
  260. fingerprint.deepAvailable := TRUE; (* no distinction between deep and shallow fp necessary *)
  261. x.SetFingerPrint(fingerprint);
  262. END;
  263. SELF.fingerprint := fingerprint
  264. (*! must be implemented
  265. IF x.enumerationBase # NIL THEN
  266. baseType := ResolveType(x.enumerationBase);
  267. resolved := baseType.resolved;
  268. enumerationBase := resolved(SyntaxTree.EnumerationType);
  269. baseScope := enumerationBase.enumerationScope;
  270. x.SetBaseValue(enumerationBase.baseValue + baseScope.numberEnumerators);
  271. END;
  272. CheckEnumerationScope(x.enumerationScope);
  273. x.SetState(SyntaxTree.Resolved);
  274. END;
  275. resolvedType := ResolvedType(x);
  276. *)
  277. END VisitEnumerationType;
  278. PROCEDURE VisitQualifiedType*(x: SyntaxTree.QualifiedType);
  279. BEGIN
  280. VType(x.resolved);
  281. END VisitQualifiedType;
  282. (*
  283. FP(ArrayType) = fpTypeComposite <*> (fpTypeOpenArray | fpTypeStaticArray)
  284. -> Name <*> FP(baseType) [<*> length].
  285. PublicFP(ArrayType) = FP(arrayType).
  286. PrivateFP(ArrayType) = FP(arrayType).
  287. *)
  288. PROCEDURE VisitArrayType*(x: SyntaxTree.ArrayType);
  289. VAR fingerprint: FingerPrint; deep: BOOLEAN; fp: LONGINT;
  290. BEGIN
  291. IF Trace THEN TraceEnter("ArrayType") END;
  292. fingerprint := x.fingerprint;
  293. deep := SELF.deep;
  294. IF ~fingerprint.shallowAvailable THEN
  295. fingerprint.shallowAvailable := TRUE; (* the fingerprinting may return to itself => avoid circles *)
  296. SELF.deep := FALSE;
  297. fp := 0;
  298. FPNumber(fp,fpTypeComposite);
  299. IF x.form = SyntaxTree.Open THEN FPNumber(fp,fpTypeOpenArray)
  300. ELSIF x.form = SyntaxTree.Static THEN FPNumber(fp,fpTypeStaticArray)
  301. ELSIF x.form = SyntaxTree.SemiDynamic THEN FPNumber(fp, fpTypeDynamicArray);
  302. ELSE HALT(200)
  303. END;
  304. TypeName(fp,x);
  305. fingerprint.shallow := fp;
  306. x.SetFingerPrint(fingerprint);
  307. FPType(fp,x.arrayBase.resolved);
  308. IF x.form = SyntaxTree.Static THEN FPNumber(fp,x.staticLength) END;
  309. fingerprint.shallow := fp;
  310. fingerprint.public := fingerprint.shallow;
  311. fingerprint.private := fingerprint.shallow;
  312. x.SetFingerPrint(fingerprint);
  313. SELF.deep := deep;
  314. END;
  315. IF deep & ~fingerprint.deepAvailable THEN
  316. fingerprint.private := fingerprint.shallow;
  317. fingerprint.public := fingerprint.shallow;
  318. fingerprint.deepAvailable := TRUE; (* to avoid circles during base finger printing *)
  319. x.SetFingerPrint(fingerprint);
  320. VType(x.arrayBase); (* make sure that base pointer is also deeply fped *)
  321. END;
  322. IF Trace THEN TraceExit("ArrayType",fingerprint) END;
  323. SELF.fingerprint := fingerprint;
  324. END VisitArrayType;
  325. (*
  326. FP(MathArrayType) = fpTypeComposite <*> (fpTypeOpenArray | fpTypeStaticArray)
  327. -> Name <*> FP(baseType) [<*> length].
  328. PublicFP(MathArrayType) = FP(arrayType).
  329. PrivateFP(MathArrayType) = FP(arrayType).
  330. *)
  331. PROCEDURE VisitMathArrayType*(x: SyntaxTree.MathArrayType);
  332. VAR fingerprint: FingerPrint; deep: BOOLEAN; fp: LONGINT;
  333. BEGIN
  334. fingerprint := x.fingerprint;
  335. deep := SELF.deep;
  336. IF Trace THEN TraceEnter("MathArrayType") END;
  337. IF ~fingerprint.shallowAvailable THEN
  338. fingerprint.shallowAvailable := TRUE; (* the fingerprinting may return to itself => avoid circles *)
  339. SELF.deep := FALSE;
  340. fp := 0;
  341. FPNumber(fp,fpTypeComposite);
  342. IF x.form = SyntaxTree.Open THEN FPNumber(fp,fpTypeOpenArray)
  343. ELSIF x.form = SyntaxTree.Static THEN FPNumber(fp,fpTypeStaticArray)
  344. ELSIF x.form = SyntaxTree.Tensor THEN (* do nothing *)
  345. ELSE HALT(200)
  346. END;
  347. TypeName(fp,x);
  348. IF x.arrayBase # NIL THEN
  349. FPType(fp,x.arrayBase.resolved);
  350. END;
  351. IF x.form = SyntaxTree.Static THEN FPNumber(fp,x.staticLength) END;
  352. fingerprint.shallow := fp;
  353. fingerprint.public := fingerprint.shallow;
  354. fingerprint.private := fingerprint.shallow;
  355. fingerprint.shallowAvailable := TRUE;
  356. x.SetFingerPrint(fingerprint);
  357. SELF.deep := deep;
  358. END;
  359. IF deep & ~fingerprint.deepAvailable THEN
  360. VType(x.arrayBase);
  361. fingerprint.private := fingerprint.shallow;
  362. fingerprint.public := fingerprint.shallow;
  363. fingerprint.deepAvailable := TRUE;
  364. x.SetFingerPrint(fingerprint);
  365. END;
  366. IF Trace THEN TraceExit("MathArrayType",fingerprint) END;
  367. SELF.fingerprint := fingerprint;
  368. END VisitMathArrayType;
  369. (*
  370. fp = fp [ -> Name(moduleName) -> Name(typeName) ]
  371. *)
  372. PROCEDURE TypeName(VAR fp: LONGINT; x:SyntaxTree.Type);
  373. VAR typeDeclaration: SyntaxTree.TypeDeclaration;
  374. BEGIN
  375. IF (x.scope # NIL) THEN
  376. (* only executed for imported types, reason:
  377. modification of a type name would result in modified fingerprint leading to modified fingerprints of using structures such as
  378. in the following example:
  379. TYPE A=ARRAY 32 OF CHAR;
  380. PROCEDURE P*(a:A);
  381. ...
  382. END P;
  383. IF name of A was changed, P would get a new fingerprint.
  384. Better: fingerprint of P only depends in type of A but not on its declared name.
  385. *)
  386. IF Trace THEN
  387. TraceIndent;
  388. D.Str("TypeName ");
  389. D.Str0(x.scope.ownerModule.name);
  390. END;
  391. typeDeclaration := x.typeDeclaration;
  392. IF(typeDeclaration # NIL) & (typeDeclaration.access # SyntaxTree.Hidden) THEN
  393. FPName(fp,x.scope.ownerModule.name);
  394. IF (typeDeclaration.declaredType.resolved # x) THEN
  395. (* in record type: pointer to type declaration of a pointer *)
  396. typeDeclaration := NIL
  397. END;
  398. IF (typeDeclaration # NIL) & (typeDeclaration.scope # NIL)THEN
  399. FPName(fp,typeDeclaration.name);
  400. IF Trace THEN
  401. D.Str(".");
  402. D.Str0(typeDeclaration.name);
  403. END;
  404. ELSIF (typeDeclaration # NIL) & (typeDeclaration.scope = NIL) THEN
  405. D.Str("typedeclaration without scope: "); D.Str0(x.typeDeclaration.name); D.Int(x.typeDeclaration.position.start,5); D.Ln;
  406. D.Update;
  407. ELSE
  408. FPNumber(fp,0);
  409. END;
  410. ELSE
  411. FPNumber(fp, 0);
  412. END;
  413. IF Trace THEN
  414. D.Str(", fp = "); D.Hex(fp,-8); D.Ln;
  415. END
  416. END
  417. END TypeName;
  418. (*
  419. FP(PointerType) = fpTypePointer <*> fpTypeBasic -> Name <*> FP(baseType).
  420. PublicFP(PointerType) = 0.
  421. PrivateFP(PointerType) = 0.
  422. *)
  423. PROCEDURE VisitPointerType*(x: SyntaxTree.PointerType);
  424. VAR fp: LONGINT; deep: BOOLEAN;
  425. BEGIN
  426. IF Trace THEN TraceEnter("PointerType"); END;
  427. fingerprint := x.fingerprint;
  428. deep := SELF.deep;
  429. IF ~fingerprint.shallowAvailable THEN
  430. IF Trace THEN TraceIndent; D.Str("PointerType shallow");D.Ln; END;
  431. SELF.deep := FALSE;
  432. fp := 0;
  433. FPNumber(fp, fpTypePointer); FPNumber(fp, fpTypeBasic);
  434. TypeName(fp,x);
  435. FPType(fp,x.pointerBase);
  436. fingerprint.shallow := fp;
  437. fingerprint.private := fp;
  438. fingerprint.public := fp;
  439. fingerprint.shallowAvailable := TRUE;
  440. fingerprint.deepAvailable := TRUE;
  441. (*
  442. deep fingerprinting leads to cycles -> must be done on record type directly, if a deep FP is needed
  443. IF deep & ~fingerprint.deepAvailable THEN
  444. IF Trace THEN TraceIndent; D.Str("PointerType:deep");D.Ln; END;
  445. x.pointerBase.Accept(SELF);
  446. fingerprint.deepAvailable := TRUE;
  447. END;
  448. *)
  449. x.SetFingerPrint(fingerprint);
  450. SELF.deep := deep;
  451. END;
  452. IF Trace THEN TraceExit("PointerType",fingerprint) END;
  453. SELF.fingerprint := fingerprint;
  454. END VisitPointerType;
  455. (*
  456. FP(PortType) = fpTypePort <*> fpTypeBasic -> Name <*> FP(baseType).
  457. PublicFP(PortType) = 0.
  458. PrivateFP(PortType) = 0.
  459. *)
  460. PROCEDURE VisitPortType*(x: SyntaxTree.PortType);
  461. VAR fingerprint: FingerPrint; fp: LONGINT; deep: BOOLEAN;
  462. BEGIN
  463. IF Trace THEN TraceEnter("PortType"); END;
  464. fingerprint := x.fingerprint;
  465. deep := SELF.deep;
  466. IF ~fingerprint.shallowAvailable THEN
  467. IF Trace THEN TraceIndent; D.Str("PortType shallow");D.Ln; END;
  468. SELF.deep := FALSE;
  469. fp := 0;
  470. FPNumber(fp, fpTypePort); FPNumber(fp, fpTypeBasic);
  471. TypeName(fp,x);
  472. FPNumber(fp,x.sizeInBits);
  473. fingerprint.shallow := fp;
  474. fingerprint.private := fp;
  475. fingerprint.public := fp;
  476. fingerprint.shallowAvailable := TRUE;
  477. fingerprint.deepAvailable := TRUE;
  478. SELF.deep := deep;
  479. END;
  480. IF Trace THEN TraceExit("PortType",fingerprint) END;
  481. SELF.fingerprint := fingerprint;
  482. END VisitPortType;
  483. (*
  484. FP(Method) = 0 <*> fpModeMethod -> Name(methodName) -> Signature(method).
  485. *)
  486. PROCEDURE FPrintMethod(VAR private,public: LONGINT; procedure,body: SyntaxTree.Procedure);
  487. VAR fingerprint: FingerPrint; fp: LONGINT; name: ARRAY 256 OF CHAR;
  488. BEGIN
  489. IF Trace THEN TraceEnter("Method");
  490. D.Address(SYSTEM.VAL(ADDRESS,procedure));
  491. procedure.GetName(name);
  492. TraceIndent; D.Str("name = "); D.Str(name); D.Ln;
  493. END;
  494. ASSERT(deep);
  495. fingerprint := procedure.fingerprint;
  496. IF ~fingerprint.shallowAvailable THEN
  497. fp := 0;
  498. FPNumber(fp,fpModeMethod);
  499. Global.GetSymbolName(procedure,name);
  500. FPString(fp,name);
  501. FPSignature(fp,procedure.type(SyntaxTree.ProcedureType),procedure IS SyntaxTree.Operator );
  502. fingerprint.shallow := fp;
  503. fingerprint.public := fingerprint.shallow;
  504. fingerprint.private := fingerprint.shallow;
  505. fingerprint.shallowAvailable := TRUE;
  506. procedure.SetFingerPrint(fingerprint)
  507. ELSE
  508. fp := fingerprint.shallow;
  509. END;
  510. IF procedure.access * SyntaxTree.Public # {} THEN (* visible method or visible supermethod *)
  511. IF Trace THEN D.String("fp before method number"); D.Hex(fp,-8); D.Ln END;
  512. FPNumber(fp,procedure.methodNumber);
  513. IF Trace THEN D.String("fp after method number"); D.Hex(fp,-8); D.Ln END;
  514. IF procedure # body THEN
  515. FPNumber(private,fp); FPNumber(public,fp);
  516. END;
  517. END;
  518. IF Trace THEN
  519. TraceIndent; D.Str("Method, fp = "); D.Hex(private,-8); D.Str(" "); D.Hex(public,-8); D.Ln;
  520. TraceExit("Method",fingerprint)
  521. END;
  522. END FPrintMethod;
  523. PROCEDURE VisitCellType*(x: SyntaxTree.CellType);
  524. VAR fingerprint: FingerPrint; fp:LONGINT;
  525. BEGIN
  526. fingerprint := x.fingerprint;
  527. deep := SELF.deep;
  528. IF ~fingerprint.shallowAvailable THEN
  529. fp := 0;
  530. TypeName(fp,x);
  531. fingerprint.shallow := fp;
  532. fingerprint.public := fp;
  533. fingerprint.private := fp;
  534. fingerprint.deepAvailable := TRUE;
  535. fingerprint.shallowAvailable := TRUE;
  536. x.SetFingerPrint(fingerprint);
  537. END;
  538. SELF.fingerprint := fingerprint
  539. END VisitCellType;
  540. (*
  541. FP(RecordType) = fpTypeComposite <*> fptypeRecord
  542. [ -> Name(moduleName) -> Name(typeName)] [<*> FP(baseType)]
  543. PublicFP(RecordType) = FP(recordType) [<*> PublicFP(baseType)] {<*> FP(method) <*> methodNumber }
  544. {<*> PublicFP(fieldType) <*> offset(field) <*> FP(field)} <*> flags.
  545. PrivateFP(RecordType) = FP(recordType) [<*> PrivateFP(baseType)] {<*> FP(method) <*> methodNumber }
  546. {<*> PrivateFP(fieldType) <*> offset(field) <*> FP(field)}
  547. *)
  548. PROCEDURE VisitRecordType*(x: SyntaxTree.RecordType);
  549. VAR scope: SyntaxTree.RecordScope; fp: LONGINT; variable: SyntaxTree.Variable;
  550. fingerprint,variableFingerPrint,variableTypeFingerPrint,baseFingerPrint: FingerPrint;flags: SET;
  551. symbol: SyntaxTree.Symbol; procedure: SyntaxTree.Procedure; baseType: SyntaxTree.Type;
  552. body: SyntaxTree.Body; name: ARRAY 256 OF CHAR;
  553. deep: BOOLEAN;
  554. (* for dealing with cycles the private and public fingerprint are computed here
  555. while FP is computed completely during call of Type0 *)
  556. BEGIN
  557. fingerprint := x.fingerprint;
  558. deep := SELF.deep;
  559. IF Trace THEN TraceEnter("Record"); END;
  560. IF ~fingerprint.shallowAvailable THEN
  561. IF Trace THEN TraceIndent; D.Str("RecordType Enter Shallow "); D.Ln; END;
  562. SELF.deep := FALSE;
  563. fp := 0;
  564. FPNumber(fp, fpTypeComposite); FPNumber(fp, fpTypeRecord);
  565. TypeName(fp,x);
  566. IF Trace THEN TraceIndent; D.Str("RecordType Name ");D.Hex(fp,-8); D.Ln; END;
  567. IF (x.baseType # NIL) THEN
  568. baseType := x.GetBaseRecord();
  569. FPType(fp,baseType);
  570. END;
  571. SELF.deep := TRUE;
  572. (* methods, sorted *)
  573. scope := x.recordScope;
  574. symbol := scope.firstSymbol;
  575. WHILE symbol # NIL DO (* number and names of procedures -- method table ! *)
  576. IF symbol IS SyntaxTree.Procedure THEN
  577. procedure := symbol(SyntaxTree.Procedure);
  578. FPNumber(fp,fpModeMethod);
  579. Global.GetSymbolName(procedure,name);
  580. FPString(fp,name);
  581. IF Trace THEN TraceIndent; D.Str("RecordType Method "); TraceFP(fingerprint); D.Ln; END;
  582. END;
  583. symbol := symbol.nextSymbol
  584. END;
  585. fingerprint.shallow := fp;
  586. fingerprint.public := fingerprint.shallow;
  587. fingerprint.private := fingerprint.shallow;
  588. fingerprint.shallowAvailable := TRUE;
  589. x.SetFingerPrint(fingerprint);
  590. SELF.deep := deep;
  591. IF Trace THEN TraceIndent; D.Str("RecordType Shallow Done "); TraceFP(fingerprint); D.Ln; END;
  592. END;
  593. IF deep & ~fingerprint.deepAvailable THEN
  594. IF Trace THEN TraceIndent; D.Str("RecordType Enter Deep "); D.Ln; END;
  595. fingerprint.private := fingerprint.shallow;
  596. fingerprint.public := fingerprint.shallow;
  597. (*! finger printing for interfaces omitted *)
  598. IF Trace THEN TraceIndent; D.Str("RecordType before basetype"); TraceFP(fingerprint); D.Ln; END;
  599. (* now compute base record finger prints *)
  600. baseType := x.GetBaseRecord();
  601. IF (baseType # NIL) THEN
  602. IF baseType IS SyntaxTree.PointerType THEN baseType := baseType(SyntaxTree.PointerType).pointerBase.resolved END;
  603. baseFingerPrint := TypeFP(baseType); (* deep finger print *)
  604. FPNumber(fingerprint.private,baseFingerPrint.private);
  605. FPNumber(fingerprint.public,baseFingerPrint.public);
  606. END;
  607. scope := x.recordScope;
  608. IF Trace THEN TraceIndent; D.Str("RecordType before methods"); TraceFP(fingerprint); D.Ln; END;
  609. (* methods, sorted *)
  610. symbol := scope.firstSymbol;
  611. WHILE symbol # NIL DO
  612. IF symbol IS SyntaxTree.Procedure THEN
  613. procedure := symbol(SyntaxTree.Procedure);
  614. FPrintMethod(fingerprint.private, fingerprint.public, procedure, scope.bodyProcedure);
  615. IF Trace THEN TraceIndent; D.Str("RecordType Method "); TraceFP(fingerprint); D.Ln; END;
  616. END;
  617. symbol := symbol.nextSymbol
  618. END;
  619. IF Trace THEN TraceIndent; D.Str("RecordType after methods"); TraceFP(fingerprint); D.Ln; END;
  620. variable := scope.firstVariable;
  621. WHILE variable # NIL DO
  622. variableFingerPrint := variable.fingerprint;
  623. IF variable.access * SyntaxTree.Public # {} THEN
  624. (* variable fp = & fpModeField & Name & Visibility [& fpUntraced] & Type *)
  625. fp := 0;
  626. FPNumber(fp,fpModeField);
  627. FPName(fp,variable.name);
  628. FPVisibility(fp,variable.access);
  629. IF variable.untraced THEN FPNumber(fp,fpUntraced) END;
  630. variableTypeFingerPrint := TypeFP(variable.type); (* deep finger print *)
  631. FPNumber(fp,variableTypeFingerPrint.shallow);
  632. variableFingerPrint.shallow := fp;
  633. FPNumber(fingerprint.private,variableTypeFingerPrint.private);
  634. FPNumber(fingerprint.private,SHORT(variable.offsetInBits DIV 8));
  635. FPNumber(fingerprint.private,fp);
  636. FPNumber(fingerprint.public,variableTypeFingerPrint.public);
  637. FPNumber(fingerprint.public,SHORT(variable.offsetInBits DIV 8));
  638. FPNumber(fingerprint.public,fp);
  639. IF Trace THEN TraceIndent; D.Str("RecordType Field "); D.Str0(variable.name); D.Str(" "); TraceFP(fingerprint); D.Ln; END;
  640. ELSE
  641. fp := 0;
  642. IF variable.untraced THEN FPNumber(fp,fpUntraced) END;
  643. FPNumber(fingerprint.private,fp);
  644. IF Trace THEN TraceIndent; D.Str("RecordType InvisibleField "); TraceFP(fingerprint); D.Ln; END;
  645. END;
  646. variable := variable.nextVariable;
  647. END;
  648. FPNumber(fingerprint.private, SHORT(x.sizeInBits DIV 8));
  649. FPNumber(fingerprint.public, SHORT(x.sizeInBits DIV 8));
  650. flags := {};
  651. IF x.recordScope.bodyProcedure # NIL THEN
  652. body := x.recordScope.bodyProcedure.procedureScope.body;
  653. INCL(flags, fpHasBody);
  654. IF body # NIL THEN
  655. IF body.isActive THEN INCL(flags,fpActive) END;
  656. IF body.isExclusive THEN INCL(flags,fpProtected) END;
  657. END;
  658. IF Trace THEN TraceIndent; D.Str("RecordType Body "); TraceFP(fingerprint); D.Ln; END;
  659. END;
  660. IF x.IsProtected() THEN INCL(flags,fpProtected) END;
  661. FPSet(fingerprint.public, flags);
  662. IF Trace THEN TraceIndent; D.Str("RecordType Exit Deep "); TraceFP(fingerprint); D.Ln; END;
  663. (*
  664. ASSERT(fingerprint.private # 0,100);
  665. ASSERT(fingerprint.public # 0,101);
  666. *)
  667. fingerprint.deepAvailable := TRUE;
  668. x.SetFingerPrint(fingerprint);
  669. END;
  670. SELF.fingerprint := fingerprint;
  671. IF Trace THEN TraceExit("Record",fingerprint); END;
  672. END VisitRecordType;
  673. (*
  674. FP(ProcedureType) = fpTypeProcedure <*> fpTypeBasic [<*> fpDelegate]-> Name.
  675. PublicFP(ProcedureType) = FP(arrayType) -> Signature(procedureType)
  676. PrivateFP(ProcedureType) = FP(arrayType)-> Signature(procedureType).
  677. *)
  678. PROCEDURE VisitProcedureType*(x: SyntaxTree.ProcedureType);
  679. VAR fingerprint: FingerPrint; deep: BOOLEAN; fp: LONGINT;
  680. BEGIN
  681. IF Trace THEN TraceEnter("ProcedureType") END;
  682. fingerprint := x.fingerprint;
  683. deep := SELF.deep;
  684. IF ~fingerprint.shallowAvailable THEN
  685. fingerprint.shallowAvailable := TRUE; (*! to avoid circles, this is not fully clean - for paco *)
  686. fp := 0;
  687. FPNumber(fp,fpTypeProcedure);
  688. FPNumber(fp,fpTypeBasic);
  689. IF x.isDelegate THEN FPNumber(fp,fpDelegate) END;
  690. x.SetFingerPrint(fingerprint);
  691. TypeName(fp,x);
  692. fingerprint.public := fp; fingerprint.private := fp;
  693. fingerprint.shallow := fp;
  694. FPSignature(fp,x,FALSE);
  695. fingerprint.public := fp; fingerprint.private := fp;
  696. fingerprint.shallow := fp;
  697. fingerprint.deepAvailable := TRUE;
  698. x.SetFingerPrint(fingerprint);
  699. END;
  700. (*
  701. IF ~fingerprint.deepAvailable THEN
  702. SELF.deep := FALSE;
  703. FPSignature(fp,x,FALSE);
  704. SELF.deep := deep;
  705. fingerprint.public := fp; fingerprint.private := fp;
  706. fingerprint.shallow := fp;
  707. fingerprint.deepAvailable := TRUE;
  708. END;
  709. *)
  710. IF Trace THEN TraceExit("ProcedureType",fingerprint) END;
  711. SELF.fingerprint := fingerprint;
  712. END VisitProcedureType;
  713. (** values - used in constant symbols - effects in fingerprint modification of (object) global variable fp *)
  714. (* fp = fp & (fpTrue | fpFalse) *)
  715. PROCEDURE VisitBooleanValue*(x: SyntaxTree.BooleanValue);
  716. BEGIN IF x.value THEN FPNumber(SELF.fp,fpTrue) ELSE FPNumber(SELF.fp,fpFalse) END
  717. END VisitBooleanValue;
  718. (* fp = fp & (HugeInt | Number) *)
  719. PROCEDURE VisitIntegerValue*(x: SyntaxTree.IntegerValue);
  720. BEGIN FPHugeInt(SELF.fp,x.value)
  721. END VisitIntegerValue;
  722. (* fp = fp & (HugeInt | Number) *)
  723. PROCEDURE VisitEnumerationValue*(x: SyntaxTree.EnumerationValue);
  724. BEGIN FPHugeInt(SELF.fp,x.value)
  725. END VisitEnumerationValue;
  726. (* fp = fp & ORD(char) *)
  727. PROCEDURE VisitCharacterValue*(x: SyntaxTree.CharacterValue);
  728. BEGIN FPNumber(SELF.fp,ORD(x.value)) END VisitCharacterValue;
  729. (* fp = fp & Set *)
  730. PROCEDURE VisitSetValue*(x: SyntaxTree.SetValue);
  731. BEGIN FPHugeInt(SELF.fp,SYSTEM.VAL(HUGEINT,x.value)) END VisitSetValue;
  732. PROCEDURE VisitMathArrayExpression*(x: SyntaxTree.MathArrayExpression);
  733. VAR element: SyntaxTree.Expression; i: LONGINT;
  734. BEGIN
  735. FOR i := 0 TO x.elements.Length()-1 DO
  736. element := x.elements.GetExpression(i);
  737. FPValue(fp, element);
  738. END;
  739. END VisitMathArrayExpression;
  740. (* fp = fp {& Value} *)
  741. PROCEDURE VisitMathArrayValue*(x: SyntaxTree.MathArrayValue);
  742. BEGIN
  743. VisitMathArrayExpression(x.array); (* do not call FPValue here, recursion possible because x.array.resolved = x *)
  744. END VisitMathArrayValue;
  745. (* fp = fp & (Real | LongReal) *)
  746. PROCEDURE VisitRealValue*(x: SyntaxTree.RealValue);
  747. BEGIN
  748. IF x.type.sizeInBits=32 THEN FPReal(SELF.fp,SHORT(x.value))
  749. ELSE FPLongReal(SELF.fp,x.value)
  750. END;
  751. END VisitRealValue;
  752. PROCEDURE VisitComplexValue*(x: SyntaxTree.ComplexValue);
  753. BEGIN
  754. FPLongReal(SELF.fp,x.realValue);
  755. FPLongReal(SELF.fp,x.imagValue);
  756. END VisitComplexValue;
  757. PROCEDURE VisitNilValue*(x: SyntaxTree.NilValue);
  758. BEGIN IF x.type.sizeInBits = 64 THEN FPHugeInt(SELF.fp, 0) ELSE FPNumber(SELF.fp, 0) END;
  759. END VisitNilValue;
  760. (* fp = fp & String *)
  761. PROCEDURE VisitStringValue*(x: SyntaxTree.StringValue);
  762. BEGIN FPString(SELF.fp,x.value^) END VisitStringValue;
  763. (* fp = fp & FP(x) *)
  764. PROCEDURE FPValue(VAR fp: LONGINT; x: SyntaxTree.Expression);
  765. BEGIN
  766. SELF.fp := fp;
  767. IF x.resolved # NIL THEN
  768. VExpression(x.resolved);
  769. ELSE
  770. VExpression(x);
  771. END;
  772. fp := SELF.fp
  773. END FPValue;
  774. PROCEDURE FPType(VAR fp: LONGINT; t: SyntaxTree.Type);
  775. BEGIN
  776. INC(level); ASSERT(level <= 100);
  777. IF t = NIL THEN FPNumber(fp,fpTypeNone);
  778. ELSE VType(t); FPNumber(fp,SELF.fingerprint.shallow);
  779. END;
  780. DEC(level);
  781. END FPType;
  782. (* Signature(f) = f <*> FP(returnType)
  783. { <*> (fpModeVarParameter | fpModeConstParameter | fpModePar)
  784. <*> FP(parameterType) [-> Name(parameterName)] }
  785. *)
  786. PROCEDURE FPSignature(VAR fp: LONGINT; t: SyntaxTree.ProcedureType; isOperator: BOOLEAN);
  787. VAR par,self: SyntaxTree.Parameter; deep: BOOLEAN;
  788. (* fp = fp & (fpModeVarPar | fpModeConstPar | fpModePar) [ & Name ] *)
  789. PROCEDURE FPPar(VAR fp: LONGINT; par: SyntaxTree.Parameter);
  790. VAR deep: BOOLEAN;
  791. BEGIN
  792. IF par.kind = SyntaxTree.VarParameter THEN FPNumber(fp, fpModeVarPar)
  793. ELSIF par.kind = SyntaxTree.ConstParameter THEN
  794. IF (par.type.resolved IS SyntaxTree.ArrayType) OR (par.type.resolved IS SyntaxTree.RecordType) THEN (*! compatiblity with paco *)
  795. FPNumber(fp,fpModeVarPar)
  796. ELSE
  797. FPNumber(fp,fpModePar)
  798. END;
  799. ELSE FPNumber(fp, fpModePar) END;
  800. deep := SELF.deep;
  801. SELF.deep := FALSE;
  802. FPType(fp,par.type);
  803. SELF.deep := deep;
  804. IF isOperator & ~(par.type.resolved IS SyntaxTree.BasicType) & (par.type.resolved.typeDeclaration # NIL) THEN
  805. FPName(fp,par.type.resolved.typeDeclaration.name);
  806. (* D.Str("fp "); D.Str0(par.type.resolved.typeDeclaration.name.name); D.Ln;*)
  807. ELSIF isOperator & (par.type.resolved IS SyntaxTree.BasicType) THEN
  808. FPName(fp,par.type.resolved(SyntaxTree.BasicType).name);
  809. (* D.Str("fpb "); D.Str0(par.type.resolved(SyntaxTree.BasicType).name.name);*)
  810. END;
  811. END FPPar;
  812. BEGIN
  813. IF Trace THEN
  814. TraceIndent; D.Str("FPSignature enter "); D.Hex(fp,-8); D.Ln;
  815. END;
  816. deep := SELF.deep;
  817. SELF.deep := FALSE;
  818. FPType(fp,t.returnType);
  819. SELF.deep := deep;
  820. IF Trace THEN
  821. TraceIndent; D.Str("FPSignature after return type "); D.Hex(fp,-8); D.Ln;
  822. END;
  823. IF IsOberonProcedure(t) THEN
  824. self := t.firstParameter;
  825. WHILE (self # NIL) & (self.name#Global.SelfParameterName) DO
  826. self := self.nextParameter;
  827. END;
  828. IF self # NIL THEN FPPar(fp,self) END; (* self parameter *)
  829. (*
  830. IF t.selfParameter # NIL THEN FPPar(fp,t.selfParameter) END; (* self parameter *)
  831. self := NIL;
  832. *)
  833. IF Trace THEN
  834. TraceIndent; D.Str("FPSignature after self "); D.Hex(fp,-8); D.Ln;
  835. END;
  836. par := t.firstParameter;
  837. WHILE (par#self) DO (*! done as in PACO *)
  838. FPPar(fp, par);
  839. IF Trace THEN
  840. TraceIndent; D.Str("FPSignature par "); D.Hex(fp,-8); D.Ln;
  841. END;
  842. par:=par.nextParameter;
  843. END;
  844. IF Trace THEN
  845. TraceIndent; D.Str("FPSignature exit "); D.Hex(fp,-8); D.Ln;
  846. END;
  847. ELSE
  848. par := t.lastParameter;
  849. WHILE (par#NIL) DO (*! done as in PACO *)
  850. FPPar(fp, par);
  851. IF Trace THEN
  852. TraceIndent; D.Str("FPSignature par "); D.Hex(fp,-8); D.Ln;
  853. END;
  854. par:=par.prevParameter;
  855. END;
  856. END;
  857. END FPSignature;
  858. (** symbols *)
  859. (*
  860. FP(TypeDeclaration) = 0 <*> fpModeType -> Name -> Visibility <*> FP(Type).
  861. *)
  862. PROCEDURE VisitTypeDeclaration*(x: SyntaxTree.TypeDeclaration);
  863. VAR fp: LONGINT;
  864. fingerprint: FingerPrint; deep: BOOLEAN;
  865. typeFP: FingerPrint;
  866. BEGIN
  867. fingerprint := x.fingerprint;
  868. IF ~fingerprint.shallowAvailable THEN
  869. IF Trace THEN TraceEnter("TypeDeclaration") END;
  870. deep := SELF.deep;
  871. SELF.deep := FALSE;
  872. fp := 0;
  873. FPNumber(fp, fpModeType);
  874. FPName(fp,x.name);
  875. IF Trace THEN TraceIndent; D.String("access="); D.Set(x.access); D.Ln; END;
  876. FPVisibility(fp, x.access);
  877. VType(x.declaredType);
  878. FPNumber(fp, SELF.fingerprint.shallow);
  879. fingerprint.shallow := fp;
  880. fingerprint.public := fp;
  881. fingerprint.private := fp;
  882. fingerprint.shallowAvailable := TRUE;
  883. x.SetFingerPrint(fingerprint);
  884. SELF.deep := deep;
  885. IF Trace THEN TraceExit("TypeDeclaration",fingerprint) END;
  886. END;
  887. IF deep & ~fingerprint.deepAvailable THEN
  888. fingerprint := x.fingerprint;
  889. typeFP := TypeFP(x.declaredType);
  890. IF x.declaredType.resolved IS SyntaxTree.PointerType THEN
  891. typeFP := TypeFP(x.declaredType.resolved(SyntaxTree.PointerType).pointerBase);
  892. END;
  893. FPNumber(fingerprint.public, typeFP.public);
  894. FPNumber(fingerprint.private, typeFP.private);
  895. fingerprint.deepAvailable := TRUE;
  896. x.SetFingerPrint(fingerprint);
  897. END;
  898. SELF.fingerprint := fingerprint
  899. END VisitTypeDeclaration;
  900. (*
  901. FP(ConstantDeclaration) = 0 <*> fpModeConstant -> Name -> Visibility <*> FP(Type) -> Basic -> Value.
  902. *)
  903. PROCEDURE VisitConstant*(x: SyntaxTree.Constant);
  904. VAR access: SET;
  905. fingerprint: FingerPrint;
  906. fp: LONGINT;
  907. deep: BOOLEAN;
  908. BEGIN
  909. fingerprint := x.fingerprint;
  910. IF ~fingerprint.shallowAvailable THEN
  911. deep := SELF.deep;
  912. SELF.deep := FALSE;
  913. fp := 0;
  914. FPNumber(fp, fpModeConst);
  915. FPName(fp,x.name);
  916. (* for compatibility with old compiler: *)
  917. access := x.access; IF SyntaxTree.PublicRead IN access THEN INCL(access,SyntaxTree.PublicWrite) END;
  918. FPVisibility(fp, access);
  919. FPType(fp, x.type);
  920. FPNumber(fp, fpTypeBasic);
  921. FPValue(fp, x.value);
  922. fingerprint.shallow := fp;
  923. fingerprint.public := fingerprint.shallow;
  924. fingerprint.private := fingerprint.shallow;
  925. fingerprint.shallowAvailable := TRUE;
  926. x.SetFingerPrint(fingerprint);
  927. SELF.deep := deep;
  928. END;
  929. SELF.fingerprint := fingerprint
  930. END VisitConstant;
  931. (*
  932. FP(VariableDeclaration) = 0 <*> fpModePar -> Name -> Visibility <*> FP(Type).
  933. *)
  934. PROCEDURE VisitVariable*(x: SyntaxTree.Variable);
  935. VAR fingerprint: FingerPrint; deep: BOOLEAN; name: SyntaxTree.IdentifierString;
  936. BEGIN
  937. fingerprint := x.fingerprint;
  938. IF ~fingerprint.shallowAvailable THEN
  939. deep := SELF.deep;
  940. SELF.deep := FALSE;
  941. fp := 0;
  942. FPNumber(fp,fpModeVar);
  943. Global.GetSymbolName(x,name);
  944. FPString(fp,name);
  945. FPVisibility(fp,x.access);
  946. VType(x.type);
  947. FPNumber(fp,SELF.fingerprint.shallow);
  948. fingerprint.shallow := fp;
  949. fingerprint.public := fingerprint.shallow;
  950. fingerprint.private := fingerprint.shallow;
  951. fingerprint.shallowAvailable := TRUE;
  952. x.SetFingerPrint(fingerprint);
  953. SELF.deep := deep;
  954. END;
  955. SELF.fingerprint := fingerprint
  956. END VisitVariable;
  957. PROCEDURE VisitProperty*(x: SyntaxTree.Property);
  958. BEGIN
  959. VisitVariable(x);
  960. END VisitProperty;
  961. (*
  962. FP(ParameterDeclaration) = 0 <*> fpModePar -> Name -> Visibility <*> FP(Type).
  963. *)
  964. PROCEDURE VisitParameter*(x: SyntaxTree.Parameter);
  965. VAR fingerprint: FingerPrint; deep: BOOLEAN; name: SyntaxTree.IdentifierString;
  966. BEGIN
  967. fingerprint := x.fingerprint;
  968. IF ~fingerprint.shallowAvailable THEN
  969. deep := SELF.deep;
  970. SELF.deep := FALSE;
  971. fp := 0;
  972. FPNumber(fp,fpModePar);
  973. Global.GetSymbolName(x,name);
  974. FPString(fp,name);
  975. FPVisibility(fp,x.access);
  976. VType(x.type);
  977. FPNumber(fp,SELF.fingerprint.shallow);
  978. fingerprint.shallow := fp;
  979. fingerprint.public := fingerprint.shallow;
  980. fingerprint.private := fingerprint.shallow;
  981. fingerprint.shallowAvailable := TRUE;
  982. x.SetFingerPrint(fingerprint);
  983. SELF.deep := deep;
  984. END;
  985. SELF.fingerprint := fingerprint
  986. END VisitParameter;
  987. (*
  988. FP(ProcedureDeclaration) = 0 <*> fpModeInlineProcedure -> Name -> Visibility <*> FP(Type) -> Code.
  989. | 0 <*> fpModeExportedProcedure -> Name -> Visibility <*> FP(Type)
  990. *)
  991. PROCEDURE VisitProcedure*(x: SyntaxTree.Procedure);
  992. VAR fp: LONGINT; access: SET; fingerprint: FingerPrint; deep: BOOLEAN; code: SyntaxTree.Code; i: LONGINT;
  993. size,value: LONGINT; name: ARRAY 256 OF CHAR;
  994. BEGIN
  995. IF x.scope IS SyntaxTree.RecordScope THEN (* method *)
  996. FPrintMethod(fp,fp,x,NIL);
  997. fingerprint := x.fingerprint;
  998. ELSE
  999. fingerprint := x.fingerprint;
  1000. IF ~fingerprint.shallowAvailable THEN
  1001. deep := SELF.deep;
  1002. SELF.deep := FALSE;
  1003. (* for compatibility with old compiler: *)
  1004. access := x.access; IF SyntaxTree.PublicRead IN access THEN INCL(access,SyntaxTree.PublicWrite) END;
  1005. fp := 0;
  1006. IF x.isInline THEN
  1007. FPNumber(fp, fpModeInlineProcedure);
  1008. FPName(fp,x.name);
  1009. FPVisibility(fp, access);
  1010. FPSignature(fp,x.type(SyntaxTree.ProcedureType),x IS SyntaxTree.Operator);
  1011. IF (x.procedureScope.body # NIL) & (x.procedureScope.body.code # NIL) THEN
  1012. code := x.procedureScope.body.code;
  1013. IF code.inlineCode = NIL THEN
  1014. size := 0
  1015. ELSE
  1016. size := code.inlineCode.GetSize() DIV 8;
  1017. END;
  1018. FPNumber(fp,size);
  1019. FOR i := 0 TO size-1 DO
  1020. value := code.inlineCode.GetBits(i*8,8);
  1021. FPNumber(fp,value);
  1022. END;
  1023. END;
  1024. ELSE
  1025. FPNumber(fp, fpModeExportedProcedure);
  1026. Global.GetSymbolName(x,name);
  1027. FPString(fp,name);
  1028. FPVisibility(fp, access);
  1029. FPSignature(fp,x.type(SyntaxTree.ProcedureType),x IS SyntaxTree.Operator);
  1030. END;
  1031. fingerprint.shallow := fp;
  1032. fingerprint.public := fingerprint.shallow;
  1033. fingerprint.private := fingerprint.shallow;
  1034. fingerprint.shallowAvailable := TRUE;
  1035. x.SetFingerPrint(fingerprint);
  1036. SELF.deep := deep;
  1037. END;
  1038. END;
  1039. SELF.fingerprint := fingerprint
  1040. END VisitProcedure;
  1041. (* cf. Procedure *)
  1042. PROCEDURE VisitOperator*(x: SyntaxTree.Operator);
  1043. BEGIN
  1044. VisitProcedure(x) (* same finger print as a procedure *)
  1045. END VisitOperator;
  1046. PROCEDURE VisitModule*(x: SyntaxTree.Module);
  1047. VAR fingerprint, symbolFingerPrint: FingerPrint; deep: BOOLEAN; fp: LONGINT; symbol: SyntaxTree.Symbol; scope: SyntaxTree.ModuleScope;
  1048. BEGIN
  1049. fingerprint := x.fingerprint;
  1050. deep := SELF.deep;
  1051. IF Trace THEN TraceEnter("Record"); END;
  1052. IF ~fingerprint.shallowAvailable THEN
  1053. IF Trace THEN TraceIndent; D.Str("Module Enter Shallow "); D.Ln; END;
  1054. SELF.deep := FALSE;
  1055. fp := 0;
  1056. FPNumber(fp, fpTypeModule);
  1057. FPName(fp,x.name);
  1058. IF Trace THEN TraceIndent; D.Str("Module Name ");D.Hex(fp,-8); D.Ln; END;
  1059. fingerprint.shallow := fp;
  1060. fingerprint.public := fingerprint.shallow;
  1061. fingerprint.private := fingerprint.shallow;
  1062. fingerprint.shallowAvailable := TRUE;
  1063. x.SetFingerPrint(fingerprint);
  1064. SELF.deep := deep;
  1065. IF Trace THEN TraceIndent; D.Str("Module Shallow Done "); TraceFP(fingerprint); D.Ln; END;
  1066. END;
  1067. IF deep & ~fingerprint.deepAvailable THEN
  1068. IF Trace THEN TraceIndent; D.Str("Module Enter Deep "); D.Ln; END;
  1069. fingerprint.private := fingerprint.shallow;
  1070. fingerprint.public := fingerprint.shallow;
  1071. scope := x.moduleScope;
  1072. IF Trace THEN TraceIndent; D.Str("RecordType before methods"); TraceFP(fingerprint); D.Ln; END;
  1073. symbol := scope.firstSymbol;
  1074. WHILE symbol # NIL DO
  1075. IF symbol.access * SyntaxTree.Public # {} THEN
  1076. symbolFingerPrint := SymbolFP(symbol);
  1077. FPNumber(fingerprint.private,symbolFingerPrint.shallow);
  1078. FPNumber(fingerprint.public,symbolFingerPrint.shallow);
  1079. END;
  1080. symbol := symbol.nextSymbol;
  1081. END;
  1082. IF Trace THEN TraceIndent; D.Str("Module Exit Deep "); TraceFP(fingerprint); D.Ln; END;
  1083. (*
  1084. ASSERT(fingerprint.private # 0,100);
  1085. ASSERT(fingerprint.public # 0,101);
  1086. *)
  1087. fingerprint.deepAvailable := TRUE;
  1088. x.SetFingerPrint(fingerprint);
  1089. END;
  1090. SELF.fingerprint := fingerprint;
  1091. IF Trace THEN TraceExit("Record",fingerprint); END;
  1092. END VisitModule;
  1093. PROCEDURE VisitSymbol*(x: SyntaxTree.Symbol);
  1094. BEGIN
  1095. fingerprint.shallow := 0;
  1096. fingerprint.public := fingerprint.shallow;
  1097. fingerprint.private := fingerprint.shallow;
  1098. fingerprint.shallowAvailable := TRUE;
  1099. x.SetFingerPrint(fingerprint);
  1100. END VisitSymbol;
  1101. PROCEDURE TraceIndent;
  1102. VAR i: LONGINT;
  1103. BEGIN
  1104. FOR i := 1 TO traceLevel DO D.Str(" "); END;
  1105. END TraceIndent;
  1106. PROCEDURE TraceEnter(CONST name: ARRAY OF CHAR);
  1107. BEGIN
  1108. INC(traceLevel); TraceIndent;
  1109. D.Str("Enter ");
  1110. D.Str(name);
  1111. D.Ln;
  1112. END TraceEnter;
  1113. PROCEDURE TraceExit(CONST name: ARRAY OF CHAR; fingerprint: FingerPrint);
  1114. BEGIN
  1115. TraceIndent; DEC(traceLevel);
  1116. D.Str("Exit "); D.Str(name); D.Str(" "); TraceFP(fingerprint); D.Ln;
  1117. END TraceExit;
  1118. PROCEDURE TraceFP(fingerprint: FingerPrint);
  1119. BEGIN
  1120. D.Hex(fingerprint.shallow,-8); D.Str(" "); D.Hex(fingerprint.private,-8);
  1121. D.Str(" "); D.Hex(fingerprint.public,-8);
  1122. END TraceFP;
  1123. (* returns the finger print (object) of a type *)
  1124. PROCEDURE TypeFP*(this: SyntaxTree.Type): FingerPrint;
  1125. VAR deep: BOOLEAN;
  1126. BEGIN
  1127. IF Trace THEN TraceEnter("TypeFP"); END;
  1128. deep := SELF.deep;
  1129. SELF.deep := TRUE;
  1130. VType(this);
  1131. SELF.deep := deep;
  1132. ASSERT(fingerprint.deepAvailable,101);
  1133. ASSERT(fingerprint.shallow #0,102);
  1134. IF Trace THEN TraceExit("TypeFP",fingerprint); D.Ln;
  1135. D.Ln; END;
  1136. RETURN fingerprint
  1137. END TypeFP;
  1138. (* returns the finger print (object) of a symbol *)
  1139. PROCEDURE SymbolFP*(this: SyntaxTree.Symbol): FingerPrint;
  1140. VAR deep: BOOLEAN;
  1141. BEGIN
  1142. deep := SELF.deep;
  1143. SELF.deep := TRUE;
  1144. IF Trace THEN TraceEnter("SymbolFP");
  1145. TraceIndent;
  1146. D.Str("name: ");
  1147. D.Str0(this.name); D.Ln;
  1148. END;
  1149. VSymbol(this);
  1150. SELF.deep := deep;
  1151. IF Trace THEN TraceExit("SymbolFP",fingerprint); D.Ln; END;
  1152. RETURN fingerprint
  1153. END SymbolFP;
  1154. END FingerPrinter;
  1155. (** ---------- FingerPrinting primitives -------------- *)
  1156. PROCEDURE IsOberonProcedure(type: SyntaxTree.ProcedureType): BOOLEAN;
  1157. BEGIN
  1158. RETURN type.callingConvention = SyntaxTree.OberonCallingConvention
  1159. END IsOberonProcedure;
  1160. (* fp = fp <*> val *)
  1161. PROCEDURE FPNumber*(VAR fp: LONGINT; val: LONGINT);
  1162. BEGIN
  1163. fp:=SYSTEM.VAL(LONGINT, SYSTEM.VAL(SET, ROT(fp, 7)) / SYSTEM.VAL(SET, val))
  1164. END FPNumber;
  1165. (* fp = fp <*> set *)
  1166. PROCEDURE FPSet*(VAR fp: LONGINT; set: SET);
  1167. BEGIN FPNumber(fp, SYSTEM.VAL(LONGINT, set))
  1168. END FPSet;
  1169. (* fp = fp <*> real *)
  1170. PROCEDURE FPReal*(VAR fp: LONGINT; real: REAL);
  1171. BEGIN FPNumber(fp, SYSTEM.VAL(LONGINT, real))
  1172. END FPReal;
  1173. (* fp = fp <*> low <*> high *)
  1174. PROCEDURE FPLongReal*(VAR fp: LONGINT; lr: LONGREAL);
  1175. VAR l, h: LONGINT;
  1176. BEGIN
  1177. SYSTEM.GET(ADDRESSOF(lr)+4, l); SYSTEM.GET(ADDRESSOF(lr), h);
  1178. FPNumber(fp, l); FPNumber(fp, h);
  1179. END FPLongReal;
  1180. (* fp = fp <*> low <*> high *)
  1181. PROCEDURE FPHugeInt*(VAR fp: LONGINT; huge: HUGEINT);
  1182. VAR l, h: LONGINT;
  1183. BEGIN
  1184. SYSTEM.GET(ADDRESSOF(huge)+4, l); SYSTEM.GET(ADDRESSOF(huge), h);
  1185. FPNumber(fp, l); FPNumber(fp, h);
  1186. END FPHugeInt;
  1187. (* fp = fp -> String *)
  1188. PROCEDURE FPName*(VAR fp: LONGINT; x: SyntaxTree.Identifier);
  1189. VAR name: Scanner.IdentifierString;
  1190. BEGIN
  1191. Basic.GetString(x,name);
  1192. FPString(fp,name);
  1193. END FPName;
  1194. (* fp = fp {<*> str[i]} *)
  1195. PROCEDURE FPString*(VAR fp: LONGINT; CONST str: ARRAY OF CHAR);
  1196. VAR i: INTEGER; ch: CHAR;
  1197. BEGIN i:=0; REPEAT ch:=str[i]; FPNumber(fp, ORD(ch)); INC(i) UNTIL ch=0X
  1198. END FPString;
  1199. (* fp = fp <*> (fpExtern | fpExternR | fpIntern | fpOther + vis) *)
  1200. PROCEDURE FPVisibility*(VAR fp: LONGINT; vis: SET);
  1201. BEGIN
  1202. IF SyntaxTree.PublicWrite IN vis THEN FPNumber(fp, fpExtern)
  1203. ELSIF SyntaxTree.PublicRead IN vis THEN FPNumber(fp, fpExternR)
  1204. ELSIF SyntaxTree.Internal * vis #{} THEN FPNumber(fp, fpIntern)
  1205. ELSE
  1206. FPNumber(fp, fpOther + SYSTEM.VAL(LONGINT, vis))
  1207. END
  1208. END FPVisibility;
  1209. PROCEDURE DumpFingerPrint*(w: Streams.Writer; fp: FingerPrint);
  1210. BEGIN
  1211. w.String("fingerprint: ");
  1212. w.String("shallow = "); w.Hex(fp.shallow,8);
  1213. w.String(", private = "); w.Hex(fp.private,8);
  1214. w.String(", public = "); w.Hex(fp.public,8);
  1215. w.Ln;
  1216. END DumpFingerPrint;
  1217. END FoxFingerPrinter.