@@ -4,45 +4,142 @@ import edg.EdgirUtils.SimpleLibraryPath
44import edg .wir .{DesignPath , IndirectDesignPath }
55import edgir .expr .expr
66import edgir .ref .ref
7+ import edgrpc .compiler .{compiler => edgcompiler }
78
89class ElaboratingException (msg : String , wrapped : Exception ) extends Exception (f " $msg: \n $wrapped" )
910
10- sealed trait CompilerError
11+ sealed trait CompilerError {
12+ def toIr : edgcompiler.ErrorRecord
13+ }
1114
1215object CompilerError {
13- case class Unelaborated (elaborateRecord : ElaborateRecord , missing : Set [ElaborateRecord ]) extends CompilerError {
16+ case class Unelaborated (record : ElaborateRecord , missing : Set [ElaborateRecord ]) extends CompilerError {
1417 // These errors may be redundant with below, but provides dependency data
15- override def toString : String = s " Unelaborated missing dependencies $elaborateRecord : \n " +
18+ override def toString : String = s " Unelaborated missing dependencies $record : \n " +
1619 s " ${missing.map(x => s " - $x" ).mkString(" \n " )}"
20+
21+ override def toIr : edgcompiler.ErrorRecord = {
22+ val missingStr = " missing " + missing.map(_.toString).mkString(" , " )
23+ val (kind, path) = record match {
24+ case ElaborateRecord .ExpandBlock (path, _) =>
25+ (f " Uncompiled block, $missingStr" , Some (path.asIndirect.toLocalPath))
26+ case ElaborateRecord .Block (path) => (f " Uncompiled block, $missingStr" , Some (path.asIndirect.toLocalPath))
27+ case ElaborateRecord .Link (path) => (f " Uncompiled link, $missingStr" , Some (path.asIndirect.toLocalPath))
28+ case ElaborateRecord .LinkArray (path) =>
29+ (f " Uncompiled link array, $missingStr" , Some (path.asIndirect.toLocalPath))
30+ case ElaborateRecord .Parameter (containerPath, _, postfix, _) =>
31+ (f " Uncompiled parameter, $missingStr" , Some ((containerPath.asIndirect ++ postfix).toLocalPath))
32+ case _ => (f " Uncompiled internal element, $missingStr" , None )
33+ }
34+ edgcompiler.ErrorRecord (
35+ path = path,
36+ kind = kind,
37+ name = " " ,
38+ details = " "
39+ )
40+ }
1741 }
1842 case class LibraryElement (path : DesignPath , target : ref.LibraryPath ) extends CompilerError {
1943 override def toString : String = s " Unelaborated library element ${target.toSimpleString} @ $path"
44+
45+ override def toIr : edgcompiler.ErrorRecord = {
46+ edgcompiler.ErrorRecord (
47+ path = Some (path.asIndirect.toLocalPath),
48+ kind = " Uncompiled library element" ,
49+ name = " " ,
50+ details = f " class ${target.toSimpleString}"
51+ )
52+ }
2053 }
2154 case class UndefinedPortArray (path : DesignPath , portType : ref.LibraryPath ) extends CompilerError {
2255 override def toString : String = s " Undefined port array ${portType.toSimpleString} @ $path"
56+
57+ override def toIr : edgcompiler.ErrorRecord = {
58+ edgcompiler.ErrorRecord (
59+ path = Some (path.asIndirect.toLocalPath),
60+ kind = " Undefined port array" ,
61+ name = " " ,
62+ details = f " port type ${portType.toSimpleString}"
63+ )
64+ }
2365 }
2466
67+ // TODO partly redundant w/ LibraryElement error, which is a compiler-level error
2568 case class LibraryError (path : DesignPath , target : ref.LibraryPath , err : String ) extends CompilerError {
2669 override def toString : String = s " Library error ${target.toSimpleString} @ $path: $err"
70+
71+ override def toIr : edgcompiler.ErrorRecord = {
72+ edgcompiler.ErrorRecord (
73+ path = Some (path.asIndirect.toLocalPath),
74+ kind = " Library error" ,
75+ name = " " ,
76+ details = f " ${target.toSimpleString}: err "
77+ )
78+ }
2779 }
2880 case class GeneratorError (path : DesignPath , target : ref.LibraryPath , err : String ) extends CompilerError {
2981 override def toString : String = s " Generator error ${target.toSimpleString} @ $path: $err"
82+
83+ override def toIr : edgcompiler.ErrorRecord = {
84+ edgcompiler.ErrorRecord (
85+ path = Some (path.asIndirect.toLocalPath),
86+ kind = " Generator error" ,
87+ name = " " ,
88+ details = f " ${target.toSimpleString}: err "
89+ )
90+ }
3091 }
3192 case class RefinementSubclassError (path : DesignPath , refinedLibrary : ref.LibraryPath , designLibrary : ref.LibraryPath )
3293 extends CompilerError {
3394 override def toString : String =
34- s " Invalid refinement ${refinedLibrary.toSimpleString} <- ${designLibrary.toSimpleString} @ $path"
95+ s " Invalid refinement ${refinedLibrary.toSimpleString} -> ${designLibrary.toSimpleString} @ $path"
96+
97+ override def toIr : edgcompiler.ErrorRecord = {
98+ edgcompiler.ErrorRecord (
99+ path = Some (path.asIndirect.toLocalPath),
100+ kind = " Invalid refinement" ,
101+ name = " " ,
102+ details = f " ${refinedLibrary.toSimpleString} -> ${designLibrary.toSimpleString}"
103+ )
104+ }
35105 }
36106
37107 case class OverAssign (target : IndirectDesignPath , causes : Seq [OverAssignCause ]) extends CompilerError {
38108 override def toString : String = s " Overassign to $target: \n " +
39109 s " ${causes.map(x => s " - $x" ).mkString(" \n " )}"
110+
111+ override def toIr : edgcompiler.ErrorRecord = {
112+ edgcompiler.ErrorRecord (
113+ path = Some (target.toLocalPath),
114+ kind = " Overassign" ,
115+ name = " " ,
116+ details = causes.map(_.toString).mkString(" , " )
117+ )
118+ }
40119 }
41120
42- case class BadRef (path : DesignPath , ref : IndirectDesignPath ) extends CompilerError
121+ case class BadRef (path : DesignPath , ref : IndirectDesignPath ) extends CompilerError {
122+ override def toIr : edgcompiler.ErrorRecord = {
123+ edgcompiler.ErrorRecord (
124+ path = Some (path.asIndirect.toLocalPath),
125+ kind = " Bad reference" ,
126+ name = " " ,
127+ details = ref.toLocalPath.toString
128+ )
129+ }
130+ }
43131
44132 case class AbstractBlock (path : DesignPath , blockType : ref.LibraryPath ) extends CompilerError {
45133 override def toString : String = s " Abstract block: $path (of type ${blockType.toSimpleString}) "
134+
135+ override def toIr : edgcompiler.ErrorRecord = {
136+ edgcompiler.ErrorRecord (
137+ path = Some (path.asIndirect.toLocalPath),
138+ kind = " Abstract block" ,
139+ name = " " ,
140+ details = f " block type ${blockType.toSimpleString}"
141+ )
142+ }
46143 }
47144
48145 sealed trait AssertionError extends CompilerError
@@ -55,6 +152,15 @@ object CompilerError {
55152 ) extends AssertionError {
56153 override def toString : String =
57154 s " Failed assertion: $root. $constrName, ${ExprToString .apply(value)} => $result"
155+
156+ override def toIr : edgcompiler.ErrorRecord = {
157+ edgcompiler.ErrorRecord (
158+ path = Some (root.asIndirect.toLocalPath),
159+ kind = " Failed assertion" ,
160+ name = constrName,
161+ details = s " ${ExprToString .apply(value)} => $result"
162+ )
163+ }
58164 }
59165 case class MissingAssertion (
60166 root : DesignPath ,
@@ -63,7 +169,16 @@ object CompilerError {
63169 missing : Set [IndirectDesignPath ]
64170 ) extends AssertionError {
65171 override def toString : String =
66- s " Unevaluated assertion: $root. $constrName ( ${ExprToString .apply(value)}), missing ${missing.mkString(" , " )}"
172+ s " Unevaluated assertion: $root. $constrName: missing ${missing.mkString(" , " )} in ${ExprToString .apply(value)}"
173+
174+ override def toIr : edgcompiler.ErrorRecord = {
175+ edgcompiler.ErrorRecord (
176+ path = Some (root.asIndirect.toLocalPath),
177+ kind = " Unevaluated assertion" ,
178+ name = constrName,
179+ details = s " Missing ${missing.mkString(" , " )} in ${ExprToString .apply(value)}"
180+ )
181+ }
67182 }
68183
69184 case class InconsistentLinkArrayElements (
@@ -75,6 +190,15 @@ object CompilerError {
75190 ) extends CompilerError {
76191 override def toString : String =
77192 s " Inconsistent link array elements: $linkPath ( $linkElements), $blockPortPath ( $blockPortElements) "
193+
194+ override def toIr : edgcompiler.ErrorRecord = {
195+ edgcompiler.ErrorRecord (
196+ path = Some (linkPath.toLocalPath),
197+ kind = " Inconsistent link array elements" ,
198+ name = " " ,
199+ details = s " $linkElements (link-side), $blockPortElements (block-side) "
200+ )
201+ }
78202 }
79203
80204 sealed trait OverAssignCause
0 commit comments