本文整理汇总了C#中Core.ResetForPrecompilation方法的典型用法代码示例。如果您正苦于以下问题:C# Core.ResetForPrecompilation方法的具体用法?C# Core.ResetForPrecompilation怎么用?C# Core.ResetForPrecompilation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Core
的用法示例。
在下文中一共展示了Core.ResetForPrecompilation方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseUserCodeCore
private static void ParseUserCodeCore(Core core, string expression, out List<AssociativeNode> astNodes, out List<AssociativeNode> commentNodes)
{
astNodes = new List<AssociativeNode>();
core.ResetForPrecompilation();
core.IsParsingCodeBlockNode = true;
core.ParsingMode = ParseMode.AllowNonAssignment;
ParseResult parseResult = ParserUtils.ParseWithCore(expression, core);
commentNodes = ParserUtils.GetAstNodes(parseResult.CommentBlockNode);
var nodes = ParserUtils.GetAstNodes(parseResult.CodeBlockNode);
Validity.Assert(nodes != null);
int index = 0;
int typedIdentIndex = 0;
foreach (var node in nodes)
{
var n = node as AssociativeNode;
Validity.Assert(n != null);
// Append the temporaries only if it is not a function def or class decl
bool isFunctionOrClassDef = n is FunctionDefinitionNode || n is ClassDeclNode;
// Handle non Binary expression nodes separately
if (n is ModifierStackNode)
{
core.BuildStatus.LogSemanticError(Resources.ModifierBlockNotSupported);
}
else if (n is ImportNode)
{
core.BuildStatus.LogSemanticError(Resources.ImportStatementNotSupported);
}
else if (isFunctionOrClassDef)
{
// Add node as it is
astNodes.Add(node);
}
else
{
// Handle temporary naming for temporary Binary exp. nodes and non-assignment nodes
var ben = node as BinaryExpressionNode;
if (ben != null && ben.Optr == Operator.assign)
{
var mNode = ben.RightNode as ModifierStackNode;
if (mNode != null)
{
core.BuildStatus.LogSemanticError(Resources.ModifierBlockNotSupported);
}
var lNode = ben.LeftNode as IdentifierNode;
if (lNode != null && lNode.Value == Constants.kTempProcLeftVar)
{
string name = Constants.kTempVarForNonAssignment + index;
var newNode = new BinaryExpressionNode(new IdentifierNode(name), ben.RightNode);
astNodes.Add(newNode);
index++;
}
else
{
// Add node as it is
astNodes.Add(node);
index++;
}
}
else
{
if (node is TypedIdentifierNode)
{
// e.g. a : int = %tTypedIdent_<Index>;
var ident = new IdentifierNode(Constants.kTempVarForTypedIdentifier + typedIdentIndex);
NodeUtils.CopyNodeLocation(ident, node);
var typedNode = new BinaryExpressionNode(node as TypedIdentifierNode, ident, Operator.assign);
NodeUtils.CopyNodeLocation(typedNode, node);
astNodes.Add(typedNode);
typedIdentIndex++;
}
else
{
string name = Constants.kTempVarForNonAssignment + index;
var newNode = new BinaryExpressionNode(new IdentifierNode(name), n);
astNodes.Add(newNode);
index++;
}
}
}
}
}
示例2: CompileCodeBlockAST
private static bool CompileCodeBlockAST(Core core, ParseParam parseParams)
{
var unboundIdentifiers = new Dictionary<int, List<VariableLine>>();
ProtoCore.BuildStatus buildStatus = null;
try
{
int blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
bool parsingPreloadFlag = core.IsParsingPreloadedAssembly;
bool parsingCbnFlag = core.IsParsingPreloadedAssembly;
core.IsParsingPreloadedAssembly = false;
core.IsParsingCodeBlockNode = true;
core.ResetForPrecompilation();
var astNodes = parseParams.ParsedNodes;
// Lookup namespace resolution map in elementResolver to rewrite
// partial classnames with their fully qualified names in ASTs
// before passing them for pre-compilation. If partial class is not found in map,
// update Resolution map in elementResolver with fully resolved name from compiler.
var reWrittenNodes = ElementRewriter.RewriteElementNames(core.ClassTable,
parseParams.ElementResolver, astNodes, core.BuildStatus.LogSymbolConflictWarning);
// Clone a disposable copy of AST nodes for PreCompile() as Codegen mutates AST's
// while performing SSA transforms and we want to keep the original AST's
var codeblock = new CodeBlockNode();
var nodes = reWrittenNodes.OfType<AssociativeNode>().Select(NodeUtils.Clone).ToList();
codeblock.Body.AddRange(nodes);
buildStatus = PreCompile(string.Empty, core, codeblock, out blockId);
core.IsParsingCodeBlockNode = parsingCbnFlag;
core.IsParsingPreloadedAssembly = parsingPreloadFlag;
parseParams.AppendErrors(buildStatus.Errors);
parseParams.AppendWarnings(buildStatus.Warnings);
if (buildStatus.ErrorCount > 0)
{
return false;
}
IEnumerable<BuildData.WarningEntry> warnings = buildStatus.Warnings;
// Get the unboundIdentifiers from the warnings
GetInputLines(parseParams.ParsedNodes, warnings, unboundIdentifiers);
foreach (KeyValuePair<int, List<VariableLine>> kvp in unboundIdentifiers)
{
foreach (VariableLine vl in kvp.Value)
parseParams.AppendUnboundIdentifier(vl.displayName, vl.variable);
}
return true;
}
catch (Exception)
{
buildStatus = null;
return false;
}
}
示例3: ParseUserCodeCore
private static IEnumerable<AST.Node> ParseUserCodeCore(Core core, string expression, string postfixGuid, ref bool parseSuccess)
{
List<ProtoCore.AST.Node> astNodes = new List<ProtoCore.AST.Node>();
core.ResetForPrecompilation();
core.IsParsingCodeBlockNode = true;
core.ParsingMode = ParseMode.AllowNonAssignment;
ProtoCore.AST.Node codeBlockNode = ProtoCore.Utils.ParserUtils.ParseWithCore(expression, core);
parseSuccess = true;
List<ProtoCore.AST.Node> nodes = ParserUtils.GetAstNodes(codeBlockNode);
Validity.Assert(nodes != null);
int index = 0;
foreach (var node in nodes)
{
ProtoCore.AST.AssociativeAST.AssociativeNode n = node as ProtoCore.AST.AssociativeAST.AssociativeNode;
ProtoCore.Utils.Validity.Assert(n != null);
// Append the temporaries only if it is not a function def or class decl
bool isFunctionOrClassDef = n is FunctionDefinitionNode || n is ClassDeclNode;
// Handle non Binary expression nodes separately
if (n is ProtoCore.AST.AssociativeAST.ModifierStackNode)
{
core.BuildStatus.LogSemanticError("Modifier Blocks are not supported currently.");
}
else if (n is ProtoCore.AST.AssociativeAST.ImportNode)
{
core.BuildStatus.LogSemanticError("Import statements are not supported in CodeBlock Nodes.");
}
else if (isFunctionOrClassDef)
{
// Add node as it is
astNodes.Add(node);
}
else
{
// Handle temporary naming for temporary Binary exp. nodes and non-assignment nodes
BinaryExpressionNode ben = node as BinaryExpressionNode;
if (ben != null && ben.Optr == ProtoCore.DSASM.Operator.assign)
{
ModifierStackNode mNode = ben.RightNode as ModifierStackNode;
if (mNode != null)
{
core.BuildStatus.LogSemanticError("Modifier Blocks are not supported currently.");
}
IdentifierNode lNode = ben.LeftNode as IdentifierNode;
if (lNode != null && lNode.Value == ProtoCore.DSASM.Constants.kTempProcLeftVar)
{
string name = string.Format("temp_{0}_{1}", index++, postfixGuid);
BinaryExpressionNode newNode = new BinaryExpressionNode(new IdentifierNode(name), ben.RightNode);
astNodes.Add(newNode);
}
else
{
// Add node as it is
astNodes.Add(node);
}
}
else
{
// These nodes are non-assignment nodes
string name = string.Format("temp_{0}_{1}", index++, postfixGuid);
BinaryExpressionNode newNode = new BinaryExpressionNode(new IdentifierNode(name), n);
astNodes.Add(newNode);
}
}
}
return astNodes;
}
示例4: TryLoadAssemblyIntoCore
public static bool TryLoadAssemblyIntoCore(Core core, string assemblyPath)
{
bool parsingPreloadFlag = core.IsParsingPreloadedAssembly;
bool parsingCbnFlag = core.IsParsingCodeBlockNode;
core.IsParsingPreloadedAssembly = true;
core.IsParsingCodeBlockNode = false;
int blockId;
string importStatement = @"import (""" + assemblyPath + @""");";
core.ResetForPrecompilation();
var status = PreCompile(importStatement, core, null, out blockId);
core.IsParsingPreloadedAssembly = parsingPreloadFlag;
core.IsParsingCodeBlockNode = parsingCbnFlag;
return status.ErrorCount == 0;
}
示例5: CompileCodeBlockAST
private static bool CompileCodeBlockAST(Core core, ParseParam parseParams)
{
Dictionary<int, List<VariableLine>> unboundIdentifiers = new Dictionary<int, List<VariableLine>>();
IEnumerable<BuildData.WarningEntry> warnings = null;
ProtoCore.BuildStatus buildStatus = null;
try
{
int blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
CodeBlockNode codeblock = new CodeBlockNode();
List<AssociativeNode> nodes = new List<AssociativeNode>();
foreach (var i in parseParams.ParsedNodes)
{
AssociativeNode assocNode = i as AssociativeNode;
if (assocNode != null)
nodes.Add(NodeUtils.Clone(assocNode));
}
codeblock.Body.AddRange(nodes);
bool parsingPreloadFlag = core.IsParsingPreloadedAssembly;
bool parsingCbnFlag = core.IsParsingPreloadedAssembly;
core.IsParsingPreloadedAssembly = false;
core.IsParsingCodeBlockNode = true;
core.ResetForPrecompilation();
buildStatus = PreCompile(string.Empty, core, codeblock, out blockId);
core.IsParsingCodeBlockNode = parsingCbnFlag;
core.IsParsingPreloadedAssembly = parsingPreloadFlag;
parseParams.AppendErrors(buildStatus.Errors);
parseParams.AppendWarnings(buildStatus.Warnings);
if (buildStatus.ErrorCount > 0)
{
return false;
}
warnings = buildStatus.Warnings;
// Get the unboundIdentifiers from the warnings
GetInputLines(parseParams.ParsedNodes, warnings, unboundIdentifiers);
foreach (KeyValuePair<int, List<VariableLine>> kvp in unboundIdentifiers)
{
foreach (VariableLine vl in kvp.Value)
parseParams.AppendUnboundIdentifier(vl.variable);
}
return true;
}
catch (Exception)
{
buildStatus = null;
return false;
}
}