// Add another variable declaration public void AddDeclaration(Bookmark bookmark, string Name, ast.Expression InitialValue) { var v = new Variable(); v.Bookmark = bookmark; v.Name = Name; v.InitialValue = InitialValue; Variables.Add(v); }
public void CheckControlCondition(ast.Statement statement, ast.Expression expr) { if (expr == null) return; if ((expr.RootNode as ast.ExprNodeAssignment)!=null) { currentScope.Compiler.RecordWarning(expr.Bookmark, "assignment as condition of flow control statement (use parens to disable this warning)"); } }
public void EnterPseudoScope(ast.Node n) { SymbolScope currentScope = m_PseudoScopes.Peek(); n.PseudoScope = new SymbolScope(currentScope.Compiler, n, Accessibility.Private); currentScope.InnerScopes.Add(n.PseudoScope); n.PseudoScope.OuterScope = currentScope; m_PseudoScopes.Push(n.PseudoScope); }
// Parse series of statements into a statement block public void ParseStatements(ast.CodeBlock block) { while (t.token != Token.closeBrace && t.token!=Token.eof) { // Skip redundant semicolons if (t.token == Token.semicolon) { t.Next(); continue; } // Add the next statement block.AddStatement(ParseSingleStatement()); } }
public bool DoesMatch(ast.ExprNodeIdentifier target, string member) { if (m_specNonMember != null) return false; // Check the member name matches if (m_specMember != null) { if (!m_specMember.DoesMatch(member)) return false; } // Check the target name matches if (m_specTarget != null) { // Skip over `prototype` if present if (target.Name == "prototype" || target.Name == "__proto__") { if (target.Lhs == null) return false; if (target.Lhs.GetType() != typeof(ast.ExprNodeIdentifier)) return false; target = (ast.ExprNodeIdentifier)target.Lhs; } // The target must be the left most part if (target.Lhs != null) return false; if (!m_specTarget.DoesMatch(target.Name)) return false; } // Match! return true; }
public void RejectConstVariable(ast.ExprNode node) { // Is the lhs a global? if (node.GetType() != typeof(ast.ExprNodeIdentifier)) return; // Check it's not a member accessor var identifier = (ast.ExprNodeIdentifier)node; if (identifier.Lhs != null) return; // Find the symbol and mark it as not a const var s = currentScope.FindSymbol(identifier.Name); if (s != null) { s.ConstValue = null; s.ConstAllowed = false; } }
// Add code to this case clause. public void AddCode(ast.Statement statement) { // First time? if (Code == null) { Code = new ast.CodeBlock(statement.Bookmark, TriState.No); } Code.AddStatement(statement); }
// Parse the parameter declarations on a function void ParseParameters(ast.ExprNodeFunction fn) { // Must have open paren t.SkipRequired(Token.openRound); // Empty? if (t.SkipOptional(Token.closeRound)) return; // Parameters while (true) { // Name t.Require(Token.identifier); fn.Parameters.Add(new ast.Parameter(t.GetBookmark(), t.identifier)); t.Next(); // Another? if (!t.SkipOptional(Token.comma)) break; } // Finished t.SkipRequired(Token.closeRound); }
// Parse a single variable declaration void ParseVarDecl(ParseContext ctx, ast.StatementVariableDeclaration decl) { var bmk = t.GetBookmark(); // Variable name t.Require(Token.identifier); var name = t.identifier; t.Next(); // Optional initial value ast.Expression InitialValue = null; if (t.SkipOptional(Token.assign)) { InitialValue = ParseSingleExpression(ctx); } // Store it decl.AddDeclaration(bmk, name, InitialValue); }
private void button1_Click(object sender, EventArgs e)// COMMIT TO THE DB { SqlConnection con = new SqlConnection("server=itdev.corp.telenetwork.com;Database=dttests;User=sa; PWD=gR!FfiN-;"); SqlConnection conn = new SqlConnection("server=sql-prod.corp.telenetwork.com;Database=PreHire;User=sa; PWD=qwerty;"); SqlCommand cmd = new SqlCommand(); SqlDataAdapter dataAdapter = new SqlDataAdapter(); DataSet ds = new DataSet(); con.Close(); // we require these to be filled out before sending them into the database if ((reason.Text.Length > 0) && (changed.Text.Length > 0)) { try { cmd.Connection = con; con.Open(); cmd.CommandText = "select username, time, reasonforedit, whatwaschanged, approvedby from dbo.dbuauditor"; cmd.Parameters.AddWithValue("@un", username.Text); cmd.Parameters.AddWithValue("@time", time.Text); cmd.Parameters.AddWithValue("@reason", reason.Text); cmd.Parameters.AddWithValue("@wwc", changed.Text); cmd.Parameters.AddWithValue("@approved", appby.Text); cmd.CommandText = "insert into dbo.dbuauditor (username, time, reasonforedit, whatwaschanged, approvedby) values (@un, @time, @reason, @wwc, @approved)"; cmd.ExecuteNonQuery(); con.Close(); HasUserFiledForm = true; } catch (SqlException) { MessageBox.Show("There was a SQL comm error. Contact an Administrator.", "SQL Error"); HasUserFiledForm = false; } finally { if (sql_log.sqlwriterlog.HasUserFiledForm == true) { try {/* * // Using update cmds I will insert the strings into sql. Update Soon. * // Note to self. I need to update the db instead of inserting. My early attempt here resulted in a few dupes in the recruiting db. * cmd.Connection = conn; * conn.Open(); * cmd.CommandText = "select bgid, fname, mname, lname, addr, city, st, zip, phone, ssn, dob, signed, appid, rundate, result, suffix, maidenName from dbo.Background_Check"; * //cmd.Parameters.AddWithValue("@BGID", bge.BGID); * cmd.Parameters.AddWithValue("@FN", ast.FN); * cmd.Parameters.AddWithValue("@MN", ast.MN); * cmd.Parameters.AddWithValue("@LN", ast.LN); * cmd.Parameters.AddWithValue("@ADDR", ast.ADD); * cmd.Parameters.AddWithValue("@CTY", ast.CTY); * cmd.Parameters.AddWithValue("@STA", ast.STA); * cmd.Parameters.AddWithValue("@ZIPC", ast.ZIPC); * cmd.Parameters.AddWithValue("@PHONENUM", ast.PHONENUM); * cmd.Parameters.AddWithValue("@SSN", ast.SSN); * cmd.Parameters.AddWithValue("@DOB", ast.DTDOB); * cmd.Parameters.AddWithValue("@SIGNED", ast.SIGNED); * cmd.Parameters.AddWithValue("@APPID", ast.APPID); * cmd.Parameters.AddWithValue("@RUNDATE", ast.RUNDATE); * cmd.Parameters.AddWithValue("@RESULT", ast.RESULT); * cmd.Parameters.AddWithValue("@SUFFIX", ast.SUFFIX); * cmd.Parameters.AddWithValue("@MAIDENNAME", ast.MAIDENNAME); * cmd.CommandText = "insert into dbo.Background_Check (fname, mname, lname, addr, city, st, zip, phone, ssn, dob, signed, appid, rundate, result, suffix, maidenName) values (@FN, @MN, @LN, @ADDR, @CTY, @STA, @ZIPC, @PHONENUM, @SSN, @DOB, @SIGNED, @APPID, @RUNDATE, @RESULT, @SUFFIX, @MAIDENNAME )"; * cmd.ExecuteNonQuery(); * conn.Close(); */ } catch (SqlException) { MessageBox.Show("There was a SQL comm error. Contact an Administrator.", "SQL Error"); this.Close(); var myForm = new main(); myForm.Show(); } finally { // goto new bge this.Close(); var myForm = new ast(); myForm.Show(); //this.RefToBGE.Show(); //this.Close(); MessageBox.Show("Background Check Database Updated!", "Update Complete"); if (sql_log.sqlwriterlog.HasUserFiledForm == true) { ast.BGID = 0; ast.FN = null; ast.MN = null; ast.LN = null; ast.ADD = null; ast.CTY = null; ast.STA = null; ast.ZIPC = null; ast.PHONENUM = null; ast.SSN = null; ast.DOB = null; ast.APPID = 0; ast.RESULT = null; ast.SUFFIX = null; ast.MAIDENNAME = null; } } } } } else { MessageBox.Show("You have not filled out the required fields.", "ERROR"); } }
// Constructor public SymbolScope(Compiler Compiler, ast.Node node, Accessibility defaultAccessibility) { m_Compiler = Compiler; Node = node; DefaultAccessibility = defaultAccessibility; }
public void ProcessAccessibilitySpecs(ast.ExprNodeIdentifier target, string identifier, Bookmark bmk) { // Check accessibility specs for (int i = m_AccessibilitySpecs.Count - 1; i >= 0; i--) { var spec = m_AccessibilitySpecs[i]; if (spec.IsWildcard() && spec.DoesMatch(target, identifier)) { var symbol=Members.DefineSymbol(identifier, bmk); if (symbol.Accessibility == Accessibility.Default) symbol.Accessibility = spec.GetAccessibility(); return; } } // Pass to outer scope if (OuterScope!=null) OuterScope.ProcessAccessibilitySpecs(target, identifier, bmk); }
public bool OnEnterNode(ast.Node n) { // New actual scope (function body or catch clause) if (n.GetType() == typeof(ast.ExprNodeFunction) || n.GetType() == typeof(ast.CatchClause)) { SymbolScope currentScope = m_Scopes.Peek(); n.Scope = new SymbolScope(currentScope.Compiler, n, Accessibility.Private); // Add this function to the parent function's list of nested functions currentScope.InnerScopes.Add(n.Scope); n.Scope.OuterScope = currentScope; // Enter scope m_Scopes.Push(n.Scope); // Also create a pseudo scope EnterPseudoScope(n); return true; } // New pseudo scope (statement body or braced code block) if (n.GetType() == typeof(ast.CodeBlock) || n.GetType() == typeof(ast.StatementBlock) || n.GetType()==typeof(ast.StatementFor) || n.GetType()==typeof(ast.StatementForIn)) { // Create pseudo scope EnterPseudoScope(n); return true; } // Is it an evil? if (n.GetType() == typeof(ast.StatementWith)) { m_Scopes.Peek().Compiler.RecordWarning(n.Bookmark, "use of `with` statement prevents local symbol obfuscation of all containing scopes"); m_Scopes.Peek().DefaultAccessibility = Accessibility.Public; return true; } // More evil if (n.GetType() == typeof(ast.ExprNodeIdentifier)) { var m = (ast.ExprNodeIdentifier)n; if (m.Lhs == null && m.Name == "eval") { m_Scopes.Peek().Compiler.RecordWarning(n.Bookmark, "use of `eval` prevents local symbol obfuscation of all containing scopes"); m_Scopes.Peek().DefaultAccessibility = Accessibility.Public; } return true; } // Private member declaration? if (n.GetType() == typeof(ast.StatementAccessibility)) { var p = (ast.StatementAccessibility)n; foreach (var s in p.Specs) { m_Scopes.Peek().AddAccessibilitySpec(p.Bookmark, s); } } // Try to guess name of function by assignment in variable declaration var decl = n as ast.StatementVariableDeclaration; if (decl != null) { foreach (var i in decl.Variables) { if (i.InitialValue!=null) { var fn = i.InitialValue.RootNode as ast.ExprNodeFunction; if (fn != null) { fn.AssignedToName = i.Name; } } } } // Try to guess name of function by assignment var assignment = n as ast.ExprNodeAssignment; if (assignment != null) { var fn = assignment.Rhs as ast.ExprNodeFunction; if (fn != null) { var id = assignment.Lhs as ast.ExprNodeIdentifier; if (id!=null) fn.AssignedToName = id.Name; } } // Try to guess name of function in object literal var objLiteral = n as ast.ExprNodeObjectLiteral; if (objLiteral != null) { foreach (var i in objLiteral.Values) { var fn = i.Value as ast.ExprNodeFunction; if (fn != null) { var id = i.Key as ast.ExprNodeIdentifier; if (id != null) { fn.AssignedToName = id.Name; } } } } return true; }