Skip to content

Commit

Permalink
Cleaned up code that no longer needs type hints.
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardgeek committed Mar 19, 2023
1 parent 1f81081 commit 668170e
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 42 deletions.
17 changes: 15 additions & 2 deletions bind/create_vars.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 Google LLC.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "de.h"

// Create a variable with the name of the identifier expression, if it does not already exist.
Expand All @@ -8,9 +22,8 @@ static void createVariableIfMissing(deBlock scopeBlock, deExpression expr) {
return;
}
deStatement statement = deFindExpressionStatement(expr);
deVariable var = deVariableCreate(scopeBlock, DE_VAR_LOCAL, false, name, deExpressionNull,
deVariableCreate(scopeBlock, DE_VAR_LOCAL, false, name, deExpressionNull,
deStatementGenerated(statement), deExpressionGetLine(expr));
deStatementInsertVariable(statement, var);
}

// Create variables when we find assignment expressions that assign to an identifier.
Expand Down
8 changes: 0 additions & 8 deletions bootstrap/database/block.rn
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ class Block(self, line: Line) {
func copyStatementsAfterStatement(self, destStatement: Statement) {
lastStatement = destStatement
for statement in self.statements() {
if false {
// Type hint for recursion.
return
}
lastStatement = statement.appendCopyAfterStatement(lastStatement)
}
}
Expand Down Expand Up @@ -96,10 +92,6 @@ class Block(self, line: Line) {

// Make a copy of the block, without sub-blocks.
func copy(self) -> Block {
if false {
// Type hint for recursion.
return self!
}
newBlock = Block(self.line)
for statement in self.statements() {
statement.appendCopy(newBlock)
Expand Down
11 changes: 0 additions & 11 deletions bootstrap/database/expr.rn
Original file line number Diff line number Diff line change
Expand Up @@ -779,10 +779,6 @@ class Expr(self, type: ExprType, line: Line) {
newExpr.autocast = self.autocast
newExpr.val = self.val
for child in self.exprs() {
if (false) {
// Type hint for recursion. TODO: make use of return type constraints.
return newExpr
}
newChild = child.copy()
newExpr.appendExpr(newChild)
}
Expand Down Expand Up @@ -810,13 +806,6 @@ relation OneToOne Function:"Type" Expr:"Type" cascade
unittest {
filepath = Filepath.new("test_filepath", null(Filepath), false)
line = Line(filepath, "Not a real line", 1u32)
if false {
// Type hints
dummyBlock = Block(line)
dummyFunction = Function(dummyBlock, FuncType.Package, Sym.new("test"), Linkage.Package, line)
dummyIdent = dummyFunction.firstIdent!
dummyKxpr = Expr.newIdent(dummyIdent)
}

func createBinaryExpr() -> Expr {
left = Expr.newConstant(Value("Hello"), line)
Expand Down
11 changes: 0 additions & 11 deletions bootstrap/database/function.rn
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,6 @@ class Function(self, owningBlock: Block?, type: FuncType, sym: Sym,

// Make a copy of the function in |destBlock|.
func copy(self, destBlock: Block) -> Function {
if false {
// Type hint for recursion.
return self
}
newFunction = Function(destBlock, self.type, self.sym, self.linkage, self.line)
newBlock = self.subBlock.copy()
newFunction.insertSubBlock(newBlock)
Expand Down Expand Up @@ -257,10 +253,6 @@ relation DoublyLinked Operator Function cascade
func createMainFunc() {
rootFilepath = Filepath("Root filepath", null(Filepath), true)
rootLine = Line(rootFilepath, "Create main", 0u32)
if false {
// Type hint for Block.
dummyBlock = Block(rootLine)
}
mainFunc = Function(null(Block(rootLine)), FuncType.Package,
Sym.new("main"), Linkage.Package, rootLine)
typeExpr = Expr(ExprType.IntType, rootLine)
Expand Down Expand Up @@ -292,9 +284,6 @@ unittest {
rootFilepath = rootLine.filepath
argcVar = rootBlock.firstVariable
argvVar = argcVar.nextBlockVariable
// Type hint: In these tests, the compiler does not know what exact class is
// added in the Ident -> Expr relation.
expr = Expr.newIdent(argcVar.firstIdent!)

func createEmptyFunction(owningBlock: Block, name: string) -> Function {
return Function(owningBlock, FuncType.Plain, Sym.new(name), Linkage.Module, rootLine)
Expand Down
4 changes: 0 additions & 4 deletions bootstrap/database/ident.rn
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ class Ident(self, block: Block, object: Function | Variable, sym: Sym, objLine:
object.appendIdent(self)
// Operator identifiers are not in any block hash table.
if !isnull(block) {
if false {
// Type hint for the ident symbol table.
block.insertIdent(self)
}
oldIdent = block.findIdent(sym)
if !isnull(oldIdent) {
Error("Tried to create an identifier '%s' that already exists on the block" % sym.name,
Expand Down
4 changes: 0 additions & 4 deletions bootstrap/database/statement.rn
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@ class Statement(self, block: Block, type: StateType, line: Line) {

// Append a deep copy of the statement to destBlock.
func appendCopy(self, destBlock: Block) -> Statement {
if false {
// Type hint for recursion.
return self
}
newStatement = Statement(destBlock, self.type, self.line)
self.copyExprAndSubBlock(newStatement)
newStatement.instantiated = self.instantiated
Expand Down
14 changes: 14 additions & 0 deletions errortests/localtype.rn
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 Google LLC.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

class Foo(self) {
}

Expand Down
2 changes: 1 addition & 1 deletion rpc/rpc_encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ static deFunction findMethod(deBlock module, char *method) {
// method's function.
static deFunction findMethodFunction(char *protoFileName, char *method) {
deBlock module = deParseModule(protoFileName, deRootGetBlock(deTheRoot), true);
deBind2();
deBind();
deBindRPCs();
deFunction function = findMethod(module, method);
if (function == deFunctionNull) {
Expand Down
2 changes: 1 addition & 1 deletion rpc/rpcgen_cc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ void deGenCCRpcCode(char *rpcDefFile, char *headerFile, char *clientFile, char *
rpcDatabaseStart();
if (!utSetjmp()) {
deParseModule(rpcDefFile, deRootGetBlock(deTheRoot), true);
deBind2();
deBind();
deBindRPCs();
genCCRpcCode(rpcDefFile, headerFile, clientFile, serverFile);
utUnsetjmp();
Expand Down
14 changes: 14 additions & 0 deletions tests/localassign.rn
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 Google LLC.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

class Foo(self) {
}

Expand Down

0 comments on commit 668170e

Please sign in to comment.