public static bool GetGlobalInstanceSetterName(string propertyName) { Validity.Assert(null != propertyName); return(propertyName.StartsWith(ProtoCore.DSASM.Constants.kGlobalInstanceNamePrefix) && propertyName.Contains(ProtoCore.DSASM.Constants.kSetterPrefix)); }
public static bool IsSetter(string propertyName) { Validity.Assert(null != propertyName); return(propertyName.StartsWith(ProtoCore.DSASM.Constants.kSetterPrefix)); }
public static bool StartsWithDoubleUnderscores(string name) { Validity.Assert(null != name); return(name.StartsWith(ProtoCore.DSASM.Constants.kDoubleUnderscores)); }
public static ProtoCore.AST.AssociativeAST.AssociativeNode Clone(ProtoCore.AST.AssociativeAST.AssociativeNode rhsNode) { if (rhsNode is ProtoCore.AST.AssociativeAST.IdentifierNode) { if (rhsNode is TypedIdentifierNode) { return(new ProtoCore.AST.AssociativeAST.TypedIdentifierNode(rhsNode as ProtoCore.AST.AssociativeAST.IdentifierNode)); } return(new ProtoCore.AST.AssociativeAST.IdentifierNode(rhsNode as ProtoCore.AST.AssociativeAST.IdentifierNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.IdentifierListNode) { return(new ProtoCore.AST.AssociativeAST.IdentifierListNode(rhsNode as ProtoCore.AST.AssociativeAST.IdentifierListNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.BinaryExpressionNode) { return(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(rhsNode as ProtoCore.AST.AssociativeAST.BinaryExpressionNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.FunctionCallNode) { return(new ProtoCore.AST.AssociativeAST.FunctionCallNode(rhsNode as ProtoCore.AST.AssociativeAST.FunctionCallNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.CodeBlockNode) { return(new ProtoCore.AST.AssociativeAST.CodeBlockNode(rhsNode as ProtoCore.AST.AssociativeAST.CodeBlockNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.ArrayNode) { return(new ProtoCore.AST.AssociativeAST.ArrayNode(rhsNode as ProtoCore.AST.AssociativeAST.ArrayNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.FunctionDotCallNode) { return(new ProtoCore.AST.AssociativeAST.FunctionDotCallNode(rhsNode as ProtoCore.AST.AssociativeAST.FunctionDotCallNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.ConstructorDefinitionNode) { return(new ProtoCore.AST.AssociativeAST.ConstructorDefinitionNode(rhsNode as ProtoCore.AST.AssociativeAST.ConstructorDefinitionNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.ArgumentSignatureNode) { return(new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode(rhsNode as ProtoCore.AST.AssociativeAST.ArgumentSignatureNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.ExprListNode) { return(new ProtoCore.AST.AssociativeAST.ExprListNode(rhsNode as ProtoCore.AST.AssociativeAST.ExprListNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.LanguageBlockNode) { return(new ProtoCore.AST.AssociativeAST.LanguageBlockNode(rhsNode as ProtoCore.AST.AssociativeAST.LanguageBlockNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.ThisPointerNode) { return(new ProtoCore.AST.AssociativeAST.ThisPointerNode(rhsNode as ProtoCore.AST.AssociativeAST.ThisPointerNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.InlineConditionalNode) { return(new ProtoCore.AST.AssociativeAST.InlineConditionalNode(rhsNode as ProtoCore.AST.AssociativeAST.InlineConditionalNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.RangeExprNode) { return(new ProtoCore.AST.AssociativeAST.RangeExprNode(rhsNode as ProtoCore.AST.AssociativeAST.RangeExprNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.ModifierStackNode) { return(new ProtoCore.AST.AssociativeAST.ModifierStackNode(rhsNode as ProtoCore.AST.AssociativeAST.ModifierStackNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.GroupExpressionNode) { return(new ProtoCore.AST.AssociativeAST.GroupExpressionNode(rhsNode as ProtoCore.AST.AssociativeAST.GroupExpressionNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.ClassDeclNode) { return(new ProtoCore.AST.AssociativeAST.ClassDeclNode(rhsNode as ProtoCore.AST.AssociativeAST.ClassDeclNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.ImportNode) { return(new ProtoCore.AST.AssociativeAST.ImportNode(rhsNode as ProtoCore.AST.AssociativeAST.ImportNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.VarDeclNode) { return(new ProtoCore.AST.AssociativeAST.VarDeclNode(rhsNode as ProtoCore.AST.AssociativeAST.VarDeclNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.FunctionDefinitionNode) { return(new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode(rhsNode as ProtoCore.AST.AssociativeAST.FunctionDefinitionNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.ReplicationGuideNode) { return(new ProtoCore.AST.AssociativeAST.ReplicationGuideNode(rhsNode as ProtoCore.AST.AssociativeAST.ReplicationGuideNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.IntNode) { return(new ProtoCore.AST.AssociativeAST.IntNode(rhsNode as ProtoCore.AST.AssociativeAST.IntNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.DoubleNode) { return(new ProtoCore.AST.AssociativeAST.DoubleNode(rhsNode as ProtoCore.AST.AssociativeAST.DoubleNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.BooleanNode) { return(new ProtoCore.AST.AssociativeAST.BooleanNode(rhsNode as ProtoCore.AST.AssociativeAST.BooleanNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.CharNode) { return(new ProtoCore.AST.AssociativeAST.CharNode(rhsNode as ProtoCore.AST.AssociativeAST.CharNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.StringNode) { return(new ProtoCore.AST.AssociativeAST.StringNode(rhsNode as ProtoCore.AST.AssociativeAST.StringNode)); } else if (rhsNode is ProtoCore.AST.AssociativeAST.NullNode) { return(new ProtoCore.AST.AssociativeAST.NullNode()); } // Comment Jun: Leaving this as an assert to can catch unhandled nodes Validity.Assert(false); return(null); }
public static bool IsAutoGeneratedVar(string name) { Validity.Assert(null != name); return(name.StartsWith("%")); }
public static bool IsGlobalInstanceGetterSetter(string propertyName) { Validity.Assert(null != propertyName); return(propertyName.StartsWith(ProtoCore.DSASM.Constants.kGlobalInstanceNamePrefix) && IsGetterSetter(propertyName)); }
public static bool IsCompilerGenerated(string varname) { Validity.Assert(null != varname); return(varname.StartsWith(ProtoCore.DSASM.Constants.kInternalNamePrefix)); }
public static bool IsDisposeMethod(string methodName) { Validity.Assert(!string.IsNullOrEmpty(methodName)); return(methodName.Equals(DSDefinitions.Keyword.Dispose)); }
public static bool IsGetTypeMethod(string methodName) { Validity.Assert(!string.IsNullOrEmpty(methodName)); return(methodName.Equals(ProtoCore.DSDefinitions.Keyword.GetType)); }
public static bool IsCompilerGenerated(string varname) { Validity.Assert(!string.IsNullOrEmpty(varname)); return(varname.StartsWith(DSASM.Constants.kInternalNamePrefix)); }
public static bool IsInternalFunction(string methodName) { Validity.Assert(!string.IsNullOrEmpty(methodName)); return(methodName.StartsWith(DSASM.Constants.kInternalNamePrefix) || methodName.StartsWith(DSDefinitions.Keyword.Dispose)); }
public static bool StartsWithSingleUnderscore(string name) { Validity.Assert(null != name); return(name.StartsWith(DSASM.Constants.kSingleUnderscore)); }
private static IEnumerable <AST.Node> ParseUserCodeCore(Core core, string expression) { List <ProtoCore.AST.Node> astNodes = new List <ProtoCore.AST.Node>(); core.ResetForPrecompilation(); core.IsParsingCodeBlockNode = true; core.ParsingMode = ParseMode.AllowNonAssignment; var codeBlockNode = ParserUtils.ParseWithCore(expression, core); List <AST.Node> nodes = ParserUtils.GetAstNodes(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++; } } } } return(astNodes); }
/// <summary> /// = array[index]. /// /// Note this function doesn't support the replication of array indexing. /// </summary> /// <param name="array"></param> /// <param name="index"></param> /// <param name="core"></param> /// <returns></returns> public static StackValue GetValueFromIndex(StackValue array, StackValue index, RuntimeCore runtimeCore) { Validity.Assert(array.IsArray || array.IsString); if (!array.IsArray && !array.IsString) { return(StackValue.Null); } if (index.IsNumeric) { index = index.ToInteger(); return(GetValueFromIndex(array, (int)index.opdata, runtimeCore)); } else if (index.IsArrayKey) { int fullIndex = (int)index.opdata; if (array.IsString) { return(GetValueFromIndex(array, fullIndex, runtimeCore)); } HeapElement he = GetHeapElement(array, runtimeCore); if (he.VisibleSize > fullIndex) { return(GetValueFromIndex(array, fullIndex, runtimeCore)); } else { fullIndex = fullIndex - he.VisibleSize; if (he.Dict != null && he.Dict.Count > fullIndex) { int count = 0; foreach (var key in he.Dict.Keys) { if (count == fullIndex) { return(he.Dict[key]); } count = count + 1; } } } return(StackValue.Null); } else { HeapElement he = GetHeapElement(array, runtimeCore); StackValue value = StackValue.Null; if (he.Dict != null && he.Dict.TryGetValue(index, out value)) { return(value); } else { return(StackValue.Null); } } }
public static bool IsInternalMethod(string methodName) { Validity.Assert(null != methodName); return(methodName.StartsWith(Constants.kInternalNamePrefix)); }
public static bool IsPropertyTemp(string varname) { Validity.Assert(!string.IsNullOrEmpty(varname)); return(varname.StartsWith(ProtoCore.DSASM.Constants.kTempPropertyVar)); }
public static bool IsGetterSetter(string propertyName) { Validity.Assert(null != propertyName); return(IsGetter(propertyName) || IsSetter(propertyName)); }
public static bool IsDefaultArgTemp(string varname) { Validity.Assert(null != varname); return(varname.StartsWith(ProtoCore.DSASM.Constants.kTempDefaultArg)); }
public static bool IsTempVarProperty(string varname) { Validity.Assert(null != varname); return(varname.StartsWith(ProtoCore.DSASM.Constants.kTempPropertyVar)); }
public static bool IsDisposeMethod(string methodName) { Validity.Assert(null != methodName); return(methodName.Equals(ProtoCore.DSDefinitions.Keyword.Dispose)); }
public static bool IsInternalFunction(string methodName) { Validity.Assert(null != methodName); return(methodName.StartsWith(ProtoCore.DSASM.Constants.kInternalNamePrefix) || methodName.StartsWith(ProtoCore.DSDefinitions.Keyword.Dispose)); }
public static ProtoCore.AST.ImperativeAST.ImperativeNode Clone(ProtoCore.AST.ImperativeAST.ImperativeNode rhsNode) { if (rhsNode is ProtoCore.AST.ImperativeAST.IdentifierNode) { return(new ProtoCore.AST.ImperativeAST.IdentifierNode(rhsNode as ProtoCore.AST.ImperativeAST.IdentifierNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.IdentifierListNode) { return(new ProtoCore.AST.ImperativeAST.IdentifierListNode(rhsNode as ProtoCore.AST.ImperativeAST.IdentifierListNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.BinaryExpressionNode) { return(new ProtoCore.AST.ImperativeAST.BinaryExpressionNode(rhsNode as ProtoCore.AST.ImperativeAST.BinaryExpressionNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.FunctionCallNode) { return(new ProtoCore.AST.ImperativeAST.FunctionCallNode(rhsNode as ProtoCore.AST.ImperativeAST.FunctionCallNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.CodeBlockNode) { return(new ProtoCore.AST.ImperativeAST.CodeBlockNode(rhsNode as ProtoCore.AST.ImperativeAST.CodeBlockNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.ArrayNode) { return(new ProtoCore.AST.ImperativeAST.ArrayNode(rhsNode as ProtoCore.AST.ImperativeAST.ArrayNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.IfStmtNode) { return(new ProtoCore.AST.ImperativeAST.IfStmtNode(rhsNode as ProtoCore.AST.ImperativeAST.IfStmtNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.ElseIfBlock) { return(new ProtoCore.AST.ImperativeAST.ElseIfBlock(rhsNode as ProtoCore.AST.ImperativeAST.ElseIfBlock)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.IfStmtPositionNode) { return(new ProtoCore.AST.ImperativeAST.IfStmtPositionNode(rhsNode as ProtoCore.AST.ImperativeAST.IfStmtPositionNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.ForLoopNode) { return(new ProtoCore.AST.ImperativeAST.ForLoopNode(rhsNode as ProtoCore.AST.ImperativeAST.ForLoopNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.WhileStmtNode) { return(new ProtoCore.AST.ImperativeAST.WhileStmtNode(rhsNode as ProtoCore.AST.ImperativeAST.WhileStmtNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.ExprListNode) { return(new ProtoCore.AST.ImperativeAST.ExprListNode(rhsNode as ProtoCore.AST.ImperativeAST.ExprListNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.LanguageBlockNode) { return(new ProtoCore.AST.ImperativeAST.LanguageBlockNode(rhsNode as ProtoCore.AST.ImperativeAST.LanguageBlockNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.RangeExprNode) { return(new ProtoCore.AST.ImperativeAST.RangeExprNode(rhsNode as ProtoCore.AST.ImperativeAST.RangeExprNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.BreakNode) { return(new ProtoCore.AST.ImperativeAST.BreakNode()); } else if (rhsNode is ProtoCore.AST.ImperativeAST.ContinueNode) { return(new ProtoCore.AST.ImperativeAST.ContinueNode()); } else if (rhsNode is ProtoCore.AST.ImperativeAST.IntNode) { return(new ProtoCore.AST.ImperativeAST.IntNode(rhsNode as ProtoCore.AST.ImperativeAST.IntNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.DoubleNode) { return(new ProtoCore.AST.ImperativeAST.DoubleNode(rhsNode as ProtoCore.AST.ImperativeAST.DoubleNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.BooleanNode) { return(new ProtoCore.AST.ImperativeAST.BooleanNode(rhsNode as ProtoCore.AST.ImperativeAST.BooleanNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.CharNode) { return(new ProtoCore.AST.ImperativeAST.CharNode(rhsNode as ProtoCore.AST.ImperativeAST.CharNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.StringNode) { return(new ProtoCore.AST.ImperativeAST.StringNode(rhsNode as ProtoCore.AST.ImperativeAST.StringNode)); } else if (rhsNode is ProtoCore.AST.ImperativeAST.NullNode) { return(new ProtoCore.AST.ImperativeAST.NullNode()); } else if (rhsNode is ProtoCore.AST.ImperativeAST.UnaryExpressionNode) { return(new ProtoCore.AST.ImperativeAST.UnaryExpressionNode(rhsNode as ProtoCore.AST.ImperativeAST.UnaryExpressionNode)); } Validity.Assert(false); return(null); }