Commit f197d733 authored by Marco Trevisan's avatar Marco Trevisan 🎺 Committed by Jürg Billeter

Add support for [Experimental] attribute

Report a warning when using experimental symbols. The GIDL parser has
been updated, too, and bindings have been regenerated.

Fixes bug 644779.
parent 7b05969a
...@@ -747,6 +747,8 @@ public class Vala.Class : ObjectTypeSymbol { ...@@ -747,6 +747,8 @@ public class Vala.Class : ObjectTypeSymbol {
process_deprecated_attribute (a); process_deprecated_attribute (a);
} else if (a.name == "GIR") { } else if (a.name == "GIR") {
process_gir_attribute (a); process_gir_attribute (a);
} else if (a.name == "Experimental") {
process_experimental_attribute (a);
} }
} }
} }
...@@ -1193,6 +1195,7 @@ public class Vala.Class : ObjectTypeSymbol { ...@@ -1193,6 +1195,7 @@ public class Vala.Class : ObjectTypeSymbol {
if (sym is Method) { if (sym is Method) {
// method is used as interface implementation, so it is not unused // method is used as interface implementation, so it is not unused
sym.check_deprecated (source_reference); sym.check_deprecated (source_reference);
sym.check_experimental (source_reference);
sym.used = true; sym.used = true;
} else { } else {
error = true; error = true;
...@@ -1213,6 +1216,7 @@ public class Vala.Class : ObjectTypeSymbol { ...@@ -1213,6 +1216,7 @@ public class Vala.Class : ObjectTypeSymbol {
if (sym is Property) { if (sym is Property) {
// property is used as interface implementation, so it is not unused // property is used as interface implementation, so it is not unused
sym.check_deprecated (source_reference); sym.check_deprecated (source_reference);
sym.check_experimental (source_reference);
sym.used = true; sym.used = true;
} else { } else {
error = true; error = true;
......
...@@ -226,6 +226,14 @@ public class Vala.CodeWriter : CodeVisitor { ...@@ -226,6 +226,14 @@ public class Vala.CodeWriter : CodeVisitor {
} }
} }
private void emit_experimental_attribute (Symbol symbol) {
if (symbol.experimental) {
write_indent ();
write_string ("[Experimental]");
write_newline ();
}
}
public override void visit_class (Class cl) { public override void visit_class (Class cl) {
if (cl.external_package) { if (cl.external_package) {
return; return;
...@@ -248,6 +256,7 @@ public class Vala.CodeWriter : CodeVisitor { ...@@ -248,6 +256,7 @@ public class Vala.CodeWriter : CodeVisitor {
} }
emit_deprecated_attribute (cl); emit_deprecated_attribute (cl);
emit_experimental_attribute (cl);
write_indent (); write_indent ();
...@@ -407,6 +416,7 @@ public class Vala.CodeWriter : CodeVisitor { ...@@ -407,6 +416,7 @@ public class Vala.CodeWriter : CodeVisitor {
} }
emit_deprecated_attribute (st); emit_deprecated_attribute (st);
emit_experimental_attribute (st);
write_indent (); write_indent ();
...@@ -490,6 +500,7 @@ public class Vala.CodeWriter : CodeVisitor { ...@@ -490,6 +500,7 @@ public class Vala.CodeWriter : CodeVisitor {
} }
emit_deprecated_attribute (iface); emit_deprecated_attribute (iface);
emit_experimental_attribute (iface);
write_indent (); write_indent ();
...@@ -568,6 +579,7 @@ public class Vala.CodeWriter : CodeVisitor { ...@@ -568,6 +579,7 @@ public class Vala.CodeWriter : CodeVisitor {
} }
emit_deprecated_attribute (en); emit_deprecated_attribute (en);
emit_experimental_attribute (en);
write_indent (); write_indent ();
...@@ -644,6 +656,7 @@ public class Vala.CodeWriter : CodeVisitor { ...@@ -644,6 +656,7 @@ public class Vala.CodeWriter : CodeVisitor {
} }
emit_deprecated_attribute (edomain); emit_deprecated_attribute (edomain);
emit_experimental_attribute (edomain);
write_indent (); write_indent ();
...@@ -680,6 +693,7 @@ public class Vala.CodeWriter : CodeVisitor { ...@@ -680,6 +693,7 @@ public class Vala.CodeWriter : CodeVisitor {
} }
emit_deprecated_attribute (c); emit_deprecated_attribute (c);
emit_experimental_attribute (c);
bool custom_cname = (c.get_cname () != c.get_default_cname ()); bool custom_cname = (c.get_cname () != c.get_default_cname ());
bool custom_cheaders = (c.parent_symbol is Namespace); bool custom_cheaders = (c.parent_symbol is Namespace);
...@@ -728,6 +742,7 @@ public class Vala.CodeWriter : CodeVisitor { ...@@ -728,6 +742,7 @@ public class Vala.CodeWriter : CodeVisitor {
} }
emit_deprecated_attribute (f); emit_deprecated_attribute (f);
emit_experimental_attribute (f);
bool custom_cname = (f.get_cname () != f.get_default_cname ()); bool custom_cname = (f.get_cname () != f.get_default_cname ());
bool custom_ctype = (f.get_ctype () != null); bool custom_ctype = (f.get_ctype () != null);
...@@ -934,6 +949,7 @@ public class Vala.CodeWriter : CodeVisitor { ...@@ -934,6 +949,7 @@ public class Vala.CodeWriter : CodeVisitor {
} }
emit_deprecated_attribute (cb); emit_deprecated_attribute (cb);
emit_experimental_attribute (cb);
write_indent (); write_indent ();
...@@ -1040,6 +1056,7 @@ public class Vala.CodeWriter : CodeVisitor { ...@@ -1040,6 +1056,7 @@ public class Vala.CodeWriter : CodeVisitor {
} }
emit_deprecated_attribute (m); emit_deprecated_attribute (m);
emit_experimental_attribute (m);
var ccode_params = new StringBuilder (); var ccode_params = new StringBuilder ();
var separator = ""; var separator = "";
...@@ -1192,6 +1209,7 @@ public class Vala.CodeWriter : CodeVisitor { ...@@ -1192,6 +1209,7 @@ public class Vala.CodeWriter : CodeVisitor {
} }
emit_deprecated_attribute (prop); emit_deprecated_attribute (prop);
emit_experimental_attribute (prop);
if (prop.no_accessor_method) { if (prop.no_accessor_method) {
write_indent (); write_indent ();
...@@ -1290,6 +1308,7 @@ public class Vala.CodeWriter : CodeVisitor { ...@@ -1290,6 +1308,7 @@ public class Vala.CodeWriter : CodeVisitor {
} }
emit_deprecated_attribute (sig); emit_deprecated_attribute (sig);
emit_experimental_attribute (sig);
write_indent (); write_indent ();
write_accessibility (sig); write_accessibility (sig);
......
...@@ -159,6 +159,8 @@ public class Vala.Constant : Symbol, Lockable { ...@@ -159,6 +159,8 @@ public class Vala.Constant : Symbol, Lockable {
process_ccode_attribute (a); process_ccode_attribute (a);
} else if (a.name == "Deprecated") { } else if (a.name == "Deprecated") {
process_deprecated_attribute (a); process_deprecated_attribute (a);
} else if (a.name == "Experimental") {
process_experimental_attribute (a);
} }
} }
} }
......
...@@ -313,6 +313,8 @@ public class Vala.Delegate : TypeSymbol { ...@@ -313,6 +313,8 @@ public class Vala.Delegate : TypeSymbol {
process_ccode_attribute (a); process_ccode_attribute (a);
} else if (a.name == "Deprecated") { } else if (a.name == "Deprecated") {
process_deprecated_attribute (a); process_deprecated_attribute (a);
} else if (a.name == "Experimental") {
process_experimental_attribute (a);
} }
} }
} }
......
...@@ -197,6 +197,8 @@ public class Vala.ErrorDomain : TypeSymbol { ...@@ -197,6 +197,8 @@ public class Vala.ErrorDomain : TypeSymbol {
process_ccode_attribute (a); process_ccode_attribute (a);
} else if (a.name == "Deprecated") { } else if (a.name == "Deprecated") {
process_deprecated_attribute (a); process_deprecated_attribute (a);
} else if (a.name == "Experimental") {
process_experimental_attribute (a);
} }
} }
} }
......
...@@ -142,6 +142,8 @@ public class Vala.Field : Variable, Lockable { ...@@ -142,6 +142,8 @@ public class Vala.Field : Variable, Lockable {
process_ccode_attribute (a); process_ccode_attribute (a);
} else if (a.name == "Deprecated") { } else if (a.name == "Deprecated") {
process_deprecated_attribute (a); process_deprecated_attribute (a);
} else if (a.name == "Experimental") {
process_experimental_attribute (a);
} }
} }
} }
......
...@@ -493,6 +493,8 @@ public class Vala.Interface : ObjectTypeSymbol { ...@@ -493,6 +493,8 @@ public class Vala.Interface : ObjectTypeSymbol {
process_ccode_attribute (a); process_ccode_attribute (a);
} else if (a.name == "Deprecated") { } else if (a.name == "Deprecated") {
process_deprecated_attribute (a); process_deprecated_attribute (a);
} else if (a.name == "Experimental") {
process_experimental_attribute (a);
} }
} }
} }
......
...@@ -138,6 +138,7 @@ public class Vala.LambdaExpression : Expression { ...@@ -138,6 +138,7 @@ public class Vala.LambdaExpression : Expression {
// track usage for flow analyzer // track usage for flow analyzer
method.used = true; method.used = true;
method.check_deprecated (source_reference); method.check_deprecated (source_reference);
method.check_experimental (source_reference);
if (!cb.has_target || !context.analyzer.is_in_instance_method ()) { if (!cb.has_target || !context.analyzer.is_in_instance_method ()) {
method.binding = MemberBinding.STATIC; method.binding = MemberBinding.STATIC;
......
...@@ -646,6 +646,7 @@ public class Vala.MemberAccess : Expression { ...@@ -646,6 +646,7 @@ public class Vala.MemberAccess : Expression {
member.used = true; member.used = true;
member.check_deprecated (source_reference); member.check_deprecated (source_reference);
member.check_experimental (source_reference);
if (access == SymbolAccessibility.PROTECTED) { if (access == SymbolAccessibility.PROTECTED) {
var target_type = (TypeSymbol) member.parent_symbol; var target_type = (TypeSymbol) member.parent_symbol;
......
...@@ -495,6 +495,8 @@ public class Vala.Method : Subroutine { ...@@ -495,6 +495,8 @@ public class Vala.Method : Subroutine {
process_deprecated_attribute (a); process_deprecated_attribute (a);
} else if (a.name == "NoThrow") { } else if (a.name == "NoThrow") {
get_error_types ().clear (); get_error_types ().clear ();
} else if (a.name == "Experimental") {
process_experimental_attribute (a);
} }
} }
} }
......
...@@ -179,6 +179,9 @@ public class Vala.Report : Object { ...@@ -179,6 +179,9 @@ public class Vala.Report : Object {
public static void deprecated (SourceReference? source, string message) { public static void deprecated (SourceReference? source, string message) {
CodeContext.get ().report.depr (source, message); CodeContext.get ().report.depr (source, message);
} }
public static void experimental (SourceReference? source, string message) {
CodeContext.get ().report.depr (source, message);
}
public static void warning (SourceReference? source, string message) { public static void warning (SourceReference? source, string message) {
CodeContext.get ().report.warn (source, message); CodeContext.get ().report.warn (source, message);
} }
......
...@@ -271,6 +271,8 @@ public class Vala.Signal : Symbol, Lockable { ...@@ -271,6 +271,8 @@ public class Vala.Signal : Symbol, Lockable {
process_signal_attribute (a); process_signal_attribute (a);
} else if (a.name == "Deprecated") { } else if (a.name == "Deprecated") {
process_deprecated_attribute (a); process_deprecated_attribute (a);
} else if (a.name == "Experimental") {
process_experimental_attribute (a);
} }
} }
} }
......
...@@ -511,6 +511,8 @@ public class Vala.Struct : TypeSymbol { ...@@ -511,6 +511,8 @@ public class Vala.Struct : TypeSymbol {
process_deprecated_attribute (a); process_deprecated_attribute (a);
} else if (a.name == "GIR") { } else if (a.name == "GIR") {
process_gir_attribute (a); process_gir_attribute (a);
} else if (a.name == "Experimental") {
process_experimental_attribute (a);
} }
} }
} }
......
...@@ -94,6 +94,11 @@ public abstract class Vala.Symbol : CodeNode { ...@@ -94,6 +94,11 @@ public abstract class Vala.Symbol : CodeNode {
*/ */
public string? replacement { get; set; default = null; } public string? replacement { get; set; default = null; }
/**
* Specifies whether this symbol is experimental.
*/
public bool experimental { get; set; default = false; }
/** /**
* Specifies whether this symbol has been accessed. * Specifies whether this symbol has been accessed.
*/ */
...@@ -501,6 +506,32 @@ public abstract class Vala.Symbol : CodeNode { ...@@ -501,6 +506,32 @@ public abstract class Vala.Symbol : CodeNode {
} }
} }
/**
* Process a [Experimental] attribute
*/
public virtual void process_experimental_attribute (Attribute attr) {
if (attr.name != "Experimental") {
return;
}
experimental = true;
}
/**
* Check to see if the symbol is experimental, and emit a warning
* if it is.
*/
public bool check_experimental (SourceReference? source_ref = null) {
if (experimental) {
if (!CodeContext.get ().experimental) {
Report.experimental (source_ref, "%s is experimental".printf (get_full_name ()));
}
return true;
} else {
return false;
}
}
/** /**
* Sets the C header filename of this namespace to the specified * Sets the C header filename of this namespace to the specified
* filename. * filename.
......
...@@ -5930,7 +5930,9 @@ namespace Gtk { ...@@ -5930,7 +5930,9 @@ namespace Gtk {
public bool urgency_hint { get; set; } public bool urgency_hint { get; set; }
[NoAccessorMethod] [NoAccessorMethod]
public Gtk.WindowPosition window_position { get; set; } public Gtk.WindowPosition window_position { get; set; }
[Experimental]
public virtual signal void default_activated (); public virtual signal void default_activated ();
[Experimental]
public virtual signal void focus_activated (); public virtual signal void focus_activated ();
public virtual signal bool frame_event (Gdk.Event event); public virtual signal bool frame_event (Gdk.Event event);
public virtual signal void keys_changed (); public virtual signal void keys_changed ();
......
...@@ -5745,7 +5745,9 @@ namespace Gtk { ...@@ -5745,7 +5745,9 @@ namespace Gtk {
public bool urgency_hint { get; set; } public bool urgency_hint { get; set; }
[NoAccessorMethod] [NoAccessorMethod]
public Gtk.WindowPosition window_position { get; set; } public Gtk.WindowPosition window_position { get; set; }
[Experimental]
public virtual signal void default_activated (); public virtual signal void default_activated ();
[Experimental]
public virtual signal void focus_activated (); public virtual signal void focus_activated ();
public virtual signal void keys_changed (); public virtual signal void keys_changed ();
[HasEmitter] [HasEmitter]
......
...@@ -489,6 +489,10 @@ public class Vala.GIdlParser : CodeVisitor { ...@@ -489,6 +489,10 @@ public class Vala.GIdlParser : CodeVisitor {
foreach (string type_param_name in eval (nv[1]).split (",")) { foreach (string type_param_name in eval (nv[1]).split (",")) {
cb.add_type_parameter (new TypeParameter (type_param_name, current_source_reference)); cb.add_type_parameter (new TypeParameter (type_param_name, current_source_reference));
} }
} else if (nv[0] == "experimental") {
if (eval (nv[1]) == "1") {
cb.experimental = true;
}
} }
} }
} }
...@@ -667,6 +671,10 @@ public class Vala.GIdlParser : CodeVisitor { ...@@ -667,6 +671,10 @@ public class Vala.GIdlParser : CodeVisitor {
if (eval (nv[1]) == "0") { if (eval (nv[1]) == "0") {
st.has_destroy_function = false; st.has_destroy_function = false;
} }
} else if (nv[0] == "experimental") {
if (eval (nv[1]) == "1") {
st.experimental = true;
}
} }
} }
} }
...@@ -757,6 +765,10 @@ public class Vala.GIdlParser : CodeVisitor { ...@@ -757,6 +765,10 @@ public class Vala.GIdlParser : CodeVisitor {
foreach (string type_param_name in eval (nv[1]).split (",")) { foreach (string type_param_name in eval (nv[1]).split (",")) {
cl.add_type_parameter (new TypeParameter (type_param_name, current_source_reference)); cl.add_type_parameter (new TypeParameter (type_param_name, current_source_reference));
} }
} else if (nv[0] == "experimental") {
if (eval (nv[1]) == "1") {
cl.experimental = true;
}
} }
} }
} }
...@@ -848,6 +860,10 @@ public class Vala.GIdlParser : CodeVisitor { ...@@ -848,6 +860,10 @@ public class Vala.GIdlParser : CodeVisitor {
if (eval (nv[1]) == "1") { if (eval (nv[1]) == "1") {
return; return;
} }
} else if (nv[0] == "experimental") {
if (eval (nv[1]) == "1") {
st.experimental = true;
}
} }
} }
} }
...@@ -996,6 +1012,10 @@ public class Vala.GIdlParser : CodeVisitor { ...@@ -996,6 +1012,10 @@ public class Vala.GIdlParser : CodeVisitor {
if (eval (nv[1]) == "0") { if (eval (nv[1]) == "0") {
st.has_destroy_function = false; st.has_destroy_function = false;
} }
} else if (nv[0] == "experimental") {
if (eval (nv[1]) == "1") {
st.experimental = true;
}
} }
} }
} }
...@@ -1071,6 +1091,10 @@ public class Vala.GIdlParser : CodeVisitor { ...@@ -1071,6 +1091,10 @@ public class Vala.GIdlParser : CodeVisitor {
if (eval (nv[1]) == "1") { if (eval (nv[1]) == "1") {
ref_function_void = true; ref_function_void = true;
} }
} else if (nv[0] == "experimental") {
if (eval (nv[1]) == "1") {
cl.experimental = true;
}
} }
} }
} }
...@@ -1227,6 +1251,10 @@ public class Vala.GIdlParser : CodeVisitor { ...@@ -1227,6 +1251,10 @@ public class Vala.GIdlParser : CodeVisitor {
m.access = SymbolAccessibility.PUBLIC; m.access = SymbolAccessibility.PUBLIC;
m.set_cname (eval(nv[1])); m.set_cname (eval(nv[1]));
en.add_method (m); en.add_method (m);
} else if (nv[0] == "experimental") {
if (eval (nv[1]) == "1") {
en.experimental = true;
}
} }
} }
} }
...@@ -1315,6 +1343,10 @@ public class Vala.GIdlParser : CodeVisitor { ...@@ -1315,6 +1343,10 @@ public class Vala.GIdlParser : CodeVisitor {
if (eval (nv[1]) == "1") { if (eval (nv[1]) == "1") {
cl.is_abstract = true; cl.is_abstract = true;
} }
} else if (nv[0] == "experimental") {
if (eval (nv[1]) == "1") {
cl.experimental = true;
}
} }
} }
} }
...@@ -2065,6 +2097,10 @@ public class Vala.GIdlParser : CodeVisitor { ...@@ -2065,6 +2097,10 @@ public class Vala.GIdlParser : CodeVisitor {
m.set_cname (m.name); m.set_cname (m.name);
m.name = symbol.substring (prefix.length); m.name = symbol.substring (prefix.length);
} }
} else if (nv[0] == "experimental") {
if (eval (nv[1]) == "1") {
m.experimental = true;
}
} }
} }
} }
...@@ -2439,6 +2475,10 @@ public class Vala.GIdlParser : CodeVisitor { ...@@ -2439,6 +2475,10 @@ public class Vala.GIdlParser : CodeVisitor {
} }
} else if (nv[0] == "type_name") { } else if (nv[0] == "type_name") {
prop.property_type = parse_type_from_string (eval (nv[1]), false); prop.property_type = parse_type_from_string (eval (nv[1]), false);
} else if (nv[0] == "experimental") {
if (eval (nv[1]) == "1") {
prop.experimental = true;
}
} }
} }
} }
...@@ -2479,6 +2519,10 @@ public class Vala.GIdlParser : CodeVisitor { ...@@ -2479,6 +2519,10 @@ public class Vala.GIdlParser : CodeVisitor {
if (eval (nv[1]) == "1") { if (eval (nv[1]) == "1") {
return null; return null;
} }
} else if (nv[0] == "experimental") {
if (eval (nv[1]) == "1") {
c.experimental = true;
}
} }
} }
} }
...@@ -2505,6 +2549,7 @@ public class Vala.GIdlParser : CodeVisitor { ...@@ -2505,6 +2549,7 @@ public class Vala.GIdlParser : CodeVisitor {
bool deprecated = false; bool deprecated = false;
string deprecated_since = null; string deprecated_since = null;
string replacement = null; string replacement = null;
bool experimental = false;
var attributes = get_attributes ("%s.%s".printf (current_data_type.get_cname (), node.name)); var attributes = get_attributes ("%s.%s".printf (current_data_type.get_cname (), node.name));
if (attributes != null) { if (attributes != null) {
...@@ -2554,6 +2599,10 @@ public class Vala.GIdlParser : CodeVisitor { ...@@ -2554,6 +2599,10 @@ public class Vala.GIdlParser : CodeVisitor {
array_length_cname = eval (nv[1]); array_length_cname = eval (nv[1]);
} else if (nv[0] == "array_length_type") { } else if (nv[0] == "array_length_type") {
array_length_type = eval (nv[1]); array_length_type = eval (nv[1]);
} else if (nv[0] == "experimental") {
if (eval (nv[1]) == "1") {
experimental = true;
}
} }
} }
} }
...@@ -2591,6 +2640,10 @@ public class Vala.GIdlParser : CodeVisitor { ...@@ -2591,6 +2640,10 @@ public class Vala.GIdlParser : CodeVisitor {
} }
} }
if (experimental) {
field.experimental = true;
}
if (ctype != null) { if (ctype != null) {
field.set_ctype (ctype); field.set_ctype (ctype);
} }
...@@ -2730,6 +2783,10 @@ public class Vala.GIdlParser : CodeVisitor { ...@@ -2730,6 +2783,10 @@ public class Vala.GIdlParser : CodeVisitor {
sig.return_type = parse_type_from_string (eval (nv[1]), false); sig.return_type = parse_type_from_string (eval (nv[1]), false);
} else if (nv[0] == "type_arguments") { } else if (nv[0] == "type_arguments") {
parse_type_arguments_from_string (sig.return_type, eval (nv[1])); parse_type_arguments_from_string (sig.return_type, eval (nv[1]));
} else if (nv[0] == "experimental") {
if (eval (nv[1]) == "1") {
sig.experimental = true;
}
} }
} }
if (ns_name != null) { if (ns_name != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment