Author: peterw
Date: 2006-07-18 23:41:02 -0400 (Tue, 18 Jul 2006)
New Revision: 62724
Added:
trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/TargetValidity.cs
Modified:
trunk/mbuild/MBuildDynamic.Core/ChangeLog
trunk/mbuild/MBuildDynamic.Core/Core.bundle
trunk/mbuild/Monkeywrench.dll.sources
trunk/mbuild/Monkeywrench/ChangeLog
trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/BuildfileParser.jay
trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/GraphBuilder.cs
trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/ProviderBuilder.cs
trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/TargetBuilder.cs
trunk/mbuild/Monkeywrench/Monkeywrench/SourceSettings.cs
trunk/mbuild/mb-bundlegen/ChangeLog
trunk/mbuild/mb-bundlegen/Parser.jay
trunk/mbuild/mb-bundlegen/ParserHelper.cs
Log:
mb-bundlegen:
2006-07-18 Peter Williams <[EMAIL PROTECTED]>
* Parser.jay: Add a way to specify 'manual' build functions, which
don't take a preconstructed result argument. Sometimes this is needed.
* ParserHelper.cs (GenBuildManual): New helper to generate CodeDom
for manual build functions.
(AddRuleBuildFunc): Take different paths depending on whether this
is a manual build function or not.
MBuildDynamic.Core:
2006-07-18 Peter Williams <[EMAIL PROTECTED]>
* Core.bundle (Switch): Of course. Preconstructed results fundamentally
don't work with Switch. Use the new 'manual build' syntax to avoid this
problem.
Monkeywrench:
2006-07-18 Peter Williams <[EMAIL PROTECTED]>
Fix requests of targets in providers to the side.
* Monkeywrench.Compiler/TargetBuilder.cs (Validity): New
TargetValidity enum member, superseding OnlyRequested.
* Monkeywrench.Compiler/TargetValidity.cs: New enum.
* Monkeywrench.Compiler/ProviderBuilder.cs (EnsureTarget): Helper
to get a TargetBuilder. Mostly old DefineTarget code.
(CanDefineTarget): Return true if it will be OK to define a target
of the given name.
(LookupTarget): New function, ensures a target but only sets its
validity to referenced ...
(DoneRequesting): ... so that if we get here, and the target hasn't
been defined, return an error.
* Monkeywrench.Compiler/GraphBuilder.cs (LookupTarget): Use the new
ProviderBuilder.LookupTarget. This way we can reference targets
in parallel providers but maintain the invariant that targets can
only be created via request from parent providers.
* Monkeywrench.Compiler/BuildfileParser.jay (CheckTargetName): Use
the new ProviderBuilder.CanDefineTarget to check for already-defined
targets.
* Monkeywrench/SourceSettings.cs (SubpathToBasis): Map '.' to '/'.
Modified: trunk/mbuild/MBuildDynamic.Core/ChangeLog
===================================================================
--- trunk/mbuild/MBuildDynamic.Core/ChangeLog 2006-07-19 02:22:39 UTC (rev
62723)
+++ trunk/mbuild/MBuildDynamic.Core/ChangeLog 2006-07-19 03:41:02 UTC (rev
62724)
@@ -1,5 +1,11 @@
2006-07-18 Peter Williams <[EMAIL PROTECTED]>
+ * Core.bundle (Switch): Of course. Preconstructed results fundamentally
+ don't work with Switch. Use the new 'manual build' syntax to avoid this
+ problem.
+
+2006-07-18 Peter Williams <[EMAIL PROTECTED]>
+
* Core.Tools.bundle: Another new syntax: the preconstructed-result /
result type inference change.
Modified: trunk/mbuild/MBuildDynamic.Core/Core.bundle
===================================================================
--- trunk/mbuild/MBuildDynamic.Core/Core.bundle 2006-07-19 02:22:39 UTC (rev
62723)
+++ trunk/mbuild/MBuildDynamic.Core/Core.bundle 2006-07-19 03:41:02 UTC (rev
62724)
@@ -280,23 +280,21 @@
return deepest_subclass;
@}
- build (Result res, ctxt) @{
+ !build (Result, ctxt) @{
if (cases.Length != values.Length) {
ctxt.Logger.Error (2051, "Number of cases not
the same as " +
"number of values in Switch rule",
cases.ToString ());
- return true;
+ return null;
}
for (int i = 0; i < cases.Length; i++) {
- if (cases[i]) {
- res = values[i];
- return false;
- }
+ if (cases[i])
+ return (Result) values[i].Clone ();
}
ctxt.Logger.Error (2051, "No case was chosen in Switch
rule",
"(You can set a default by having a case whose
condition is \"true\")");
- return true;
+ return null;
@}
}
Modified: trunk/mbuild/Monkeywrench/ChangeLog
===================================================================
--- trunk/mbuild/Monkeywrench/ChangeLog 2006-07-19 02:22:39 UTC (rev 62723)
+++ trunk/mbuild/Monkeywrench/ChangeLog 2006-07-19 03:41:02 UTC (rev 62724)
@@ -1,5 +1,34 @@
2006-07-18 Peter Williams <[EMAIL PROTECTED]>
+ Fix requests of targets in providers to the side.
+
+ * Monkeywrench.Compiler/TargetBuilder.cs (Validity): New
+ TargetValidity enum member, superseding OnlyRequested.
+
+ * Monkeywrench.Compiler/TargetValidity.cs: New enum.
+
+ * Monkeywrench.Compiler/ProviderBuilder.cs (EnsureTarget): Helper
+ to get a TargetBuilder. Mostly old DefineTarget code.
+ (CanDefineTarget): Return true if it will be OK to define a target
+ of the given name.
+ (LookupTarget): New function, ensures a target but only sets its
+ validity to referenced ...
+ (DoneRequesting): ... so that if we get here, and the target hasn't
+ been defined, return an error.
+
+ * Monkeywrench.Compiler/GraphBuilder.cs (LookupTarget): Use the new
+ ProviderBuilder.LookupTarget. This way we can reference targets
+ in parallel providers but maintain the invariant that targets can
+ only be created via request from parent providers.
+
+ * Monkeywrench.Compiler/BuildfileParser.jay (CheckTargetName): Use
+ the new ProviderBuilder.CanDefineTarget to check for already-defined
+ targets.
+
+ * Monkeywrench/SourceSettings.cs (SubpathToBasis): Map '.' to '/'.
+
+2006-07-18 Peter Williams <[EMAIL PROTECTED]>
+
* Monkeywrench/MakeDictionaryRule.cs (Build): Use CreateResultObject
and GeneralResultType.
Modified: trunk/mbuild/Monkeywrench/Monkeywrench/SourceSettings.cs
===================================================================
--- trunk/mbuild/Monkeywrench/Monkeywrench/SourceSettings.cs 2006-07-19
02:22:39 UTC (rev 62723)
+++ trunk/mbuild/Monkeywrench/Monkeywrench/SourceSettings.cs 2006-07-19
03:41:02 UTC (rev 62724)
@@ -88,7 +88,7 @@
// Convert a basis to a subpath. There exists a
// basis for every directory-only subpath.
- if (subpath.Length == 0)
+ if (subpath.Length == 0 || subpath == ".")
return "/";
string s;
Modified: trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/BuildfileParser.jay
===================================================================
--- trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/BuildfileParser.jay
2006-07-19 02:22:39 UTC (rev 62723)
+++ trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/BuildfileParser.jay
2006-07-19 03:41:02 UTC (rev 62724)
@@ -272,8 +272,7 @@
return false;
}
- TargetBuilder tb = pb.GetTarget (name);
- if (tb != null && !tb.OnlyRequested) {
+ if (!pb.CanDefineTarget (name)) {
Error (2009, "Target \'" + name + "\' already
defined.", null);
return false;
}
Modified: trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/GraphBuilder.cs
===================================================================
--- trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/GraphBuilder.cs
2006-07-19 02:22:39 UTC (rev 62723)
+++ trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/GraphBuilder.cs
2006-07-19 03:41:02 UTC (rev 62724)
@@ -219,12 +219,7 @@
string basis = name.Substring (0, i + 1); // include trailing slash
ProviderBuilder pb = GetProviderBuilder (basis);
- TargetBuilder tb = pb.GetTarget (basename);
-
- if (tb == null)
- throw new Exception ("Referencing undefined target " + name);
-
- return tb.Id;
+ return pb.LookupTarget (basename);
}
///////////////////////////////////////////
Modified: trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/ProviderBuilder.cs
===================================================================
--- trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/ProviderBuilder.cs
2006-07-19 02:22:39 UTC (rev 62723)
+++ trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/ProviderBuilder.cs
2006-07-19 03:41:02 UTC (rev 62724)
@@ -78,20 +78,22 @@
List<TargetBuilder> def_waitlist = null;
- public TargetBuilder DefineTarget (string name) {
- check_done ();
-
+ TargetBuilder EnsureTarget (string name)
+ {
TargetBuilder tb;
+ int idx;
- if (targets.ContainsKey (name)) {
+ if (targets.ContainsKey (name))
tb = targets[name];
-
- if (!tb.OnlyRequested)
- // should be error 2009
- throw new Exception (String.Format ("Target {0} being
redefined", name));
-
- tb.OnlyRequested = false;
+ else if (def_waitlist != null &&
+ ((idx = def_waitlist.FindIndex (delegate (TargetBuilder q)
{
+ return q.Name == name;
+ })) >= 0))
+ {
+ tb = def_waitlist[idx];
} else {
+ check_done ();
+
tb = new TargetBuilder (this);
if (def_waitlist == null)
@@ -107,28 +109,56 @@
return tb;
}
- public int RequestTarget (string name) {
- check_done ();
+ public TargetBuilder DefineTarget (string name)
+ {
+ TargetBuilder tb = EnsureTarget (name);
- TargetBuilder tb;
- int idx;
+ if (tb.Validity == TargetValidity.Defined)
+ // should be error 2009
+ throw ExHelp.App ("Target {0} being redefined", name);
- if (targets.ContainsKey (name))
- tb = targets[name];
- else if (def_waitlist != null &&
- ((idx = def_waitlist.FindIndex (delegate (TargetBuilder q)
{
- return q.Name == name;
- })) >= 0))
- {
- tb = def_waitlist[idx];
- } else {
- tb = DefineTarget (name);
- tb.OnlyRequested = true;
- }
+ tb.Validity = TargetValidity.Defined;
+ return tb;
+ }
+ public bool CanDefineTarget (string name)
+ {
+ if (!targets.ContainsKey (name))
+ return true;
+
+ // We ignore def_waitlist. Not 100% sure that is
+ // correct but this function is meant to be called
+ // from the buildfile parser, not during fixup.
+
+ TargetBuilder tb = targets[name];
+
+ if (tb.Validity != TargetValidity.Defined)
+ return true;
+
+ return false;
+ }
+
+ public int RequestTarget (string name)
+ {
+ TargetBuilder tb = EnsureTarget (name);
+
+ if (tb.Validity == TargetValidity.Referenced ||
+ tb.Validity == TargetValidity.Undefined)
+ tb.Validity = TargetValidity.Requested;
+
return tb.Id;
}
+ public int LookupTarget (string name)
+ {
+ TargetBuilder tb = EnsureTarget (name);
+
+ if (tb.Validity == TargetValidity.Undefined)
+ tb.Validity = TargetValidity.Referenced;
+
+ return tb.Id;
+ }
+
public virtual bool DoneRequesting (string basis, BundleManager bm,
ITargetRequestSink requests,
IWarningLogger logger) {
if (done)
@@ -155,7 +185,15 @@
foreach (TargetBuilder tb in keeplist) {
targets[tb.Name] = tb;
- if (tb.OnlyRequested) {
+ if (tb.Validity == TargetValidity.Referenced) {
+ // FIXME: this error message sucks
+ logger.Error (2000, "A target was referenced from
another provider " +
+ "that was not formally allowed to request
it, and the " +
+ "target was not defined by its provider",
tb.FullName);
+ return true;
+ }
+
+ if (tb.Validity == TargetValidity.Requested) {
Type rule = namecontext.TryDepRuleMatch (tb.FullName,
logger);
if (rule == null) {
Modified: trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/TargetBuilder.cs
===================================================================
--- trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/TargetBuilder.cs
2006-07-19 02:22:39 UTC (rev 62723)
+++ trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/TargetBuilder.cs
2006-07-19 03:41:02 UTC (rev 62724)
@@ -56,13 +56,8 @@
}
}
- bool only_requested = false;
+ internal TargetValidity Validity = TargetValidity.Undefined;
- internal bool OnlyRequested {
- get { return only_requested; }
- set { only_requested = value; }
- }
-
public void SetName (string n)
{
// Needed because the Name property that is overridden
Added: trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/TargetValidity.cs
===================================================================
--- trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/TargetValidity.cs
2006-07-19 02:22:39 UTC (rev 62723)
+++ trunk/mbuild/Monkeywrench/Monkeywrench.Compiler/TargetValidity.cs
2006-07-19 03:41:02 UTC (rev 62724)
@@ -0,0 +1,31 @@
+namespace Monkeywrench.Compiler {
+
+ public enum TargetValidity {
+
+ Undefined,
+
+ // The target has been explicitly defined
+ // in its provider, or it was requested
+ // and successfully constructed during fixup
+
+ Defined,
+
+ // Another provider, above this target's
+ // provider in the heirarchy, has referenced
+ // this target, and matchers will be used to
+ // try and automatically construct it
+
+ Requested,
+
+ // Another provider, not above this target's
+ // provider in the heirarchy, has referenced
+ // this target. If it ends up not being explicitly
+ // defined, that is an error. (The above conditions
+ // make it so that all the targets in a given
+ // provider can be known by parsing only the given
+ // provider and all its parents.)
+
+ Referenced
+ }
+
+}
Modified: trunk/mbuild/Monkeywrench.dll.sources
===================================================================
--- trunk/mbuild/Monkeywrench.dll.sources 2006-07-19 02:22:39 UTC (rev
62723)
+++ trunk/mbuild/Monkeywrench.dll.sources 2006-07-19 03:41:02 UTC (rev
62724)
@@ -37,5 +37,6 @@
Monkeywrench/Monkeywrench.Compiler/ProviderLoaderBase.cs
Monkeywrench/Monkeywrench.Compiler/TargetBuilder.cs
Monkeywrench/Monkeywrench.Compiler/TargetTagInfo.cs
+Monkeywrench/Monkeywrench.Compiler/TargetValidity.cs
Monkeywrench/Monkeywrench.Compiler/XmlGraphSerializer.cs
Monkeywrench/Monkeywrench.Compiler/XmlBackedGraph.cs
Modified: trunk/mbuild/mb-bundlegen/ChangeLog
===================================================================
--- trunk/mbuild/mb-bundlegen/ChangeLog 2006-07-19 02:22:39 UTC (rev 62723)
+++ trunk/mbuild/mb-bundlegen/ChangeLog 2006-07-19 03:41:02 UTC (rev 62724)
@@ -1,5 +1,15 @@
2006-07-18 Peter Williams <[EMAIL PROTECTED]>
+ * Parser.jay: Add a way to specify 'manual' build functions, which
+ don't take a preconstructed result argument. Sometimes this is needed.
+
+ * ParserHelper.cs (GenBuildManual): New helper to generate CodeDom
+ for manual build functions.
+ (AddRuleBuildFunc): Take different paths depending on whether this
+ is a manual build function or not.
+
+2006-07-18 Peter Williams <[EMAIL PROTECTED]>
+
* Tokenizer.cs: Add a 'restype' token.
* Parser.jay: Add new syntax to support preconstructed results: a result
Modified: trunk/mbuild/mb-bundlegen/Parser.jay
===================================================================
--- trunk/mbuild/mb-bundlegen/Parser.jay 2006-07-19 02:22:39 UTC (rev
62723)
+++ trunk/mbuild/mb-bundlegen/Parser.jay 2006-07-19 03:41:02 UTC (rev
62724)
@@ -443,8 +443,12 @@
build_func_definition
: BUILD OPEN_PARENS classname IDENTIFIER COMMA IDENTIFIER CLOSE_PARENS
NATIVE_CODE
{
- ph.AddRuleBuildFunc ((string) $3, (string) $4, (string) $6,
(string) $8);
+ ph.AddRuleBuildFunc (false, (string) $3, (string) $4, (string)
$6, (string) $8);
}
+ | BANG BUILD OPEN_PARENS classname COMMA IDENTIFIER CLOSE_PARENS
NATIVE_CODE
+ {
+ ph.AddRuleBuildFunc (true, (string) $4, "unused", (string) $6,
(string) $8);
+ }
;
rule_tags_statement
Modified: trunk/mbuild/mb-bundlegen/ParserHelper.cs
===================================================================
--- trunk/mbuild/mb-bundlegen/ParserHelper.cs 2006-07-19 02:22:39 UTC (rev
62723)
+++ trunk/mbuild/mb-bundlegen/ParserHelper.cs 2006-07-19 03:41:02 UTC (rev
62724)
@@ -1262,37 +1262,30 @@
ra_cleararg.Statements.Add (assg);
}
- public void AddRuleBuildFunc (string ret_class, string ret_arg, string
context_arg, string code)
+ public void AddRuleBuildFunc (bool is_manual, string ret_class, string
ret_arg,
+ string context_arg, string code)
{
// FIXME: allow retclass to be 'bool', 'string', etc and do the
// appropriate conversions.
- CodeParameterDeclarationExpression p1 =
- new CodeParameterDeclarationExpression (ret_class, ret_arg);
- CodeParameterDeclarationExpression p2 =
+ CodeParameterDeclarationExpression p =
new CodeParameterDeclarationExpression (tr_icontext,
context_arg);
- CodeStatement stmt = new CodeSnippetStatement (code);
- stmt.LinePragma = lexer.ChunkBeginLinePragma;
-
CodeMemberMethod meth = new CodeMemberMethod ();
- meth.Name = "BuildImpl";
- meth.Attributes = MemberAttributes.Private;
- meth.ReturnType = tr_bool;
- meth.Parameters.Add (p1);
- meth.Parameters.Add (p2);
- meth.Statements.Add (stmt);
- cur_type.Members.Add (meth);
-
- meth = new CodeMemberMethod ();
meth.Name = "Build";
meth.Attributes = MemberAttributes.Public |
MemberAttributes.Override;
meth.ReturnType = tr_result;
- meth.Parameters.Add (p2);
+ meth.Parameters.Add (p);
cur_type.Members.Add (meth);
- GenBuildWrapper (meth, ret_class, ret_arg, context_arg);
+ CodeStatement stmt = new CodeSnippetStatement (code);
+ stmt.LinePragma = lexer.ChunkBeginLinePragma;
+ if (is_manual)
+ GenBuildManual (meth, ret_class, context_arg, stmt);
+ else
+ GenBuildWrapped (meth, ret_class, ret_arg, context_arg, stmt);
+
// GeneralResultType
AddGeneralResultCode (ret_class);
@@ -1303,8 +1296,15 @@
hashtext.Append (code);
}
- void GenBuildWrapper (CodeMemberMethod meth, string ret_class, string
ret_arg, string context_arg)
+ void GenBuildManual (CodeMemberMethod meth, string ret_class, string
context_arg,
+ CodeStatement stmt)
{
+ meth.Statements.Add (stmt);
+ }
+
+ void GenBuildWrapped (CodeMemberMethod meth, string ret_class, string
ret_arg,
+ string context_arg, CodeStatement stmt)
+ {
CodeMethodInvokeExpression inv =
new CodeMethodInvokeExpression (expr_this,
"CreateResultObject",
new CodeExpression[0] {});
@@ -1330,6 +1330,22 @@
meth.Statements.Add (cond);
meth.Statements.Add (new CodeMethodReturnStatement (r1));
+
+ // BuildImpl
+
+ CodeParameterDeclarationExpression p1 =
+ new CodeParameterDeclarationExpression (ret_class, ret_arg);
+ CodeParameterDeclarationExpression p2 =
+ new CodeParameterDeclarationExpression (tr_icontext,
context_arg);
+
+ meth = new CodeMemberMethod ();
+ meth.Name = "BuildImpl";
+ meth.Attributes = MemberAttributes.Private;
+ meth.ReturnType = tr_bool;
+ meth.Parameters.Add (p1);
+ meth.Parameters.Add (p2);
+ meth.Statements.Add (stmt);
+ cur_type.Members.Add (meth);
}
public void StartRuleTags ()
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches