Skip to content

Commit

Permalink
Adrian Pop, adrpo@ida.liu.se, 2006-02-06
Browse files Browse the repository at this point in the history
- changed Absyn.INFO(file, isReadOnly, startline, startcolumn, endline, endcolumn)
- the endline/endcolumn is not very easy to get from ANTLR, so I just used the 
  same values as startline, startcolumn for now.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2086 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Feb 6, 2006
1 parent f0d1633 commit 992c674
Show file tree
Hide file tree
Showing 13 changed files with 460 additions and 221 deletions.
37 changes: 24 additions & 13 deletions Compiler/Absyn.rml
Expand Up @@ -94,10 +94,13 @@ module Absyn:
| TOP


(** adrpo added 2005-10-29 **)
datatype Info = INFO of string (* filename where the class is defined in *)
* int (* lineNumber *)
* int (* columnNumber *)
(** adrpo added 2005-10-29, changed 2006-02-05 **)
datatype Info = INFO of string (* fileName where the class is defined in *)
* bool (* isReadOnly : (true|false). Should be true for libraries *)
* int (* lineNumberStart *)
* int (* columnNumberStart *)
* int (* lineNumberEnd *)
* int (* columnNumberEnd *)

(** - Classes *)
(** A class definition consists of a name, a flag to indicate if this *)
Expand All @@ -109,7 +112,10 @@ module Absyn:
* bool (* encapsulated *)
* Restriction (* restricion *)
* ClassDef (* body *)
* Info (* info ; FileName the class is defined in + line no + column no *)
* Info (* info ; FileName the class is defined in +
isReadOnly bool +
start line no + start column no +
end line no + end column no *)


