15
15
use sym
16
16
17
17
use root
18
- use line
18
+ use location
19
19
use filepath
20
20
use value
21
21
use expr
@@ -70,17 +70,17 @@ func getFuncTypeName(type: FuncType) -> string {
70
70
71
71
// Create a new function.
72
72
class Function(self, parent: Function?, type: FuncType, sym: Sym,
73
- linkage: Linkage, line: Line ) {
73
+ linkage: Linkage, location: Location ) {
74
74
self.type = type
75
75
self.sym = sym
76
76
self.linkage = linkage
77
- self.line = line
77
+ self.location = location
78
78
self.isExtern = linkage == Linkage.ExternC || linkage == Linkage.ExternRpc
79
79
if !isnull(parent) {
80
80
parent!.appendChildFunction(self)
81
- Ident(parent!, self, sym, line )
81
+ Ident(parent!, self, sym, location )
82
82
}
83
- subBlock = Block(line )
83
+ subBlock = Block(location )
84
84
// Assume it can return until we learn otherwise. This is only an issue when
85
85
// evaluating recursive functions.
86
86
subBlock.canReturn = true
@@ -142,7 +142,7 @@ class Function(self, parent: Function?, type: FuncType, sym: Sym,
142
142
143
143
// Make a copy of the function in |destBlock|.
144
144
func copy(self, destFunc: Function) -> Function {
145
- newFunction = Function(destFunc, self.type, self.sym, self.linkage, self.line )
145
+ newFunction = Function(destFunc, self.type, self.sym, self.linkage, self.location )
146
146
for variable in self.variables() {
147
147
variable.copy(newFunction)
148
148
}
@@ -174,28 +174,27 @@ class Function(self, parent: Function?, type: FuncType, sym: Sym,
174
174
func appendFunctionCall(self, childFunction: Function) -> Statement {
175
175
ident = childFunction.firstNameIdent
176
176
pathExpr = ident!.createPathExpr()
177
- text = "%s()\n" % childFunction.name()
178
177
block = self.subBlock!
179
- line = Line (block.line .filepath!, text , 0u32)
180
- emptyParamsExpr = Expr(ExprType.List, line )
181
- callExpr = Expr.newBinary(ExprType.Call, pathExpr, emptyParamsExpr, line )
182
- statement = Statement(block, StateType.Call, line )
178
+ location = Location (block.location .filepath!, 0u32, 0u32 , 0u32)
179
+ emptyParamsExpr = Expr(ExprType.List, location )
180
+ callExpr = Expr.newBinary(ExprType.Call, pathExpr, emptyParamsExpr, location )
181
+ statement = Statement(block, StateType.Call, location )
183
182
statement.insertExpr(callExpr)
184
183
return statement
185
184
}
186
185
187
186
// Declare an iterator.
188
187
func newIterator(owningFunc: Function, name: Sym, selfName: Sym, linkage: Linkage,
189
- line: Line ) -> Function {
190
- iteratorFunc = Function(owningFunc, FuncType.Iterator, name, linkage, line )
191
- Variable(iteratorFunc, true, false, selfName, null(Expr), null(Expr), false, line )
188
+ location: Location ) -> Function {
189
+ iteratorFunc = Function(owningFunc, FuncType.Iterator, name, linkage, location )
190
+ Variable(iteratorFunc, true, false, selfName, null(Expr), null(Expr), false, location )
192
191
return iteratorFunc
193
192
}
194
193
195
194
// Create an overloaded operator.
196
- func newOperator(owningFunc: Function, opType: ExprType, line: Line ) -> Function {
195
+ func newOperator(owningFunc: Function, opType: ExprType, location: Location ) -> Function {
197
196
name = owningFunc.createUniqueSym(Sym.new(getExprTypeName(opType)))
198
- function = Function(owningFunc, FuncType.Operator, name, Linkage.Package, line )
197
+ function = Function(owningFunc, FuncType.Operator, name, Linkage.Package, location )
199
198
root = getRoot()
200
199
return function
201
200
}
@@ -217,27 +216,26 @@ class Function(self, parent: Function?, type: FuncType, sym: Sym,
217
216
218
217
// Create a path expression to this function.
219
218
func createPathExpr(self) -> Expr {
220
- identExpr = Expr.newIdent(self.sym, self.line )
219
+ identExpr = Expr.newIdent(self.sym, self.location )
221
220
parent = self.parentFunction
222
221
if isnull(parent) {
223
222
return identExpr
224
223
}
225
224
prefixExpr = parent!.createPathExpr()
226
- return Expr.newBinary(ExprType.Dot, prefixExpr, identExpr, self.line )
225
+ return Expr.newBinary(ExprType.Dot, prefixExpr, identExpr, self.location )
227
226
}
228
227
}
229
228
230
229
// Append a call statement to the module initialization function in the root function.
231
230
func insertModuleInitializationCall(moduleFunc: Function) {
232
231
pathExpr = moduleFunc.createPathExpr()
233
232
block = moduleFunc.subBlock!
234
- text = "%s()\n" % moduleFunc.name()
235
- line = Line(block.line.filepath!, text, 0u32)
236
- emptyParamsExpr = Expr(ExprType.List, line)
237
- callExpression = Expr.newBinary(ExprType.Call, pathExpr, emptyParamsExpr, line)
233
+ location = Location(block.location.filepath!, 0u32, 0u32, 0u32)
234
+ emptyParamsExpr = Expr(ExprType.List, location)
235
+ callExpression = Expr.newBinary(ExprType.Call, pathExpr, emptyParamsExpr, location)
238
236
root = getRoot()
239
237
block = getMainFunc().subBlock!
240
- statement = Statement(block, StateType.Call, line )
238
+ statement = Statement(block, StateType.Call, location )
241
239
statement.insertExpr(callExpression)
242
240
// Move the statement to after the last initialization call.
243
241
lastInitializer = root.lastInitializerStatement
@@ -258,24 +256,24 @@ relation OneToOne Filepath:"Module" Function:"Module"
258
256
// Create the main function.
259
257
func createMainFunc() {
260
258
rootFilepath = Filepath("Root filepath", null(Filepath), true)
261
- rootLine = Line (rootFilepath, "Create main" , 0u32)
259
+ rootLocation = Location (rootFilepath, 0u32, 0u32 , 0u32)
262
260
mainFunc = Function(null(Function), FuncType.Package,
263
- Sym.new("main"), Linkage.Package, rootLine )
264
- typeExpr = Expr(ExprType.IntType, rootLine )
261
+ Sym.new("main"), Linkage.Package, rootLocation )
262
+ typeExpr = Expr(ExprType.IntType, rootLocation )
265
263
typeExpr.width = 32u32
266
264
mainFunc.insertTypeExpr(typeExpr)
267
265
getRoot().insertMainFunction(mainFunc)
268
266
rootBlock = mainFunc.subBlock!
269
267
rootFilepath.insertModuleFunction(mainFunc)
270
- nullExpr = null(Expr(ExprType.Add, rootLine ))
271
- u32TypeExpr = Expr(ExprType.UintType, rootLine )
272
- stringTypeExpr = Expr(ExprType.StringType, rootLine )
268
+ nullExpr = null(Expr(ExprType.Add, rootLocation ))
269
+ u32TypeExpr = Expr(ExprType.UintType, rootLocation )
270
+ stringTypeExpr = Expr(ExprType.StringType, rootLocation )
273
271
u32TypeExpr.width = 32u32
274
- argcVar = Variable(mainFunc, true, true, Sym.new("argc"), nullExpr, u32TypeExpr, true, rootLine )
272
+ argcVar = Variable(mainFunc, true, true, Sym.new("argc"), nullExpr, u32TypeExpr, true, rootLocation )
275
273
argvVar = Variable(mainFunc, true, true, Sym.new("argv"), nullExpr,
276
- stringTypeExpr, true, rootLine )
277
- statement = Statement(mainFunc.subBlock!, StateType.Return, rootLine )
278
- retVal = Expr.newConstant(Value(0i32), rootLine )
274
+ stringTypeExpr, true, rootLocation )
275
+ statement = Statement(mainFunc.subBlock!, StateType.Return, rootLocation )
276
+ retVal = Expr.newConstant(Value(0i32), rootLocation )
279
277
statement.insertExpr(retVal)
280
278
}
281
279
@@ -285,19 +283,19 @@ unittest {
285
283
use statement
286
284
287
285
mainFunc = getMainFunc()
288
- rootLine = mainFunc.line
289
- rootFilepath = rootLine .filepath
286
+ rootLocation = mainFunc.location
287
+ rootFilepath = rootLocation .filepath
290
288
argcVar = mainFunc.firstVariable!
291
289
argvVar = argcVar.nextFunctionVariable!
292
290
293
291
func createEmptyFunction(owningFunc: Function?, name: string) -> Function {
294
- return Function(owningFunc, FuncType.Plain, Sym.new(name), Linkage.Module, rootLine )
292
+ return Function(owningFunc, FuncType.Plain, Sym.new(name), Linkage.Module, rootLocation )
295
293
}
296
294
297
295
func createPrintlnFunction(owningFunc: Function?, name: string, text: string) {
298
296
function = createEmptyFunction(owningFunc, name);
299
297
block = function.subBlock!
300
- Statement(block, StateType.Println, rootLine )
298
+ Statement(block, StateType.Println, rootLocation )
301
299
return function
302
300
}
303
301
}
@@ -328,8 +326,8 @@ unittest prependAndAppendFunctionCallTest {
328
326
329
327
unittest newIteratorAndOperatorTest {
330
328
itr = Function.newIterator(mainFunc, Sym.new("testItr"), Sym.new("self"),
331
- Linkage.Module, rootLine )
332
- op = Function.newOperator(mainFunc, ExprType.Add, rootLine )
329
+ Linkage.Module, rootLocation )
330
+ op = Function.newOperator(mainFunc, ExprType.Add, rootLocation )
333
331
itr.dump()
334
332
op.dump()
335
333
itr.destroy()
0 commit comments