@@ -90,74 +90,75 @@ let readCmt cmtFile =
9090 Log_. item " Try to clean and rebuild.\n\n " ;
9191 assert false
9292
93+ let readInputCmt isInterface cmtFile =
94+ let inputCMT = readCmt cmtFile in
95+ let ignoreInterface = ref false in
96+ let checkAnnotation ~loc :_ attributes =
97+ if
98+ attributes
99+ |> Annotation. getAttributePayload Annotation. tagIsGenTypeIgnoreInterface
100+ <> None
101+ then ignoreInterface := true ;
102+ attributes
103+ |> Annotation. getAttributePayload Annotation. tagIsOneOfTheGenTypeAnnotations
104+ <> None
105+ in
106+ let hasGenTypeAnnotations =
107+ inputCMT |> cmtCheckAnnotations ~check Annotation
108+ in
109+ if isInterface then
110+ let cmtFileImpl =
111+ (cmtFile |> (Filename. chop_extension [@ doesNotRaise])) ^ " .cmt"
112+ in
113+ let inputCMTImpl = readCmt cmtFileImpl in
114+ let hasGenTypeAnnotationsImpl =
115+ inputCMTImpl
116+ |> cmtCheckAnnotations ~check Annotation:(fun ~loc attributes ->
117+ if attributes |> checkAnnotation ~loc then (
118+ if not ! ignoreInterface then (
119+ Log_.Color. setup () ;
120+ Log_. info ~loc ~name: " Warning genType" (fun ppf () ->
121+ Format. fprintf ppf
122+ " Annotation is ignored as there's a .rei file" ));
123+ true )
124+ else false )
125+ in
126+ ( (match ! ignoreInterface with
127+ | true -> inputCMTImpl
128+ | false -> inputCMT),
129+ match ! ignoreInterface with
130+ | true -> hasGenTypeAnnotationsImpl
131+ | false -> hasGenTypeAnnotations )
132+ else (inputCMT, hasGenTypeAnnotations)
133+
93134let processCmtFile cmt =
94135 let config = Paths. readConfig ~namespace: (cmt |> Paths. findNameSpace) in
95136 if ! Debug. basic then Log_. item " Cmt %s\n " cmt;
96137 let cmtFile = cmt |> Paths. getCmtFile in
97138 if cmtFile <> " " then
98- let outputFile = cmt |> Paths. getOutputFile ~config in
99- let outputFileRelative = cmt |> Paths. getOutputFileRelative ~config in
100139 let fileName = cmt |> Paths. getModuleName in
101140 let isInterface = Filename. check_suffix cmtFile " .cmti" in
141+ let inputCMT, hasGenTypeAnnotations = readInputCmt isInterface cmtFile in
142+ let sourceFile =
143+ match inputCMT.cmt_annots |> FindSourceFile. cmt with
144+ | Some sourceFile -> sourceFile
145+ | None -> (
146+ (fileName |> ModuleName. toString)
147+ ^
148+ match isInterface with
149+ | true -> " .resi"
150+ | false -> " .res" )
151+ in
152+ let outputFile = sourceFile |> Paths. getOutputFile ~config in
153+ let outputFileRelative =
154+ sourceFile |> Paths. getOutputFileRelative ~config
155+ in
102156 let resolver =
103157 ModuleResolver. createLazyResolver ~config ~extensions: [" .res" ; " .shim.ts" ]
104158 ~exclude File:(fun fname ->
105159 fname = " React.res" || fname = " ReasonReact.res" )
106160 in
107- let inputCMT, hasGenTypeAnnotations =
108- let inputCMT = readCmt cmtFile in
109- let ignoreInterface = ref false in
110- let checkAnnotation ~loc :_ attributes =
111- if
112- attributes
113- |> Annotation. getAttributePayload
114- Annotation. tagIsGenTypeIgnoreInterface
115- <> None
116- then ignoreInterface := true ;
117- attributes
118- |> Annotation. getAttributePayload
119- Annotation. tagIsOneOfTheGenTypeAnnotations
120- <> None
121- in
122- let hasGenTypeAnnotations =
123- inputCMT |> cmtCheckAnnotations ~check Annotation
124- in
125- if isInterface then
126- let cmtFileImpl =
127- (cmtFile |> (Filename. chop_extension [@ doesNotRaise])) ^ " .cmt"
128- in
129- let inputCMTImpl = readCmt cmtFileImpl in
130- let hasGenTypeAnnotationsImpl =
131- inputCMTImpl
132- |> cmtCheckAnnotations ~check Annotation:(fun ~loc attributes ->
133- if attributes |> checkAnnotation ~loc then (
134- if not ! ignoreInterface then (
135- Log_.Color. setup () ;
136- Log_. info ~loc ~name: " Warning genType" (fun ppf () ->
137- Format. fprintf ppf
138- " Annotation is ignored as there's a .rei file" ));
139- true )
140- else false )
141- in
142- ( (match ! ignoreInterface with
143- | true -> inputCMTImpl
144- | false -> inputCMT),
145- match ! ignoreInterface with
146- | true -> hasGenTypeAnnotationsImpl
147- | false -> hasGenTypeAnnotations )
148- else (inputCMT, hasGenTypeAnnotations)
149- in
150161 if hasGenTypeAnnotations then
151- let sourceFile =
152- match inputCMT.cmt_annots |> FindSourceFile. cmt with
153- | Some sourceFile -> sourceFile
154- | None -> (
155- (fileName |> ModuleName. toString)
156- ^
157- match isInterface with
158- | true -> " .resi"
159- | false -> " .res" )
160- in
161162 inputCMT
162163 |> translateCMT ~config ~output FileRelative ~resolver
163164 |> emitTranslation ~config ~file Name ~output File ~output FileRelative
0 commit comments