(** The `ClassDef' type contains the definition part of a class *)
Expand Down Expand Up @@ -168,12 +174,17 @@ module Absyn:
(** - Elements *)
(* The basic element type in Modelica *)
datatype Element = ELEMENT of bool (* final *)
* RedeclareKeywords option (* redeclareKeywords ; replaceable, redeclare *)
* InnerOuter (* innerOuter ; inner/outer *)
* Ident (* name *)
* ElementSpec (* specification ; Actual element specification*)
* Info (* info ; File name the class is defined in + line no + column no *)
* ConstrainClass option (* constrainClass ; only valid for classdef and component*)
* RedeclareKeywords option (* redeclareKeywords ; replaceable, redeclare *)
* InnerOuter (* innerOuter ; inner/outer *)
* Ident (* name *)
* ElementSpec (* specification ; Actual element specification*)
* Info (* info ; File name the class is defined in + line no + column no *)
* ConstrainClass option (* constrainClass ; only valid for classdef and component*)
| TEXT of Ident option (* optName : optional name of text, e.g. model with syntax error.
We need the name to be able to browse it...*)
* string (* text *)
* Info (* info : filename, readonly bool, start and stop position of text *)



(* Constraining type, must be extends *)
Expand Down Expand Up @@ -883,7 +894,7 @@ end
**)
relation class_filename: Class => string =

axiom class_filename (CLASS(_,_,_,_,_,_,INFO(filename,_,_))) => filename
axiom class_filename (CLASS(_,_,_,_,_,_,INFO(filename,_,_,_,_,_))) => filename
end


Expand All @@ -896,7 +907,7 @@ relation set_class_filename: (Class,string) => Class =


axiom set_class_filename(CLASS(n,p,f,e,r,body,_),filename)
=> CLASS(n,p,f,e,r,body,INFO(filename,0,0))
=> CLASS(n,p,f,e,r,body,INFO(filename,false,0,0,0,0))
end


Expand Down
7 changes: 5 additions & 2 deletions Compiler/Ceval.rml
Expand Up @@ -1116,9 +1116,12 @@ relation ceval_ast_elt: (Env.Env, Absyn.Element,

rule ceval_ast_citems(env,citems,impl,st,msg) => citems'
-----------------------------------------------
ceval_ast_elt (env, Absyn.ELEMENT(f,r,io,id,Absyn.COMPONENTS(attr,tp,citems),Absyn.INFO(file,line,column),c),
ceval_ast_elt (env,
Absyn.ELEMENT(f,r,io,id,
Absyn.COMPONENTS(attr,tp,citems),
info as Absyn.INFO(file,isReadOnly,sline,scolumn,eline,ecolumn),c),
impl,st,msg)
=> (Absyn.ELEMENT(f,r,io,id,Absyn.COMPONENTS(attr,tp,citems'),Absyn.INFO(file,line,column),c))
=> (Absyn.ELEMENT(f,r,io,id,Absyn.COMPONENTS(attr,tp,citems'),info,c))
end


Expand Down
136 changes: 104 additions & 32 deletions Compiler/Dump.rml
Expand Up @@ -108,7 +108,8 @@ module Dump:
relation unparse_comment_option: (Absyn.Comment option) => string
relation unparse_comment_option_no_annotation: (Absyn.Comment option) => string
relation unparse_each_str: (Absyn.Each) => string

relation print_info:(Absyn.Info) => ()
relation unparse_info_str:(Absyn.Info) => string
end


Expand Down Expand Up @@ -481,9 +482,63 @@ relation dump_istmt : Interactive.InteractiveStmts => () =
axiom dump_istmt(_) => ()
end

(** relation: print_info
**
** Dumps an Info to the Print buffer.
** author: adrpo, 2006-02-05
**)
relation print_info: Absyn.Info => () =

rule Print.print_buf("Absyn.INFO(\"") &
Print.print_buf filename &
Print.print_buf("\", ") &
print_bool(isReadOnly) &
Print.print_buf(", ") &
int_string sline => s1 &
Print.print_buf s1 &
Print.print_buf(", ") &
int_string scol => s2 &
Print.print_buf s2 &
Print.print_buf(", ") &
int_string eline => s3 &
Print.print_buf s3 &
Print.print_buf(", ") &
int_string ecol => s4 &
Print.print_buf s4 &
Print.print_buf(")")
-----------------------------------------------------------------
print_info(Absyn.INFO(filename,isReadOnly,sline,scol,eline,ecol)) => ()
end

(** relation: unparse_info_str
**
** Translates Info to a string representation
** author: adrpo, 2006-02-05
**)
relation unparse_info_str: Absyn.Info => string =

rule select_string(isReadOnly,"readonly","writable") => s1 &
int_string sline => s2 &
int_string scol => s3 &
int_string eline => s4 &
int_string ecol => s5 &
Util.string_append_list(
["Absyn.INFO(\"",
filename, "\", ",
s1, ", ",
s2, ", ",
s3, ", ",
s4, ", ",
s5, ")\n"]) => str
------------------------------------------------------------------------
unparse_info_str(Absyn.INFO(filename,isReadOnly,sline,scol,eline,ecol)) => str

end

(** relation: print_class
**
** Dumps a Class to the Print buffer.
** changed by adrpo, 2006-02-05 to use print_info.
**)
relation print_class: Absyn.Class => () =

Expand All @@ -499,17 +554,11 @@ relation print_class: Absyn.Class => () =
print_class_restriction(r) &
Print.print_buf(", ") &
print_classdef(cdef) &
Print.print_buf(",Absyn.INFO(\"") &
Print.print_buf filename &
Print.print_buf("\", ") &
int_string line => s1 &
Print.print_buf s1 &
Print.print_buf(", ") &
int_string col => s2 &
Print.print_buf s2 &
Print.print_buf("))\n")
print_info(info) &
Print.print_buf(")\n")
----------------------------------------
print_class(Absyn.CLASS(n,p,f,e,r,cdef,Absyn.INFO(filename,line,col))) => ()
print_class(Absyn.CLASS(n,p,f,e,r,cdef,info)) => ()
end

(** relation: print_classdef
Expand Down Expand Up @@ -1086,6 +1135,7 @@ end
(** relation: print_element
**
** Prints an Element to the Print buffer.
** changed by adrpo, 2006-02-06 to use print_info and dump Absyn.TEXT also
**)
relation print_element: Absyn.Element => () =

Expand All @@ -1098,17 +1148,11 @@ relation print_element: Absyn.Element => () =
Print.print_buf name &
Print.print_buf "\", " &
print_elementspec spec &
Print.print_buf ", Absyn.INFO(\"" &
Print.print_buf filename &
Print.print_buf "\", " &
int_string lineno => s1 &
Print.print_buf s1 &
Print.print_buf ", " &
int_string colno => s2 &
Print.print_buf s2 &
Print.print_buf ", " &
print_info info &
Print.print_buf "), NONE)"
---------------------------
print_element (Absyn.ELEMENT(final,repl,inout,name,spec,Absyn.INFO(filename,lineno,colno),NONE))
print_element (Absyn.ELEMENT(final,repl,inout,name,spec,info,NONE))

rule Print.print_buf "Absyn.ELEMENT(" &
print_bool(final) &
Expand All @@ -1119,23 +1163,40 @@ relation print_element: Absyn.Element => () =
Print.print_buf name &
Print.print_buf "\", " &
print_elementspec spec &
Print.print_buf ", Absyn.INFO(\"" &
Print.print_buf filename &
Print.print_buf "\", " &
int_string lineno => s1 &
Print.print_buf s1 &
Print.print_buf ", " &
int_string colno => s2 &
Print.print_buf s2 &
Print.print_buf "), SOME(...))"
Print.print_buf ", " &
print_info info &
Print.print_buf ", SOME(...))"
---------------------------
print_element (Absyn.ELEMENT(final,repl,inout,name,spec,info,SOME(_)))

rule Print.print_buf "Absyn.TEXT(" &
Print.print_buf "SOME(\"" &
Print.print_buf name &
Print.print_buf "\"), \"" &
Print.print_buf text &
Print.print_buf "\", " &
print_info info &
Print.print_buf ")"
---------------------------
print_element (Absyn.TEXT(SOME(name), text, info))

rule Print.print_buf "Absyn.TEXT(" &
Print.print_buf "NONE, \"" &
Print.print_buf text &
Print.print_buf "\", " &
print_info info &
Print.print_buf ")"
---------------------------
print_element (Absyn.ELEMENT(final,repl,inout,name,spec,Absyn.INFO(filename,lineno,colno),SOME(_)))
print_element (Absyn.TEXT(NONE, text, info))

end

(** relation: unparse_element_str
**
** Prettyprints and Element to a string.
** changed by adrpo 2006-02-05 to print also Absyn.TEXT as a comment
** TODO?? - should we also dump info as a comment for an element??
** - should we dump Absyn.TEXT as an Annotation Item??
**)
relation unparse_element_str: (int, Absyn.Element) => string =

Expand All @@ -1144,17 +1205,28 @@ relation unparse_element_str: (int, Absyn.Element) => string =
unparse_innerouter_str inout => s3 &
unparse_elementspec_str(i, spec,s1,s2,s3) => s4 &
unparse_constrainclass_opt_str(constr) => s5 &
Util.string_append_list([s4, s5, ";"]) => str
Util.string_append_list([s4, s5, ";"]) => str
----------------------------
unparse_element_str(i, Absyn.ELEMENT(final,SOME(repl),inout,_,spec,Absyn.INFO(filename,lineno,colno),constr)) => str
unparse_element_str(i, Absyn.ELEMENT(final,SOME(repl),inout,_,spec,info,constr)) => str

rule select_string(final, "final ", "") => s1 &
unparse_innerouter_str inout => s3 &
unparse_elementspec_str(i, spec,s1,"",s3) => s4 &
unparse_constrainclass_opt_str(constr) => s5 &
Util.string_append_list([s4,s5, ";"]) => str
----------------------------
unparse_element_str(i, Absyn.ELEMENT(final,NONE,inout,_,spec,Absyn.INFO(filename,lineno,colno),constr)) => str
unparse_element_str(i, Absyn.ELEMENT(final,NONE,inout,_,spec,info,constr)) => str

rule unparse_info_str(info) => s1 &
Util.string_append_list(["/* Absyn.TEXT(SOME(\"",name,"\"), \"",text,"\", ", s1, "); */"]) => str
----------------------------
unparse_element_str(i, Absyn.TEXT(SOME(name),text,info)) => str

rule unparse_info_str(info) => s1 &
Util.string_append_list(["/* Absyn.TEXT(NONE, \"",text,"\", ", s1, "); */"]) => str
----------------------------
unparse_element_str(i, Absyn.TEXT(NONE,text,info)) => str

end

(** relation: unparse_constrainclass_opt_str
Expand Down
34 changes: 26 additions & 8 deletions Compiler/Error.rml
Expand Up @@ -688,10 +688,10 @@ relation add_source_message: ( ErrorID,MessageTokens, Absyn.Info) => () =
message_type_str(msg_type) => msg_type_str &
severity_str(severity) => severity_string &
ErrorExt.add_source_message(error_id,msg_type_str,severity_string,
line,col,file,
sline,scol,eline,ecol,isReadOnly,file,
msg,tokens )
---------------------------
add_source_message(error_id,tokens,Absyn.INFO(file,line,col)) => ()
add_source_message(error_id,tokens,Absyn.INFO(file,isReadOnly,sline,scol,eline,ecol)) => ()

rule not lookup_message(error_id) => (_,_,_) &
Print.print_error_buf "#Internal error, error message with id " &
Expand Down Expand Up @@ -842,16 +842,34 @@ relation severity_str:(Severity) => string =
axiom severity_str(NOTIFICATION) => "NOTIFICATION"
end


(** relation select_string
** author: adrpo, 2006-02-05
** selects first string is bool is true otherwise the second string
**)
relation select_string: (bool, string, string) => string =

axiom select_string(true,s1,_) => s1
axiom select_string(false,_,s2) => s2

end


(** relation: info_str
**
** Converts a Absyn.Info to a string.
** adrpo changed 2006-02-05 to match the new Absyn.INFO specification
**
**)
relation info_str:(Absyn.Info) => string =

rule int_string(line) => line_str &
int_string(col) => col_str &
Util.string_append_list(["{",filename,", ",line_str,", ",
col_str,"}"]) => res
-----------------------
info_str(Absyn.INFO(filename,line,col)) => res
rule select_string(isReadOnly,"readonly","writable") => s1 &
int_string(sline) => sline_str &
int_string(scol) => scol_str &
int_string(eline) => eline_str &
int_string(ecol) => ecol_str &
Util.string_append_list(["{",filename,", ", s1, ",", sline_str,", ",
scol_str,", ", eline_str, ", ", ecol_str, "}"]) => res
----------------------------------
info_str(Absyn.INFO(filename,isReadOnly,sline,scol,eline,ecol)) => res
end
8 changes: 6 additions & 2 deletions Compiler/ErrorExt.rml
Expand Up @@ -65,8 +65,11 @@ relation add_message:(Error.ErrorID,
relation add_source_message:(Error.ErrorID,
string, (* messageType*)
string, (* severity*)
int, (* line*)
int, (* col*)
int, (* sline*)
int, (* scol*)
int, (* eline*)
int, (* ecol*)
bool, (* isReadOnly filename *)
string, (* filename*)
string, (*message*)
string list) (* tokens*)
Expand All @@ -78,5 +81,6 @@ relation get_messages_str:() => string
relation error_off:() => ()

relation error_on:() => ()

end

0 comments on commit 992c674

Please sign in to comment.